github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/model/preferences.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "encoding/json" 8 "io" 9 ) 10 11 type Preferences []Preference 12 13 func (o *Preferences) ToJson() string { 14 b, _ := json.Marshal(o) 15 return string(b) 16 } 17 18 func PreferencesFromJson(data io.Reader) (Preferences, error) { 19 decoder := json.NewDecoder(data) 20 var o Preferences 21 err := decoder.Decode(&o) 22 if err == nil { 23 return o, nil 24 } else { 25 return nil, err 26 } 27 }