forked from lmas/ss13.se
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstorage.go
59 lines (48 loc) · 1.16 KB
/
storage.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
package ss13_se
import (
"html/template"
"net/url"
"time"
)
type ServerEntry struct {
ID string `db:"id"`
Title string `db:"title"`
SiteURL string `db:"site_url"`
GameURL string `db:"game_url"`
Time time.Time `db:"time"`
Players int `db:"players"`
}
func (e ServerEntry) IsZero() bool {
return e.ID == ""
}
func (e ServerEntry) LastUpdated() string {
return e.Time.Format("2006-01-02 15:04 MST")
}
func (e ServerEntry) ByondURL() template.URL {
u, err := url.Parse(e.GameURL)
if err != nil {
return ""
}
if u.Scheme != "byond" {
return ""
}
return template.URL(u.String())
}
type ServerPoint struct {
Time time.Time `db:"time"`
ServerID string `db:"server_id"`
Players int `db:"players"`
}
func (p ServerPoint) IsZero() bool {
return p.ServerID == "" && p.Time.IsZero()
}
type Storage interface {
Open() error
SaveServers([]ServerEntry) error
GetServer(string) (ServerEntry, error)
GetServers() ([]ServerEntry, error)
RemoveServers([]ServerEntry) error
SaveServerHistory([]ServerPoint) error
GetServerHistory(int) ([]ServerPoint, error)
GetSingleServerHistory(string, int) ([]ServerPoint, error)
}