plugin

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2021 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package plugin 插件模块

Index

Constants

This section is empty.

Variables

View Source
var NotExistErr = errors.New("plugin not exist")

Functions

func ArchiveURL

func ArchiveURL(pluginID string, req *http.Request) string

ArchiveURL 插件的前端压缩包地址

func BuildFromDir

func BuildFromDir(path, tag string) (imageID string, err error)

BuildFromDir 从源码编译镜像

func BuildFromTar

func BuildFromTar(tarPath string) (imageID string, err error)

BuildFromTar 从源码tar压缩包中build镜像

func DefaultOnDeviceStateChange

func DefaultOnDeviceStateChange(d entity.Device, attr entity.Attribute) error

func DisconnectDevice added in v1.5.0

func DisconnectDevice(identity, pluginID string, authParams map[string]string) error

func EndPointsManager

func EndPointsManager() (manager endpoints.Manager, err error)

func GetControlAttributeByID

func GetControlAttributeByID(d entity.Device, instanceID int, attr string) (attribute entity.Attribute, err error)

GetControlAttributeByID 获取设备属性(不包括设备型号、厂商等属性)

func GetControlAttributes

func GetControlAttributes(d entity.Device) (attributes []entity.Attribute, err error)

GetControlAttributes 获取设备属性(不包括设备型号、厂商等属性)

func GetInfoFromDeviceAttrs added in v1.5.0

func GetInfoFromDeviceAttrs(pluginID string, das DeviceAttributes) (d entity.Device, err error)

func GetInstanceControlAttributes

func GetInstanceControlAttributes(instance Instance) (attributes []entity.Attribute)

GetInstanceControlAttributes 获取实例的控制属性

func LogoURL

func LogoURL(req *http.Request, d entity.Device) string

LogoURL Logo图片地址

func NewClient

func NewClient(callbacks ...OnDeviceStateChange) *client

func NewDiscovery

func NewDiscovery(cli *client) *discovery

func NewManager

func NewManager() *manager

func PluginBasePath added in v1.5.0

func PluginBasePath(path string) (plgPath string)

PluginBasePath 根据配置文件config.json确定插件包准确目录

func PluginURL

func PluginURL(d entity.Device, req *http.Request, token string) string

PluginURL 返回设备的插件控制页url

func RelativeControlPath

func RelativeControlPath(d entity.Device, token string) string

RelativeControlPath 返回设备的插件控制页相对路径

func RemoveDevice

func RemoveDevice(deviceID int) (err error)

RemoveDevice 删除设备,断开相关连接和回收资源

func RunPlugin added in v1.5.0

func RunPlugin(plg Plugin) (containerID string, err error)

RunPlugin 运行插件

func SetAttributes

func SetAttributes(areaID uint64, pluginID, identity string, data json.RawMessage) (err error)

SetAttributes 通过插件设置设备的属性

func SetGlobalClient

func SetGlobalClient(c Client)

func SetGlobalManager

func SetGlobalManager(m Manager)

func StaticURL

func StaticURL(pluginID, relativePath string, req *http.Request) string

StaticURL 插件的静态文件地址

func UpdateShadowReported

func UpdateShadowReported(d entity.Device, attr entity.Attribute) (err error)

UpdateShadowReported 更新设备影子属性报告值

Types

type Attribute

type Attribute struct {
	server.Attribute
	CanControl bool `json:"can_control"`
}

type Client

type Client interface {
	DevicesDiscover(ctx context.Context) <-chan DiscoverResponse
	GetAttributes(device entity.Device) (DeviceAttributes, error)
	SetAttributes(device entity.Device, data json.RawMessage) (result []byte, err error)
	HealthCheck(entity.Device) error
	IsOnline(entity.Device) bool

	// Connect 连接设备
	Connect(identity, pluginID string, authParams map[string]string) (DeviceAttributes, error)
	// Disconnect 与设备断开连接
	Disconnect(identity, pluginID string, authParams map[string]string) error

	// DeviceConfig 设备的配置
	DeviceConfig(entity.Device) DeviceConfig
	// DeviceConfigs 所有设备的配置
	DeviceConfigs() []DeviceConfig
}

Client 与插件服务交互的客户端

func GetGlobalClient

func GetGlobalClient() Client

type Device

type Device struct {
	Model string     `json:"model" yaml:"model"`
	Name  string     `json:"name" yaml:"name"`
	Type  DeviceType `json:"type" yaml:"type"` // 设备类型

	Control      string `json:"control" yaml:"control"`           // 设备控制页面相对路径
	Provisioning string `json:"provisioning" yaml:"provisioning"` // 设备置网页面相对路径
}

type DeviceAttributes

type DeviceAttributes struct {
	Identity  string     `json:"identity"`
	Instances []Instance `json:"instances"`
	Online    bool       `json:"online"`
}

func ConnectDevice added in v1.5.0

func ConnectDevice(identity, pluginID string, authParams map[string]string) (das DeviceAttributes, err error)

func GetUserDeviceAttributes

func GetUserDeviceAttributes(areaID uint64, userID int, pluginID, identity string) (das DeviceAttributes, err error)

