github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/services/remotecluster/response.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package remotecluster
     5  
     6  import (
     7  	"encoding/json"
     8  )
     9  
    10  // Response represents the bytes replied from a remote server when a message is sent.
    11  type Response struct {
    12  	Status  string          `json:"status"`
    13  	Err     string          `json:"err"`
    14  	Payload json.RawMessage `json:"payload"`
    15  }
    16  
    17  // IsSuccess returns true if the response status indicates success.
    18  func (r *Response) IsSuccess() bool {
    19  	return r.Status == ResponseStatusOK
    20  }
    21  
    22  // SetPayload serializes an arbitrary struct as a RawMessage.
    23  func (r *Response) SetPayload(v interface{}) error {
    24  	raw, err := json.Marshal(v)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	r.Payload = raw
    29  	return nil
    30  }