iotschema

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: AGPL-3.0 Imports: 2 Imported by: 0

README

物模型

轻量级物模型,主要用于在边缘侧显示数据,约束数据,属于IoTHub的物模型的子集。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolRule

type BoolRule struct {
	DefaultValue bool   `json:"defaultValue"`
	TrueLabel    string `json:"trueLabel"`  // UI界面对应的label
	FalseLabel   string `json:"falseLabel"` // UI界面对应的label
}

* * 布尔规则 *

func (BoolRule) Validate

func (V BoolRule) Validate(Value interface{}) error

type FloatRule

type FloatRule struct {
	DefaultValue float64 `json:"defaultValue"`
	Max          int     `json:"max"`
	Min          int     `json:"min"`
	Round        int     `json:"round"`
}

* * 浮点数规则 *

func (FloatRule) Validate

func (V FloatRule) Validate(Value interface{}) error

type GeoRule

type GeoRule struct {
	DefaultValue IoTPropertyGeo `json:"defaultValue"`
}

* * 地理坐标规则 *

func (GeoRule) Validate

func (V GeoRule) Validate(Value interface{}) error

type IntegerRule

type IntegerRule struct {
	DefaultValue int `json:"defaultValue"`
	Max          int `json:"max"`
	Min          int `json:"min"`
}

* * 整数规则 *

func (IntegerRule) Validate

func (V IntegerRule) Validate(Value interface{}) error

type IoTProperty

type IoTProperty struct {
	Label       string          `json:"label"`           // UI显示的那个文本
	Name        string          `json:"name"`            // 变量关联名
	Description string          `json:"description"`     // 额外信息
	Type        IoTPropertyType `json:"type"`            // 类型, 只能是上面几种
	Rw          string          `json:"rw"`              // R读 W写 RW读写
	Unit        string          `json:"unit"`            // 单位 例如:摄氏度、米、牛等等
	Value       any             `json:"value,omitempty"` // Value 是运行时值, 前端不用填写
	Rule        IoTPropertyRule `json:"rule"`            // 规则
}

物模型属性

func (*IoTProperty) BoolValue

func (I *IoTProperty) BoolValue() bool

func (*IoTProperty) FloatValue

func (I *IoTProperty) FloatValue() float64

func (*IoTProperty) IntValue

func (I *IoTProperty) IntValue() int

func (*IoTProperty) StringValue

func (I *IoTProperty) StringValue() string

func (IoTProperty) ValidateFields

func (V IoTProperty) ValidateFields() error

* * 验证类型 *

func (IoTProperty) ValidateRule

func (V IoTProperty) ValidateRule() error

* * 验证物模型本身是否合法, 包含了 IoTPropertyType,Rule 的对应关系 *

func (IoTProperty) ValidateType

func (V IoTProperty) ValidateType() error

* * 验证数据类型 *

type IoTPropertyBool

type IoTPropertyBool bool

bool

type IoTPropertyFloat

type IoTPropertyFloat float32

float

type IoTPropertyGeo

type IoTPropertyGeo struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

地理坐标系统

type IoTPropertyInteger

type IoTPropertyInteger int

int

type IoTPropertyRule

type IoTPropertyRule struct {
	DefaultValue any    `json:"defaultValue"`         // 默认值
	Max          int    `json:"max,omitempty"`        // 最大值
	Min          int    `json:"min,omitempty"`        // 最小值
	TrueLabel    string `json:"trueLabel,omitempty"`  // 真值label
	FalseLabel   string `json:"falseLabel,omitempty"` // 假值label
	Round        int    `json:"round,omitempty"`      // 小数点位
}

规则

type IoTPropertyString

type IoTPropertyString string

string

type IoTPropertyType

type IoTPropertyType string
const (
	// 目前边缘侧暂时只支持常见类型
	IoTPropertyTypeString  IoTPropertyType = "STRING"
	IoTPropertyTypeInteger IoTPropertyType = "INTEGER"
	IoTPropertyTypeFloat   IoTPropertyType = "FLOAT"
	IoTPropertyTypeBool    IoTPropertyType = "BOOL"
	IoTPropertyTypeGeo     IoTPropertyType = "GEO"
)

type IoTSchema

type IoTSchema struct {
	IoTProperties []IoTProperty `json:"iotProperties"`
}

* 物模型,边缘端目前暂时只支持属性 *

type SchemaRule

type SchemaRule interface {
	Validate(Value interface{}) error
}

* * 物模型规则 : String|Float|Int|Bool *

type StringRule

type StringRule struct {
	MaxLength    int    `json:"maxLength"`
	DefaultValue string `json:"defaultValue"`
}

* * 字符串规则 *

func (StringRule) Validate

func (S StringRule) Validate(Value interface{}) error

Jump to

Keyboard shortcuts

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