forked from predbdotovh/pre-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnuke.go
More file actions
44 lines (35 loc) · 928 Bytes
/
Copy pathnuke.go
File metadata and controls
44 lines (35 loc) · 928 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
44
package main
import "database/sql"
const nukeTable = "nuke"
type nuke struct {
ID int `json:"id"`
TypeID int `json:"typeId"`
Type string `json:"type"`
PreID int `json:"preId"`
Reason string `json:"reason"`
Net string `json:"net"`
source string
NukeAt int64 `json:"nukeAt"`
}
var nukeTypes = map[int]string{
1: "nuke",
2: "unnuke",
3: "modnuke",
4: "delpre",
5: "undelpre",
}
func (n *nuke) setType() {
if n.Type == "" {
n.Type = nukeTypes[n.TypeID]
}
}
func getNuke(db *sql.DB, preID int) (*nuke, error) {
sqlQuery := "SELECT id, pre_id, nuke_id, reason, net, source, UNIX_TIMESTAMP(set_at) FROM " + nukeTable +
" WHERE pre_id = ? ORDER BY id DESC LIMIT 1"
var r nuke
err := db.QueryRow(sqlQuery, preID).Scan(&r.ID, &r.PreID, &r.TypeID, &r.Reason, &r.Net, &r.source, &r.NukeAt)
if err != nil {
return nil, err
}
return &r, nil
}