github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/model/cluster_message.go (about)

     1  // Copyright (c) 2016-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  const (
    12  	CLUSTER_EVENT_PUBLISH                                           = "publish"
    13  	CLUSTER_EVENT_UPDATE_STATUS                                     = "update_status"
    14  	CLUSTER_EVENT_INVALIDATE_ALL_CACHES                             = "inv_all_caches"
    15  	CLUSTER_EVENT_INVALIDATE_CACHE_FOR_REACTIONS                    = "inv_reactions"
    16  	CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK                      = "inv_webhook"
    17  	CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS                = "inv_channel_posts"
    18  	CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS = "inv_channel_members_notify_props"
    19  	CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS              = "inv_channel_members"
    20  	CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME              = "inv_channel_name"
    21  	CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL                      = "inv_channel"
    22  	CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER                         = "inv_user"
    23  	CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER                      = "clear_session_user"
    24  	CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES                        = "inv_roles"
    25  
    26  	CLUSTER_SEND_BEST_EFFORT = "best_effort"
    27  	CLUSTER_SEND_RELIABLE    = "reliable"
    28  )
    29  
    30  type ClusterMessage struct {
    31  	Event            string            `json:"event"`
    32  	SendType         string            `json:"-"`
    33  	WaitForAllToSend bool              `json:"-"`
    34  	Data             string            `json:"data,omitempty"`
    35  	Props            map[string]string `json:"props,omitempty"`
    36  }
    37  
    38  func (o *ClusterMessage) ToJson() string {
    39  	b, _ := json.Marshal(o)
    40  	return string(b)
    41  }
    42  
    43  func ClusterMessageFromJson(data io.Reader) *ClusterMessage {
    44  	var o *ClusterMessage
    45  	json.NewDecoder(data).Decode(&o)
    46  	return o
    47  }