1 回答

TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊
根據(jù)注釋和此鏈接,一個(gè)選項(xiàng)是創(chuàng)建自定義類型。Tags
type Tags []string
//Implement Scanner interface
func (t *Tags) Scan(value interface{}) error {
val, ok := value.([]byte)
if !ok {
return errors.New(fmt.Sprint("wrong type", value))
}
*t = Tags(strings.Split(string(val), ","))
return nil
}
//Implement Valuer interface
func (t Tags) Value() (driver.Value, error) {
//this check is here if you don't want to save an empty string
if len(t) == 0 {
return nil, nil
}
return []byte(strings.Join(t, ",")), nil
}
- 1 回答
- 0 關(guān)注
- 216 瀏覽
添加回答
舉報(bào)