-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaselinker.go
49 lines (38 loc) · 1 KB
/
baselinker.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
package baselinker
import (
"encoding/json"
"net/url"
)
type BaseLinker struct {
Url string
Token string
}
type BaseResponse struct {
Status string `json:"status"`
ErrorMessage string `json:"error_message"`
ErrorCode string `json:"error_code"`
}
func (baseLinkerResponse *BaseResponse) IsSuccess() bool {
return baseLinkerResponse.Status == "SUCCESS"
}
func (baseLinkerResponse *BaseResponse) Error() string {
return baseLinkerResponse.ErrorMessage
}
func (baseLinkerResponse *BaseResponse) CodeError() string {
return baseLinkerResponse.ErrorCode
}
func NewBaseLinker(url string, token string) *BaseLinker {
return &BaseLinker{Url: url, Token: token}
}
func (baseLiner *BaseLinker) createRequestForm(method string, parameters interface{}) url.Values {
parametersJson, err := json.Marshal(parameters)
if nil != err {
return url.Values{}
}
formData := url.Values{
"token": {baseLiner.Token},
"method": {method},
"parameters": {string(parametersJson)},
}
return formData
}