GetUserDeviceAttributes 获取用户设备的属性(包括权限)

type DeviceConfig added in v1.5.0

type DeviceConfig struct {
	Device
	PluginID string
}

type DeviceInfo added in v1.5.0

type DeviceInfo struct {
	Model string `json:"model" validate:"required"`
	Name  string `json:"name" validate:"required"`

	Control      string `json:"control" validate:"required"` // 设备控制页面相对路径
	Provisioning string `json:"provisioning"`                // 设备置网页面相对路径
}

type DeviceType

type DeviceType string
const (
	TypeLight          DeviceType = "light"           // 灯
	TypeSwitch         DeviceType = "switch"          // 开关
	TypeOutlet         DeviceType = "outlet"          // 插座
	TypeRoutingGateway DeviceType = "routing_gateway" // 路由网关
	TypeSecurity       DeviceType = "security"        // 安防
)

type DiscoverResponse

type DiscoverResponse struct {
	Name         string `json:"name"`
	Identity     string `json:"identity"`
	Model        string `json:"model"`
	Manufacturer string `json:"manufacturer"`
	PluginID     string `json:"plugin_id"`
	AuthRequired bool   `json:"auth_required"`
}

type Info

type Info struct {
	Control      string `json:"control" yaml:"control"`           // 设备控制页面相对路径
	Provisioning string `json:"provisioning" yaml:"provisioning"` // 设备置网页面相对路径
	Compress     string `json:"compress" yaml:"compress"`         // 压缩包地址
}

type Instance

type Instance struct {
	Type       string      `json:"type"`
	InstanceId int         `json:"instance_id"`
	Attributes []Attribute `json:"attributes"`
}

type Manager

type Manager interface {
	// LoadPlugins 加载并返回所有插件
	LoadPlugins() (map[string]*Plugin, error)
	// GetPlugin 加载并返回插件
	GetPlugin(id string) (*Plugin, error)
}

Manager 与SC服务交互获取插件信息

func GetGlobalManager

func GetGlobalManager() Manager

type OnDeviceStateChange

type OnDeviceStateChange func(d entity.Device, attr entity.Attribute) error

type Plugin

type Plugin struct {
	ID             string    `json:"id" yaml:"id"`
	Name           string    `json:"name" yaml:"name"`
	Image          string    `json:"image" yaml:"image"`
	Version        string    `json:"version" yaml:"version"`
	Brand          string    `json:"brand" yaml:"brand"`
	Info           string    `json:"info" yaml:"info"`
	DownloadURL    string    `json:"download_url" yaml:"download_url"` // 插件静态文件下载地址
	SupportDevices []*Device `json:"support_devices" yaml:"support_devices"`
	Source         string    `json:"source" yaml:"source"` // 插件来源
	AreaID         uint64    `json:"area_id" yaml:"area_id"`
}

func GetPluginConfig added in v1.5.0

func GetPluginConfig(addr, pluginID string) (config Plugin, err error)

GetPluginConfig 获取插件配置

func LoadPluginFromZip

func LoadPluginFromZip(path string, areaID uint64) (plg Plugin, err error)

LoadPluginFromZip 从压缩包中加载插件

func NewFromEntity added in v1.5.0

func NewFromEntity(p entity.PluginInfo) Plugin

func (Plugin) Install

func (p Plugin) Install() (err error)

Install 安装并且启动插件

func (Plugin) IsAdded

func (p Plugin) IsAdded() bool

func (Plugin) IsDevelopment

func (p Plugin) IsDevelopment() bool

IsDevelopment 是否开发者上传的插件

func (Plugin) IsNewest

func (p Plugin) IsNewest() bool

func (Plugin) IsRunning

func (p Plugin) IsRunning() bool

func (Plugin) Remove

func (p Plugin) Remove() (err error)

Remove 删除插件

func (Plugin) Up

func (p Plugin) Up() (err error)

Up 启动插件

func (Plugin) Update

func (p Plugin) Update() (err error)

Update 更新插件

func (Plugin) UpdateOrInstall added in v1.5.0

func (p Plugin) UpdateOrInstall() (err error)

type PluginConfig added in v1.5.0

type PluginConfig struct {
	Name           string       `json:"name" validate:"required"`            // 插件名称
	Version        string       `json:"version" validate:"required"`         // 版本
	Info           string       `json:"info"`                                // 介绍
	SupportDevices []DeviceInfo `json:"support_devices" validate:"required"` // 支持的设备
}

func LoadPluginConfig added in v1.5.0

func LoadPluginConfig(path string) (plg PluginConfig, err error)

LoadPluginConfig 加载插件配置

func (PluginConfig) ID added in v1.5.0

func (p PluginConfig) ID() string

ID 根据配置生成插件ID

func (PluginConfig) Validate added in v1.5.0

func (p PluginConfig) Validate() error

Directories

Path Synopsis
Package docker 提供与本机 Docker 守护进程交互的功能;包括镜像管理,容器启动
Package docker 提供与本机 Docker 守护进程交互的功能;包括镜像管理,容器启动

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL