-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctf.go
73 lines (57 loc) · 1.31 KB
/
ctf.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
package ctfbot
import (
"context"
"time"
)
type CTF struct {
ID int
Name string
Start time.Time
// Discord-related information.
RoleID string
CanJoin bool
// CTFTime infos.
CTFTimeURL string
// Metadata about creation.
CreatedAt time.Time
UpdatedAt time.Time
}
func (c *CTF) Validate() error {
if c.Name == "" {
return Errorf(EINVALID, "Name required.")
}
if c.RoleID == "" {
return Errorf(EINVALID, "Player role required.")
}
return nil
}
type CTFService interface {
// Creates a new CTF.
CreateCTF(ctx context.Context, ctf *CTF) error
// Retrieves a CTF by name.
FindCTFByName(ctx context.Context, name string) (*CTF, error)
// Retrieves a list of ctfs by filter.
FindCTFs(ctx context.Context, filter CTFFilter) ([]*CTF, int, error)
// Updates a CTF object.
UpdateCTF(ctx context.Context, name string, upd CTFUpdate) (*CTF, error)
// Permanently deletes a CTF.
DeleteCTF(ctx context.Context, name string) error
}
// CTFFilter represents a filter passed to FindCTFs().
type CTFFilter struct {
ID *int
Name *string
RoleID *string
CanJoin *bool
// Limit and offset.
Limit int
Offset int
}
// CTFUpdate represents a filter passed to UpdateCTF().
type CTFUpdate struct {
Name *string
RoleID *string
CanJoin *bool
CTFTimeURL *string
Start *time.Time
}