github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/model/analytics_row.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 AnalyticsRow struct { 12 Name string `json:"name"` 13 Value float64 `json:"value"` 14 } 15 16 type AnalyticsRows []*AnalyticsRow 17 18 func (me *AnalyticsRow) ToJson() string { 19 b, _ := json.Marshal(me) 20 return string(b) 21 } 22 23 func AnalyticsRowFromJson(data io.Reader) *AnalyticsRow { 24 var me *AnalyticsRow 25 json.NewDecoder(data).Decode(&me) 26 return me 27 } 28 29 func (me AnalyticsRows) ToJson() string { 30 if b, err := json.Marshal(me); err != nil { 31 return "[]" 32 } else { 33 return string(b) 34 } 35 } 36 37 func AnalyticsRowsFromJson(data io.Reader) AnalyticsRows { 38 var me AnalyticsRows 39 json.NewDecoder(data).Decode(&me) 40 return me 41 }