diff --git a/config/form.go b/config/form.go new file mode 100644 index 0000000..5d0f120 --- /dev/null +++ b/config/form.go @@ -0,0 +1,70 @@ +package config + +import "encoding/json" + +const ( + FormTypeText = "text" //文本输入框 + FormTypeTextarea = "textarea" //多行文本 + FormTypeRadio = "radio" //单选框 + FormTypeCheckbox = "checkbox" //单选框 + FormTypeSwitch = "switch" //开关 + FormTypeJson = "json" //JSON输入框 +) + +type FormOption struct { + Name string `json:"name"` //选项名称 + Value string `json:"value"` //选项值 +} + +type Form struct { + Type string `json:"type"` //表单类型 + Name string `json:"name"` //表单名称 + Key string `json:"key"` //表单KEY + Value string `json:"value"` //表单值 + Help string `json:"help"` //表单提示 + Options []*FormOption `json:"options"` //表单选项,radion和checkbox需要 +} + +func NewFroms(tplConfig, saveConfig string) ([]*Form, error) { + var forms []*Form + err := json.Unmarshal([]byte(tplConfig), &forms) + if err != nil { + return nil, err + } + + var cfg map[string]string + err = json.Unmarshal([]byte(saveConfig), &cfg) + if err != nil { + return nil, err + } + if cfg == nil { + cfg = map[string]string{} + } + + for _, form := range forms { + if _, ok := cfg[form.Key]; ok { + form.Value = cfg[form.Key] + } + } + return forms, err +} + +func MergeConfig(oldConfig, newConfig string) (string, error) { + var oldCfg map[string]interface{} + var newCfg map[string]interface{} + json.Unmarshal([]byte(oldConfig), &oldCfg) + json.Unmarshal([]byte(newConfig), &newCfg) + if oldCfg == nil { + oldCfg = make(map[string]interface{}) + } + if newCfg == nil { + newCfg = make(map[string]interface{}) + } + + for k, v := range newCfg { + oldCfg[k] = v + } + + res, _ := json.Marshal(oldCfg) + return string(res), nil +} diff --git a/go.mod b/go.mod index bc691ea..8621b72 100644 --- a/go.mod +++ b/go.mod @@ -1,58 +1,3 @@ -module git.u8t.cn/open/gosdk +module gosdk -go 1.18 - -require ( - github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 - github.com/eclipse/paho.mqtt.golang v1.4.3 - github.com/gin-gonic/gin v1.9.1 - github.com/gomodule/redigo v1.8.9 - github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c - github.com/minio/minio-go v6.0.14+incompatible - github.com/qiniu/go-sdk/v7 v7.21.1 - github.com/sirupsen/logrus v1.9.3 - github.com/smbrave/goutil v0.0.0-20240105134047-64fe0dfafba2 - github.com/spf13/cast v1.6.0 - github.com/tidwall/gjson v1.17.1 - github.com/wechatpay-apiv3/wechatpay-go v0.2.18 - golang.org/x/crypto v0.25.0 - gorm.io/gorm v1.25.6 -) - -require ( - github.com/BurntSushi/toml v1.3.2 // indirect - github.com/alex-ant/gomath v0.0.0-20160516115720-89013a210a82 // indirect - github.com/bytedance/sonic v1.9.1 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect - github.com/gin-contrib/sse v0.1.0 // indirect - github.com/go-ini/ini v1.67.0 // indirect - github.com/go-playground/locales v0.14.1 // indirect - github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.14.0 // indirect - github.com/goccy/go-json v0.10.2 // indirect - github.com/gofrs/flock v0.8.1 // indirect - github.com/gorilla/websocket v1.5.0 // indirect - github.com/jinzhu/inflection v1.0.0 // indirect - github.com/jinzhu/now v1.1.5 // indirect - github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.4 // indirect - github.com/leodido/go-urn v1.2.4 // indirect - github.com/matishsiao/goInfo v0.0.0-20210923090445-da2e3fa8d45f // indirect - github.com/mattn/go-isatty v0.0.19 // indirect - github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.0.8 // indirect - github.com/tidwall/match v1.1.1 // indirect - github.com/tidwall/pretty v1.2.0 // indirect - github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect - golang.org/x/arch v0.3.0 // indirect - golang.org/x/net v0.27.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/text v0.16.0 // indirect - google.golang.org/protobuf v1.30.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) +go 1.24