open_api_lib.go
1.3 KB
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
package apilib
import (
"fmt"
"github.com/beego/beego/v2/core/logs"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api"
"net/http"
"time"
)
type OpenApiLib struct {
Token string
api.BaseServiceGateway
}
func (gateway *OpenApiLib) WithToken(token string) *OpenApiLib {
gateway.Token = token
return gateway
}
func (gateway *OpenApiLib) DefaultHeader() http.Header {
var header = make(map[string][]string)
header["x-mmm-accesstoken"] = []string{gateway.Token}
header["x-mmm-appproject"] = []string{"byte-bank"}
return header
}
func NewApiAuthLib(host string) *OpenApiLib {
gt := api.NewBaseServiceGateway(host)
gt.ConnectTimeout = 360 * time.Second
gt.ReadWriteTimeout = 360 * time.Second
gt.Interceptor = func(msg string) {
logs.Debug(msg)
}
gt.ServiceName = "【开发接口】"
return &OpenApiLib{
BaseServiceGateway: gt,
}
}
func (gateway *OpenApiLib) Upload(param RequestUpload) (*DataUploadItem, error) {
url := gateway.Host() + "/v1/vod/putObject"
method := "post"
var data DataUpload
err := gateway.FastDoRequest(url, method, struct{}{}, &data, api.WithHeader(gateway.DefaultHeader()), api.WithFileMap(param.UploadFileMap))
if err != nil {
return nil, err
}
if len(data) > 0 {
return data[0], nil
}
return nil, fmt.Errorf("上传失败")
}