package model import ( "database/sql/driver" "fmt" "strings" ) type Forward struct { Id int `json:"id"` Name string `json:"name"` LocalIp string `json:"local_ip"` LocalPort int `json:"local_port"` TargetAddr StringList `json:"target_addr"` Protocol int `json:"protocol"` Status int `json:"status"` CreateTime string `json:"create_time"` UpdateTime string `json:"update_time"` } type StringList []string func (s *StringList) Scan(value interface{}) error { v, ok := value.(string) if !ok { return fmt.Errorf("value is not string") } *s = strings.Split(v, ",") return nil } func (s StringList) Value() (driver.Value, error) { if len(s) == 0 { return "", nil } return strings.Join(s, ","), nil }