drivers

package
v0.0.0-...-e35e166 Latest Latest
Warning

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

Go to latest
Published: May 4, 2017 License: AGPL-3.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertInput

func ConvertInput(input interface{}, data interface{}) (interface{}, error)

ConvertInput 解析Input输入

func ConvertValue

func ConvertValue(v interface{}, dst interface{}) error

ConvertValue 尝试将 v 转换为 dst

func RegisterDriver

func RegisterDriver(driver DriverInterface)

RegisterDriver 将驱动器注册到全局中, 注册时需保证Namespace唯一。

func UUID

func UUID() string

UUID 生成一个唯一ID

Types

type Action

type Action struct {
	ID        string `json:"id"`
	Title     string `json:"title"`
	Driver    string `json:"driver"` //对应Driver的Namespace
	Namespace string `json:"namespace"`
	Input     Values `json:"inputValues"`
}

Action 驱动动作

func (*Action) String

func (a *Action) String() string

type ActionDescriptor

type ActionDescriptor struct {
	Title       string             `json:"title"`
	Namespace   string             `json:"namespace"`
	Description string             `json:"desc"`
	Input       []InputDescriptor  `json:"input"`
	Output      []OutputDescriptor `json:"output"`
}

ActionDescriptor Action描述信息

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver 驱动

func NewDriver

func NewDriver(cfg DriverConfig) Driver

NewDriver 新建驱动器

func (*Driver) ActionHandler

func (d *Driver) ActionHandler(ctx *bee.Context)

ActionHandler 执行Action

func (*Driver) Description

func (d *Driver) Description() string

Description 获取驱动器描述

func (*Driver) ExecAction

func (d *Driver) ExecAction(a *Action) (Output, error)

ExecAction 执行Action,但基础Driver中不具体实现。

func (*Driver) LogErrorf

func (d *Driver) LogErrorf(format string, args ...interface{})

LogErrorf logs a formatted error string

func (*Driver) LogFatal

func (d *Driver) LogFatal(args ...interface{})

LogFatal logs a fatal error

func (*Driver) Logf

func (d *Driver) Logf(format string, args ...interface{})

Logf logs a formatted string

func (*Driver) Logln

func (d *Driver) Logln(args ...interface{})

Logln 写日志

func (*Driver) Namespace

func (d *Driver) Namespace() string

Namespace 获取驱动器命名空间,以此注册驱动器

func (*Driver) NewAction

func (d *Driver) NewAction(actionNamespace string, values Values) (*Action, error)

NewAction 初始化一个Action

func (*Driver) Options

func (d *Driver) Options() Options

Options 获取驱动器配置选项信息

func (*Driver) String

func (d *Driver) String() string

func (*Driver) Title

func (d *Driver) Title() string

Title 此驱动名称

type DriverConfig

type DriverConfig struct {
	Title       string  `json:"title"`     //驱动名称,简称
	Namespace   string  `json:"namespace"` //驱动标识符,必须全局唯一。依次同其他驱动器进行区分
	Description string  `json:"desc"`      //驱动描述,在使用驱动时,可以显示对驱动的描述,以方便了解驱动功能
	Options     Options `json:"options"`   //驱动器配置信息
}

DriverConfig 驱动器配置

type DriverFactory

type DriverFactory struct {
}

DriverFactory 驱动Factory

type DriverFactoryInterface

type DriverFactoryInterface interface {
	// 驱动ID
	ID() string
	// 驱动名称
	Name() string
	// 驱动描述
	Description() string

	// 创建驱动所需的选项配置信息
	Options() []OptionDescriptor

	// 驱动所还有的行为描述
	Actions() []ActionDescriptor

	// New 新建驱动实例
	New(name, description string, options Options) DriverInterface
}

DriverFactoryInterface 用于创建驱动器.

type DriverInterface

type DriverInterface interface {

	// Title 此驱动名称
	Title() string
	// Namespace 驱动标识符
	Namespace() string

	// 驱动器描述
	Description() string

	// 获取驱动器配置选项信息
	Options() Options

	Logln(args ...interface{})
	Logf(format string, args ...interface{})
	LogErrorf(format string, args ...interface{})
	LogFatal(args ...interface{})

	// Actions 行为描述
	Actions() []ActionDescriptor

	NewAction(actionNamespace string, input Values) (*Action, error)

	// Action 执行行为命令
	ExecAction(action *Action) (interface{}, error)

	String() string
}

DriverInterface 驱动器接口

func GetDriver

func GetDriver(namespace string) (DriverInterface, error)

GetDriver 获取指定类型的驱动器

func GetDrivers

func GetDrivers() []DriverInterface

GetDrivers 获取所有已注册的Drivers

type InputDescriptor

type InputDescriptor struct {
	OptionDescriptor
	Required bool `json:"required"` //是否是必要参数

}

InputDescriptor 输入信息描述

type NotFoundItemError

type NotFoundItemError struct {
	Item string
}

NotFoundItemError 不存在该项Error

func (*NotFoundItemError) Error

func (n *NotFoundItemError) Error() string

type Option

type Option struct {
	Name  string           `json:"name"` //参数名称
	Desc  OptionDescriptor `json:"desc"` //参数描述
	Value interface{}      `json:"value"`
}

Option 选项信息

type OptionDescriptor

type OptionDescriptor struct {
	Name        string    `json:"name"`      //参数名称
	Description string    `json:"desc"`      //参数描述
	ValueType   kind.Kind `json:"valueType"` //参数值数据类型
}

OptionDescriptor Option描述

type Options

type Options []Option

Options 一组选项信息

func (Options) Bind

func (opts Options) Bind(name string, dst interface{}) error

Bind 给选项绑定一值

func (Options) SetValue

func (opts Options) SetValue(name string, value interface{}) error

SetValue 给一组参数名为 name 的设置值

func (Options) Value

func (opts Options) Value(name string) interface{}

Value 从选项配置中获取对应项的值

type Output

type Output struct {
	ID       string      `json:"id"`
	ActionID string      `json:"action_id"`
	Type     OutputType  `json:"typ"`
	Value    interface{} `json:"value"`
}

Output 输出信息

type OutputDescriptor

type OutputDescriptor struct {
	OptionDescriptor
}

OutputDescriptor 结果描述

type OutputType

type OutputType kind.Kind

OutputType 数据输出类型

type Values

type Values map[string]interface{}

Values 驱动器选项输入值

func (Values) Bind

func (v Values) Bind(key string, dst interface{}) error

Bind 将Map的值转换为指定类型的数据,如果未找到Key所对应的项或转换失败则返回错误

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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