support client extra info (#13)
* feat(#extras) : add client extra info * feat(#extras) : add host interface --------- Co-authored-by: mike.wq <mike.wq@alibaba-inc.com>
This commit is contained in:
parent
a561b39a6d
commit
aab862d51f
|
|
@ -33,9 +33,11 @@ type StreamClient struct {
|
|||
|
||||
subscriptions map[string]map[string]handler.IFrameHandler
|
||||
|
||||
conn *websocket.Conn
|
||||
sessionId string
|
||||
mutex sync.Mutex
|
||||
conn *websocket.Conn
|
||||
sessionId string
|
||||
mutex sync.Mutex
|
||||
extras map[string]string
|
||||
openApiHost string
|
||||
}
|
||||
|
||||
func NewStreamClient(options ...ClientOption) *StreamClient {
|
||||
|
|
@ -276,6 +278,7 @@ func (cli *StreamClient) GetConnectionEndpoint(ctx context.Context) (*payload.Co
|
|||
ClientSecret: cli.AppCredential.ClientSecret,
|
||||
UserAgent: cli.UserAgent.UserAgent,
|
||||
Subscriptions: make([]*payload.SubscriptionModel, 0),
|
||||
Extras: cli.extras,
|
||||
}
|
||||
if localIp, err := utils.GetFirstLanIP(); err == nil {
|
||||
requestModel.LocalIP = localIp
|
||||
|
|
@ -292,7 +295,14 @@ func (cli *StreamClient) GetConnectionEndpoint(ctx context.Context) (*payload.Co
|
|||
|
||||
requestJsonBody, _ := json.Marshal(requestModel)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, utils.GetConnectionEndpointAPIUrl, bytes.NewReader(requestJsonBody))
|
||||
var targetHost string
|
||||
if len(cli.openApiHost) == 0 {
|
||||
targetHost = utils.DefaultOpenApiHost
|
||||
} else {
|
||||
targetHost = cli.openApiHost
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, targetHost+utils.GetConnectionEndpointAPIUrl, bytes.NewReader(requestJsonBody))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ type UserAgentConfig struct {
|
|||
|
||||
func NewDingtalkGoSDKUserAgent() *UserAgentConfig {
|
||||
return &UserAgentConfig{
|
||||
UserAgent: "dingtalk-sdk-go/v0.6.1",
|
||||
UserAgent: "dingtalk-sdk-go/v0.6.2",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,3 +36,15 @@ func WithUserAgent(ua *UserAgentConfig) ClientOption {
|
|||
c.UserAgent = ua
|
||||
}
|
||||
}
|
||||
|
||||
func WithExtras(extras map[string]string) ClientOption {
|
||||
return func(c *StreamClient) {
|
||||
c.extras = extras
|
||||
}
|
||||
}
|
||||
|
||||
func WithOpenApiHost(host string) ClientOption {
|
||||
return func(c *StreamClient) {
|
||||
c.openApiHost = host
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ type ConnectionEndpointRequest struct {
|
|||
Subscriptions []*SubscriptionModel `json:"subscriptions"`
|
||||
UserAgent string `json:"ua"`
|
||||
LocalIP string `json:"localIp"`
|
||||
Extras map[string]string `json:"extras"`
|
||||
}
|
||||
|
||||
// 长连接接入点参数
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ package utils
|
|||
*/
|
||||
|
||||
const (
|
||||
GetConnectionEndpointAPIUrl = "https://api.dingtalk.com/v1.0/gateway/connections/open"
|
||||
DefaultOpenApiHost = "https://api.dingtalk.com"
|
||||
GetConnectionEndpointAPIUrl = "/v1.0/gateway/connections/open"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
Loading…
Reference in New Issue