forked from bandabh/phxgoclient
-
Notifications
You must be signed in to change notification settings - Fork 1
/
constants.go
61 lines (51 loc) · 1.34 KB
/
constants.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package phxgoclient
type Status string
type State string
type Event string
type Transport string
const (
PhxSocket Transport = "/websocket"
PhxLongPool Transport = "/longpoll"
)
func (transport Transport) ToPath() string {
return string(transport)
}
const (
OkStatus Status = "ok"
ErrorStatus Status = "error"
TimeoutStatus Status = "timeout"
)
const (
ClosedState State = "closed"
ErroredState State = "errored"
JoinedState State = "joined"
JoiningState State = "joining"
LeavingState State = "leaving"
)
const (
// MessageEvent represents a regular message on a topic.
MessageEvent Event = "phx_message"
// JoinEvent represents a successful join on a channel.
JoinEvent Event = "phx_join"
// CloseEvent represents the closing of a channel.
CloseEvent Event = "phx_close"
// ErrorEvent represents an error.
ErrorEvent Event = "phx_error"
// ReplyEvent represents a reply to a message sent on a topic.
ReplyEvent Event = "phx_reply"
// LeaveEvent represents leaving a channel and unsubscribing from a topic.
LeaveEvent Event = "phx_leave"
)
func (status Status) StatusToString() string {
return string(status)
}
func (state State) StateToString() string {
return string(state)
}
func (event Event) EventToString() string {
return string(event)
}
func ToEvent(str string) Event {
var event Event = Event(str)
return event
}