channel

package
v0.0.0-...-7a22eef Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOK    Status = "ok"
	StatusError Status = "error"

	TypeHearbeat EventType = "heartbeat"
	TypeEvent    EventType = "event"
	TypeJoin     EventType = "phx_join"
	TypeReply    EventType = "phx_reply"
	TypeLeave    EventType = "phx_leave"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel interface {
	Join(*melody.Session, *Message) (interface{}, error)
	Handle(*melody.Session, *Message) (interface{}, error)
	Leave(*melody.Session) error
}

type Event

type Event struct {
	Type  string `json:"type"`
	Event string `json:"event"`
	Value string `json:"value"`
}

type EventType

type EventType string

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

func NewHub

func NewHub() *Hub

func (*Hub) Broadcast

func (h *Hub) Broadcast(pattern string, event string, payload interface{}) error

func (*Hub) Register

func (h *Hub) Register(pattern string, channel Channel)

func (*Hub) ServeHTTP

func (h *Hub) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type Join

type Join struct {
	URL     string                 `json:"url"`
	Params  map[string]interface{} `json:"params"`
	Session string                 `json:"session"`
	Static  string                 `json:"static"`
}

type Message

type Message struct {
	JoinRef *string
	Ref     *string
	Topic   string
	Event   EventType
	Payload json.RawMessage
}

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(buf []byte) error

type Reply

type Reply struct {
	JoinRef *string     `json:"join_ref"`
	Ref     *string     `json:"ref"`
	Topic   string      `json:"topic"`
	Status  Status      `json:"status"`
	Payload interface{} `json:"payload"`
}

TODO combine with Message

func (*Reply) MarshalJSON

func (r *Reply) MarshalJSON() ([]byte, error)

func (*Reply) SetPayload

func (r *Reply) SetPayload(resp interface{}, err error)

type Response

type Response struct {
	Status   Status      `json:"status"`
	Response interface{} `json:"response"`
}

type Status

type Status string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL