forked from sionide21/Go2Lunch
/
common.go
75 lines (61 loc) · 1.16 KB
/
common.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"strconv"
"bytes"
)
type Byter interface {
Byte() []byte
}
type AddPlaceArgs struct {
Auth
Name string
}
func (a *AddPlaceArgs) Byte() []byte {
b := bytes.NewBufferString(a.Name)
return b.Bytes()
}
type UIntArgs struct {
Auth
Num uint
}
func (a *UIntArgs) Byte() []byte {
b := bytes.NewBufferString(strconv.Uitoa(a.Num))
return b.Bytes()
}
type EmptyArgs struct {
Auth
}
func (a *EmptyArgs) Byte() []byte {
return make([]byte, 1)
}
type Person struct {
CanDrive bool
Name string
NumSeats uint
NominationsLeft uint
}
func (p *Person) String() string {
str := p.Name
if p.CanDrive {
str += " [" + strconv.Uitoa(p.NumSeats) + " seats]"
}
return str
}
type Place struct {
Id uint
Name string
Votes uint
People []*Person
Nominator *Person
}
type Auth struct {
Name string
Mac, CChallenge, SChallenge []byte
}
func (p *Place) String() string {
str := strconv.Uitoa(p.Id) + ") " + p.Name + " nominated by " + p.Nominator.Name + " [" + strconv.Uitoa(p.Votes) + " votes]"
for _, person := range p.People {
str += "\n - " + person.String()
}
return str
}