-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
57 lines (45 loc) · 1 KB
/
state.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
package main
import "fmt"
type State struct {
paired bool
connected bool
random string
}
func NewState() *State {
state := &State{}
state.paired = false
state.connected = false
return state
}
func (state *State) isPaired() bool {
return state.paired
}
func (state *State) isRandomNumber() bool {
return len(state.random) > 0
}
func (state *State) isConnected() bool {
return state.connected
}
func (state *State) Paired() {
fmt.Println("State changed to: paired")
state.paired = true
}
func (state *State) Unpaired() {
fmt.Println("State changed to: unpaired")
state.paired = false
}
func (state *State) Connected() {
fmt.Println("State changed to: connected")
state.connected = true
}
func (state *State) Disconnected() {
fmt.Println("State changed to: disconnected")
state.connected = false
}
func (state *State) SetRandomString(random string) {
fmt.Printf("Received random key: %s\n", random)
state.random = random
}
func (state *State) RandomString() string {
return state.random
}