forked from optim-corp/cios-golang-sdk
/
model.go
82 lines (76 loc) · 2.03 KB
/
model.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
package ciossdk
import (
"context"
"net/http"
"github.com/fcfcqloow/go-advance/check"
cnv "github.com/fcfcqloow/go-advance/convert"
"github.com/optim-corp/cios-golang-sdk/cios"
sdkmodel "github.com/optim-corp/cios-golang-sdk/model"
)
var (
createClient = func(client *http.Client, servers cios.ServerConfigurations, debug bool) *cios.APIClient {
config := cios.NewConfiguration()
config.Debug = debug
config.UserAgent = "OPTiM Cloud IoT OS Golang SDK"
config.HTTPClient = client
config.Servers = servers
return cios.NewAPIClient(config)
}
getWithHostFunc = func(index int) func(ctx context.Context) context.Context {
return func(ctx context.Context) context.Context {
if check.IsNil(ctx) {
return context.WithValue(context.Background(), cios.ContextServerIndex, index)
}
return context.WithValue(ctx, cios.ContextServerIndex, index)
}
}
str = cnv.MustStr
)
type (
CiosClientConfig struct {
AutoRefresh bool
Debug bool
Urls sdkmodel.CIOSUrl
CustomClient *http.Client
AuthConfig *AuthConfig
WebSocketConfig *WebSocketConfig
}
WebSocketConfig struct {
ReadTimeoutMilliSec int64
WriteTimeoutMilliSec int64
}
AuthConfig struct {
sdkmodel.ClientID
sdkmodel.ClientSecret
sdkmodel.RefreshToken
sdkmodel.Assertion
sdkmodel.Scope
_type string
}
)
func ClientAuthConf(clientId, clientSecret, scope string) *AuthConfig {
return &AuthConfig{
ClientID: clientId,
ClientSecret: clientSecret,
Scope: scope,
_type: sdkmodel.CLIENT_TYPE,
}
}
func RefreshTokenAuth(clientId, clientSecret, refreshToken, scope string) *AuthConfig {
return &AuthConfig{
ClientID: clientId,
ClientSecret: clientSecret,
RefreshToken: refreshToken,
Scope: scope,
_type: sdkmodel.REFRESH_TYPE,
}
}
func DeviceAuthConf(clientId, clientSecret, assertion, scope string) *AuthConfig {
return &AuthConfig{
ClientID: clientId,
ClientSecret: clientSecret,
Assertion: assertion,
Scope: scope,
_type: sdkmodel.DEVICE_TYPE,
}
}