-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.go
More file actions
43 lines (34 loc) · 763 Bytes
/
events.go
File metadata and controls
43 lines (34 loc) · 763 Bytes
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
package esl
import (
"errors"
"time"
)
// Event hold information regarding
type Event struct {
Message chan *Message
}
// ESL is the structure for all type of events and commands
type ESL struct {
socket *Socket
funcs map[string][]func(Event)
loggedIn bool
}
// NewESL create a new ESL, and does a login
func NewESL(host string, password string, maxRetries uint64, timeout time.Duration) (*ESL, error) {
esl := ESL{}
socket, err := Dial(host, password, maxRetries, timeout)
if err != nil {
return nil, err
}
esl.socket = socket
if !esl.socket.LoggedIn() {
loggedIn, err := esl.socket.Login()
if err != nil {
return nil, err
}
if !loggedIn {
return nil, errors.New("Unable to loggin, but no error")
}
}
return &esl, nil
}