This commit is contained in:
Sun
2023-11-08 21:53:07 +08:00
commit 211c3071dc
245 changed files with 39293 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
package datatype
import (
"database/sql/driver"
"encoding/json"
"errors"
"fmt"
)
// 项目配置 可用
type MapJson map[string]interface{}
// 查询的时候解析
func (j *MapJson) Scan(value interface{}) error {
bytes, ok := value.([]byte)
if !ok {
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
}
err := json.Unmarshal(bytes, j)
return err
}
// 保存时的编译
func (j MapJson) Value() (driver.Value, error) {
str, err := json.Marshal(j)
if err != nil {
return string(str), err
}
return string(str), nil
}
type JSON json.RawMessage
// 实现 sql.Scanner 接口,Scan 将 value 扫描至 Jsonb
func (j *JSON) Scan(value interface{}) error {
bytes, ok := value.([]byte)
if !ok {
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
}
result := json.RawMessage{}
err := json.Unmarshal(bytes, &result)
*j = JSON(result)
return err
}
// 实现 driver.Valuer 接口,Value 返回 json value
func (j JSON) Value() (driver.Value, error) {
if len(j) == 0 {
return nil, nil
}
return json.RawMessage(j).MarshalJSON()
}
+8
View File
@@ -0,0 +1,8 @@
package datatype
type ItemIconIconInfo struct {
ItemType int `json:"itemType"`
Src string `json:"src"`
Text string `json:"text"`
BgColor string `json:"bgColor"`
}