github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/model/cluster_info.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  	"strings"
    10  )
    11  
    12  type ClusterInfo struct {
    13  	Id         string `json:"id"`
    14  	Version    string `json:"version"`
    15  	ConfigHash string `json:"config_hash"`
    16  	IpAddress  string `json:"ipaddress"`
    17  	Hostname   string `json:"hostname"`
    18  }
    19  
    20  func (me *ClusterInfo) ToJson() string {
    21  	b, _ := json.Marshal(me)
    22  	return string(b)
    23  }
    24  
    25  func (me *ClusterInfo) Copy() *ClusterInfo {
    26  	json := me.ToJson()
    27  	return ClusterInfoFromJson(strings.NewReader(json))
    28  }
    29  
    30  func ClusterInfoFromJson(data io.Reader) *ClusterInfo {
    31  	var me *ClusterInfo
    32  	json.NewDecoder(data).Decode(&me)
    33  	return me
    34  }
    35  
    36  func ClusterInfosToJson(objmap []*ClusterInfo) string {
    37  	b, _ := json.Marshal(objmap)
    38  	return string(b)
    39  }
    40  
    41  func ClusterInfosFromJson(data io.Reader) []*ClusterInfo {
    42  	decoder := json.NewDecoder(data)
    43  
    44  	var objmap []*ClusterInfo
    45  	if err := decoder.Decode(&objmap); err != nil {
    46  		return make([]*ClusterInfo, 0)
    47  	} else {
    48  		return objmap
    49  	}
    50  }