package common_models import "encoding/json" type Formula struct { Id int `json:"id"` Expression string `json:"expression"` Params []FormulaParam `json:"params"` IoFields IoFields `json:"ioFields"` Type string `json:"type"` } // redis序列化 func (m *Formula) MarshalBinary() (data []byte, err error) { return json.Marshal(m) } // redis序列化 func (m *Formula) UnmarshalBinary(data []byte) error { return json.Unmarshal(data, m) } type FormulaParam struct { Name string `json:"name"` Alias string `json:"alias"` Unit string `json:"unit"` Default float64 `json:"default"` } type IoFields struct { Input []ItemParam `json:"input"` Output []ItemParam `json:"output"` } func (the *IoFields) GetInFieldUnit(Field string) string { for _, InField := range the.Input { if InField.Name == Field { return InField.Unit } } return "" } func (the *IoFields) GetOutFieldUnit(Field string) string { for _, OutField := range the.Output { if OutField.Name == Field { return OutField.Unit } } return "" } type ItemParam struct { Name string `json:"name"` Unit string `json:"unit"` }