parser.go 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
package model

type _base struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

type ModelLink struct {
	_base
	Protocol string `json:"protocol"`
}

type ModelVariable struct {
	_base
	Link     string `json:"link"`
	Type     string `json:"type"`
	Addr     string `json:"addr"`
	Default  string `json:"default"`
	Writable bool   `json:"writable"` //可写,用于输出(如开关)

	//TODO 采样:无、定时、轮询
	Cron string `json:"cron"`

	Children []ModelVariable `json:"children"`
}

type ModelBatchResult struct {
	Offset   int    `json:"offset"`
	Variable string `json:"variable"` //ModelVariable path
}

type ModelBatch struct {
	_base
	Link string `json:"link"`
	Type string `json:"type"`
	Addr string `json:"addr"`
	Size int    `json:"size"`
	Cron string `json:"cron"`

	Results []ModelBatchResult `json:"results"`
}

type ModelJob struct {
	_base
	Cron   string `json:"cron"`
	Script string `json:"script"` //javascript
}

type ModelStrategy struct {
	_base
	Script string `json:"script"` //javascript
}

type Model struct {
	_base

	Version string `json:"version"`
	H5      string `json:"h5"`

	Links      []ModelLink     `json:"links"`
	Variables  []ModelVariable `json:"variables"`
	Batches    []ModelBatch    `json:"batches"`
	Jobs       []ModelJob      `json:"jobs"`
	Strategies []ModelStrategy `json:"strategies"`
}

func Import(json string) error {
	//TODO parser model, import
	return nil
}

func Export(id int) string {
	//TODO ge
	return ""
}