summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/mattermost-server/v6/model/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v6/model/utils.go')
-rw-r--r--vendor/github.com/mattermost/mattermost-server/v6/model/utils.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v6/model/utils.go b/vendor/github.com/mattermost/mattermost-server/v6/model/utils.go
index fab3f494..c57716f7 100644
--- a/vendor/github.com/mattermost/mattermost-server/v6/model/utils.go
+++ b/vendor/github.com/mattermost/mattermost-server/v6/model/utils.go
@@ -6,6 +6,7 @@ package model
import (
"bytes"
"crypto/rand"
+ "database/sql/driver"
"encoding/base32"
"encoding/json"
"fmt"
@@ -24,6 +25,7 @@ import (
"github.com/mattermost/mattermost-server/v6/shared/i18n"
"github.com/pborman/uuid"
+ "github.com/pkg/errors"
)
const (
@@ -72,6 +74,30 @@ func (sa StringArray) Equals(input StringArray) bool {
return true
}
+// Value converts StringArray to database value
+func (sa StringArray) Value() (driver.Value, error) {
+ return json.Marshal(sa)
+}
+
+// Scan converts database column value to StringArray
+func (sa *StringArray) Scan(value interface{}) error {
+ if value == nil {
+ return nil
+ }
+
+ buf, ok := value.([]byte)
+ if ok {
+ return json.Unmarshal(buf, sa)
+ }
+
+ str, ok := value.(string)
+ if ok {
+ return json.Unmarshal([]byte(str), sa)
+ }
+
+ return errors.New("received value is neither a byte slice nor string")
+}
+
var translateFunc i18n.TranslateFunc
var translateFuncOnce sync.Once