Initialize AutoLibrary website with Gitea deployment
This commit is contained in:
commit
18216953e7
101 files changed
+12581
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package base_model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"database/sql/driver"
|
||||
)
|
||||
|
||||
type StringArray []string
|
||||
|
||||
func (s StringArray) Value() (driver.Value, error) {
|
||||
if len(s) == 0 {
|
||||
return "[]", nil // empty array
|
||||
}
|
||||
return json.Marshal(s)
|
||||
}
|
||||
|
||||
func (s *StringArray) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
*s = StringArray{}
|
||||
return nil
|
||||
}
|
||||
|
||||
var bytes []byte
|
||||
switch v := value.(type) {
|
||||
case []byte:
|
||||
bytes = v
|
||||
case string:
|
||||
bytes = []byte(v)
|
||||
default:
|
||||
return fmt.Errorf("unsupported type: %T", value)
|
||||
}
|
||||
|
||||
if len(bytes) == 0 {
|
||||
*s = StringArray{}
|
||||
return nil
|
||||
}
|
||||
|
||||
if string(bytes) == "[]" {
|
||||
*s = StringArray{}
|
||||
return nil
|
||||
}
|
||||
|
||||
return json.Unmarshal(bytes, s)
|
||||
}
|
||||
Reference in new issue
Block a user