-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_api.go
45 lines (38 loc) · 1.02 KB
/
basic_api.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
package seatapi
import (
"fmt"
"strings"
)
// SeaTableApi 接口
type SeaTableApi struct {
Host string
}
// wholeUrl 生成完整URL
func (api SeaTableApi) wholeUrl(path string, params ...interface{}) string {
if len(params) == 0 {
return fmt.Sprintf("%s%s", api.Host, path)
}
return fmt.Sprintf("%s%s", api.Host, fmt.Sprintf(path, params...))
}
// wholeUrl 生成完整URL
func (api SeaTableApi) assignUrl(host string, path string, params ...interface{}) string {
if strings.HasSuffix(host, "/") {
host = strings.TrimSuffix(host, "/")
}
if len(params) == 0 {
return fmt.Sprintf("%s%s", host, path)
}
return fmt.Sprintf("%s%s", host, fmt.Sprintf(path, params...))
}
func (api SeaTableApi) tokenHeader(token string) string {
return fmt.Sprintf("Bearer %s", token)
}
// ApiError 仅错误时返回
type ApiError struct {
ErrorMsg string `json:"error_msg"`
}
// ApiResult API操作结果,可能成功也可能失败
type ApiResult struct {
ErrorMessage string `json:"error_message"`
Success bool `json:"success"`
}