api_auth_lib.go
1.2 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
package authlib
import (
"github.com/beego/beego/v2/core/logs"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api"
"net/http"
"time"
)
type ApiAuthLib struct {
Token string
api.BaseServiceGateway
}
func (gateway *ApiAuthLib) WithToken(token string) *ApiAuthLib {
gateway.Token = token
return gateway
}
func (gateway *ApiAuthLib) DefaultHeader() http.Header {
var header = make(map[string][]string)
header["x-mmm-accesstoken"] = []string{gateway.Token}
return header
}
func NewApiAuthLib(host string) *ApiAuthLib {
gt := api.NewBaseServiceGateway(host)
gt.ConnectTimeout = 360 * time.Second
gt.ReadWriteTimeout = 360 * time.Second
gt.Interceptor = func(msg string) {
//log.Logger.Info(msg)
logs.Debug(msg)
}
gt.ServiceName = "【授权中心】"
return &ApiAuthLib{
BaseServiceGateway: gt,
}
}
func (gateway *ApiAuthLib) MeInfo(param RequestUserMeQuery) (*DataUserMe, error) {
url := gateway.Host() + "/v1/user/me"
method := "get"
var data DataUserMe
err := gateway.FastDoRequest(url, method, param, &data, api.WithHeader(gateway.DefaultHeader()))
if err != nil {
return nil, err
}
return &data, nil
}