This repository has been archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypes.go
163 lines (136 loc) · 3.95 KB
/
Types.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"github.com/labstack/echo"
)
const (
InsertFail = "insert-fail"
SelectFail = "select-fail"
UpdateFail = "update-fail"
DeleteFail = "delete-fail"
NoInsertID = "no-insert-id"
NoRowsAffected = "no-rows-affected"
)
var (
Functions = map[string] func(*APIRequest) *APIResponse {
"no-route": NoRoute,
"get-all-accounts": GetAccounts,
"add-account": AddAccount,
"get-account": GetAccount,
"update-account": UpdateAccount,
"delete-account": DeleteAccount,
"lock-account": LockAccount,
"ban-account": BanAccount,
"create-account": CreateAccount,
"get-create-account-status": GetCreateAccountStatus,
"reset-password": ResetAccountPassword,
"get-reset-password-status": GetResetPasswordStatus,
"get-all-clients": GetAllClients,
"add-client": AddClient,
"get-client": GetClient,
"update-client": UpdateClient,
"delete-client": DeleteClient,
"get-clients-for-server": GetClientsForServer,
}
)
type Account struct {
ID int64 `json:"id" db:"ID" static:"true"`
UserID int64 `json:"userid" db:"UserID" static:"true"`
Email string `json:"email" db:"Email"`
Password string `json:"password" db:"Password"`
Locks int64 `json:"locks" db:"Locks"`
Locked bool `json:"locked" db:"Locked"`
Banned bool `json:"banned" db:"Banned"`
}
type User struct {
ID int64 `json:"id" db:"ID" static:"true"`
Email string `json:"email" db:"Email" static:"true"`
Password string `json:"password" db:"Password"`
ApiKey string `json:"email" db:"ApiKey"`
}
func BindAccount(c echo.Context) *Account {
account := new(Account)
if err := c.Bind(account); err != nil {
return nil
}
if id, ok := ParamToInt64(c, "id"); ok {
account.ID = id
}
return account
}
type AccountCreationRequest struct {
ID int64 `json:id db:"ID" static:"true"`
UserID int64 `json:userid db:"UserID" static:"true"`
Email string `json:email`
DisplayName string `json:display_name`
Password string `json:password`
Age int64 `json:age`
AccountID int64 `json:accountid`
StartTime int64 `json:start_time`
EndTime int64 `json:end_time`
Status string `json:status`
}
func BindAccountCreationRequest(c echo.Context) *AccountCreationRequest {
request := new(AccountCreationRequest)
if err := c.Bind(request); err != nil {
return nil
}
if id, ok := ParamToInt64(c, "id"); ok {
request.ID = id
}
return request
}
type PasswordResetRequest struct {
ID int64 `json:"id" db:"ID" static:"true"`
UserID int64 `json:userid db:"UserID" static:"true"`
AccountID int64 `json:accountid db:"AccountID" static:"true"`
NewPassword string `json:new_password`
RequestURL string `json:request_url`
StartTime int64 `json:start_time`
EndTime int64 `json:end_time`
Status string `json:status`
}
func BindPasswordResetRequest(c echo.Context) *PasswordResetRequest {
request := new(PasswordResetRequest)
if err := c.Bind(request); err != nil {
return nil
}
if id, ok := ParamToInt64(c, "id"); ok {
request.ID = id
}
return request
}
type Server struct {
ID int64 `json:"id" db:"ID" static:"true"`
UserID int64 `json:userid db:"UserID" static:"true"`
IPAddress int64 `json:ip_address db:"IPAddress" static:"true"`
Name string `json:name`
}
func BindServer(c echo.Context) *Server {
server := new(Server)
if err := c.Bind(server); err != nil {
return nil
}
if id, ok := ParamToInt64(c, "id"); ok {
server.ID = id
}
return server
}
type Client struct {
ID int64 `json:"id" db:"ID" static:"true"`
UserID int64 `json:"userid" db:"UserID" static:"true"`
ServerID int64 `json:"serverid" db:"ServerID" static:"true"`
AccountID int64 `json:"accountid" db:"AccountID"`
ScriptName string `json:"script_name" db:"ScriptName"`
ScriptArguments string `json:"script_arguments" db:"ScriptArguments"`
World int64 `json:"world" db:"World"`
}
func BindClient(c echo.Context) *Client {
client := new(Client)
if err := c.Bind(client); err != nil {
return nil
}
if id, ok := ParamToInt64(c, "id"); ok {
client.ID = id
}
return client
}