Documentation ¶
Index ¶
- Variables
- func DecodeMsg(rawMsg []byte, v interface{}) error
- func EncodeMsg(msg interface{}) ([]byte, error)
- func IsType(msgType, part string) bool
- type BaseMsg
- type BaseMsger
- type ChatMsg
- type ChatMsger
- type CmdMsg
- type ConnMsg
- type ConnState
- type DecodeMsgError
- type EnterMsg
- type EntityInfo
- type IDInfo
- type KeyValueInfo
- type LeaveMsg
- type MediaInfo
- type MemberChangedMsg
- type MemberInfo
- type Message
- type MessageInfo
- type Msger
- type NetMsg
- type NetMsger
- type NetworkStateInfo
- type ProtocolStateInfo
- type StateEntry
- type StateMsg
- type Statuser
- type SubscribeMsg
- type SubscriptionStateInfo
- type TypeInfo
- type TypingMsg
- type UserChangedMsg
- type UserInfo
- type ValuesInfo
- func (vi *ValuesInfo) Add(key, value string) *ValuesInfo
- func (vi ValuesInfo) AppendAll(result []string, key string) []string
- func (vi ValuesInfo) Get(key string) string
- func (vi ValuesInfo) GetAll(key string) []string
- func (vi ValuesInfo) Lookup(key string) (string, bool)
- func (vi *ValuesInfo) Set(key, value string) *ValuesInfo
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidMsg = errors.New("not a valid message")
var JSON basicJSONer = json
JSON encoder/decoder. Marshal, MarshalIndent, Unmarshal.
Functions ¶
func DecodeMsg ¶
DecodeMsg decodes rawMsg bytes into v. Error returned will be of type DecodeMsgError, use Unwrap to get the error from the JSON unmarshaller.
Types ¶
type BaseMsg ¶
type BaseMsg struct { TypeInfo // msg/* info/* group-enter/* other/* ... ID string `json:"id"` Protocol string `json:"proto,omitempty"` // empty if not from the protocol. Time time.Time `json:"time,omitempty"` // can be zero if from client. Message MessageInfo `json:"msg,omitempty"` Values ValuesInfo `json:"values,omitempty"` }
BaseMsg is the basis for a msg.
func (*BaseMsg) GetBaseMsg ¶
func (BaseMsg) GetMessage ¶
func (BaseMsg) GetMessageString ¶
func (*BaseMsg) GetProtocol ¶
type BaseMsger ¶
type BaseMsger interface { Msger GetBaseMsg() *BaseMsg GetID() string GetMessage(msgType string) Message GetMessageString() string }
BaseMsger is anything based on BaseMsg.
func ParseBaseMsg ¶
ParseBaseMsg parses rawMsg JSON into a specific base msg type.
type ChatMsg ¶
type ChatMsg struct { NetMsg Destination EntityInfo `json:"dest,omitempty"` From EntityInfo `json:"from,omitempty"` ReplyToID string `json:"replyTo,omitempty"` Attachments []MediaInfo `json:"attachments,omitempty"` }
ChatMsg is a chat msg.
func (*ChatMsg) GetChatMsg ¶
type CmdMsg ¶
type CmdMsg struct { BaseMsg Network EntityInfo `json:"net,omitempty"` // optional, if applicable. Command string `json:"cmd"` Args []string `json:"args,omitempty"` }
CmdMsg is a msg for a command. The Message should be empty, it is reserved for future use.
func NewLogout ¶
NewLogout is a logout request. logoutID can be the network ID or conn ID (if applicable)
func NewLogoutReason ¶
NewLogoutReason is NewLogout with a reason for logging out. The reason may (or may not) be announced to chat users as a leave message.
func (CmdMsg) GetNetwork ¶
func (msg CmdMsg) GetNetwork() EntityInfo
GetNetwork gets the network, this is optional!
type ConnMsg ¶
type ConnMsg struct { NetMsg Connection EntityInfo `json:"conn"` State ConnState `json:"state"` Cause string `json:"cause,omitempty"` }
ConnMsg is a msg for a connection. An implementation is not required to use all the ConnState values, but at least Connected and Disconnected are needed. Note: the value of Cause may change or may be removed completely!
type ConnState ¶
type ConnState string
ConnState represents the connection state. Note that ConnectFailed during Connecting or Reconnecting does not indicate the end of the connection attempt, a Disconnected does. ConnectFailed goes to the conn topic, not error; it is a ConnMsg and is not an exceptional error.
type DecodeMsgError ¶
type DecodeMsgError struct {
// contains filtered or unexported fields
}
func (*DecodeMsgError) Error ¶
func (err *DecodeMsgError) Error() string
func (*DecodeMsgError) Unwrap ¶
func (err *DecodeMsgError) Unwrap() error
type EnterMsg ¶
type EnterMsg struct { ChatMsg Member MemberInfo `json:"member"` // the member who entered. }
EnterMsg is about a member entering a chat.
type EntityInfo ¶
EntityInfo represents an entity with an ID, optional name and a type.
func (*EntityInfo) Init ¶
func (x *EntityInfo) Init(id, typ string)
type IDInfo ¶
type IDInfo struct { ID string `json:"id"` Name string `json:"name,omitempty"` // use GetName DisplayName string `json:"dispName,omitempty"` // use GetDisplayName }
IDInfo has information on an object's ID and name. Name and DisplayName are both optional, they fallback to Name and ID if empty.
func (IDInfo) GetDisplayName ¶
GetName gets the display name (or name if no display name)
type KeyValueInfo ¶
type KeyValueInfo [2]string
KeyValueInfo represents a key-value pair. [0] is the key name, [1] is the value.
type LeaveMsg ¶
type LeaveMsg struct { ChatMsg User EntityInfo `json:"user"` // the member who left. }
LeaveMsg is about a member leaving a chat.
type MediaInfo ¶
type MediaInfo struct { TypeInfo // MIME type, or hint such as "image/*" Name string `json:"name,omitempty"` // Default is file name from URL. URL string `json:"url"` ThumbURL string `json:"thumb,omitempty"` // optional thumbnail. Expires time.Time `json:"expires,omitempty"` // When the URL expires. Values ValuesInfo `json:"values,omitempty"` }
MediaInfo has info related to media, such as an image or video.
func (MediaInfo) GetDisplayName ¶
func (*MediaInfo) MarshalJSON ¶
type MemberChangedMsg ¶
type MemberChangedMsg struct { ChatMsg User EntityInfo `json:"user"` // the user who changed. Member MemberInfo `json:"member"` // the updated member. }
MemberChangedMsg is a msg about a member changing in a chat.
type MemberInfo ¶
type MemberInfo struct { TypeInfo // member Info UserInfo `json:"info"` Values ValuesInfo `json:"values,omitempty"` // member values. }
MemberInfo has information on a chat member.
type Message ¶
Message is a message in a specific MIME type. Text types are assumed to be in UTF-8 unless otherwise specified.
type MessageInfo ¶
type MessageInfo []Message
MessageInfo represents a message in various types/formats.
func (MessageInfo) Get ¶
func (msg MessageInfo) Get(msgType string) Message
Get message in the specified type, or an empty message.
func (*MessageInfo) Set ¶
func (msg *MessageInfo) Set(msgType, content string)
func (*MessageInfo) SetText ¶
func (msg *MessageInfo) SetText(content string)
SetText in text/plain type.
func (MessageInfo) String ¶
func (msg MessageInfo) String() string
String returns the content for text/plain, or empty string.
type NetMsg ¶
type NetMsg struct { BaseMsg Network EntityInfo `json:"net"` }
NetMsg is a generic network message.
func (NetMsg) GetNetwork ¶
func (msg NetMsg) GetNetwork() EntityInfo
type NetMsger ¶
type NetMsger interface { BaseMsger GetNetwork() EntityInfo }
NetMsger is any base msg which also has a network.
type NetworkStateInfo ¶
type NetworkStateInfo struct { TypeInfo // network-state Network EntityInfo `json:"net"` Protocol string `json:"proto"` Connection EntityInfo `json:"conn,omitempty"` // Optional, if connections. Myself EntityInfo `json:"myself"` Values ValuesInfo `json:"values,omitempty"` Ready bool `json:"ready"` }
NetworkStateInfo is network state information.
func (NetworkStateInfo) GetProtocol ¶
func (x NetworkStateInfo) GetProtocol() string
func (NetworkStateInfo) String ¶
func (x NetworkStateInfo) String() string
type ProtocolStateInfo ¶
type ProtocolStateInfo struct { TypeInfo // proto-state Protocol string `json:"proto"` Values ValuesInfo `json:"values,omitempty"` }
ProtocolStateInfo is protocol state information.
func (ProtocolStateInfo) GetProtocol ¶
func (x ProtocolStateInfo) GetProtocol() string
func (ProtocolStateInfo) String ¶
func (x ProtocolStateInfo) String() string
type StateEntry ¶
type StateEntry struct {
Statuser
}
func (StateEntry) MarshalJSON ¶
func (se StateEntry) MarshalJSON() ([]byte, error)
func (StateEntry) UnmarshalJSON ¶
func (se StateEntry) UnmarshalJSON(data []byte) error
type StateMsg ¶
type StateMsg struct { BaseMsg // The protocol is empty. List []StateEntry `json:"list"` }
type SubscribeMsg ¶
type SubscribeMsg struct { ChatMsg Subject MessageInfo `json:"subject,omitempty"` Photo MediaInfo `json:"photo,omitempty"` // URL or no photo. Members []MemberInfo `json:"members,omitempty"` // includes myself on subscribe. Myself EntityInfo `json:"myself"` // myself as the new member. HistoryURL string `json:"history,omitempty"` // see SubscriptionStateInfo }
SubscribeMsg is a msg about yourself subscribing or unsubscribing to a chat. Myself is not a MemberInfo because Members includes myself, and SubscribeMsg is also reused for leaving, which has no need for MemberInfo. See the destination type for the type of chat.
type SubscriptionStateInfo ¶
type SubscriptionStateInfo struct { TypeInfo // subscription-state Network EntityInfo `json:"net"` Protocol string `json:"proto"` Destination EntityInfo `json:"dest"` Subject MessageInfo `json:"subject,omitempty"` Members []MemberInfo `json:"members,omitempty"` Values ValuesInfo `json:"values,omitempty"` HistoryURL string `json:"history,omitempty"` // empty if not supported. }
SubscriptionStateInfo is subscription state information. HistoryURL can be a URL with a known JSON REST API to fetch history, if supported. TODO: define history API.
func (SubscriptionStateInfo) GetProtocol ¶
func (x SubscriptionStateInfo) GetProtocol() string
func (SubscriptionStateInfo) String ¶
func (x SubscriptionStateInfo) String() string
type TypeInfo ¶
type TypeInfo struct {
Type string `json:"type"`
}
TypeInfo has information on the type of an object.
type TypingMsg ¶
type TypingMsg struct { ChatMsg // typing Typing bool `json:"typing"` Expires time.Time `json:"expires,omitempty"` // Optional; when typing state expires. }
TypingMsg a msg for a user typing a message. Destination is where they are typing.
type UserChangedMsg ¶
type UserChangedMsg struct { NetMsg User EntityInfo `json:"user"` // the user who changed. Info UserInfo `json:"info"` // the changes. Myself bool `json:"myself,omitempty"` }
UserChangedMsg is a msg about a user changing.
type UserInfo ¶
type UserInfo struct { User EntityInfo `json:"user"` // user Photo MediaInfo `json:"photo,omitempty"` // URL or no photo. Values ValuesInfo `json:"values,omitempty"` // user values. }
UserInfo has information on a user.
type ValuesInfo ¶
type ValuesInfo []KeyValueInfo
ValuesInfo represents zero or more auxiliary key-value pairs. Protocol-specific keys are PROTO.* and adhere to that protocol. Implementation-specific keys are x-NAME.* or PROTO.x-NAME.* (depending on scope) Duplicate keys are valid.
func (*ValuesInfo) Add ¶
func (vi *ValuesInfo) Add(key, value string) *ValuesInfo
Add the specified key and value, regardless if the key exists or not.
func (ValuesInfo) AppendAll ¶
func (vi ValuesInfo) AppendAll(result []string, key string) []string
AppendAll appends all the values for the specified key and returns the updates.
func (ValuesInfo) Get ¶
func (vi ValuesInfo) Get(key string) string
Get the value of the specified key, or empty string.
func (ValuesInfo) GetAll ¶
func (vi ValuesInfo) GetAll(key string) []string
GetAll returns all the values for the specified key, or nil if none.
func (ValuesInfo) Lookup ¶
func (vi ValuesInfo) Lookup(key string) (string, bool)
Lookup the value of the specified key, returns true if found.
func (*ValuesInfo) Set ¶
func (vi *ValuesInfo) Set(key, value string) *ValuesInfo
Set will update the value for an existing key, or add the new key-value pair. If more than one matching key exists, updates only the first and ignores the rest.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package provider is a helper package for writing a service provider.
|
Package provider is a helper package for writing a service provider. |