Merge pull request #7 from chzealot/main
feat: 支持对Stream通道标识本地局域网IP,用于问题诊断
This commit is contained in:
commit
24b714f7ed
|
|
@ -273,6 +273,9 @@ func (cli *StreamClient) GetConnectionEndpoint(ctx context.Context) (*payload.Co
|
||||||
UserAgent: cli.UserAgent.UserAgent,
|
UserAgent: cli.UserAgent.UserAgent,
|
||||||
Subscriptions: make([]*payload.SubscriptionModel, 0),
|
Subscriptions: make([]*payload.SubscriptionModel, 0),
|
||||||
}
|
}
|
||||||
|
if localIp, err := utils.GetFirstLanIP(); err == nil {
|
||||||
|
requestModel.LocalIP = localIp
|
||||||
|
}
|
||||||
|
|
||||||
for ttype, subs := range cli.subscriptions {
|
for ttype, subs := range cli.subscriptions {
|
||||||
for ttopic, _ := range subs {
|
for ttopic, _ := range subs {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ type UserAgentConfig struct {
|
||||||
|
|
||||||
func NewDingtalkGoSDKUserAgent() *UserAgentConfig {
|
func NewDingtalkGoSDKUserAgent() *UserAgentConfig {
|
||||||
return &UserAgentConfig{
|
return &UserAgentConfig{
|
||||||
UserAgent: "dingtalk-sdk-go/v0.2.0",
|
UserAgent: "dingtalk-sdk-go/v0.3.0",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ type ConnectionEndpointRequest struct {
|
||||||
ClientSecret string `json:"clientSecret"` //自建应用appSecret; 三方应用suiteSecret
|
ClientSecret string `json:"clientSecret"` //自建应用appSecret; 三方应用suiteSecret
|
||||||
Subscriptions []*SubscriptionModel `json:"subscriptions"`
|
Subscriptions []*SubscriptionModel `json:"subscriptions"`
|
||||||
UserAgent string `json:"ua"`
|
UserAgent string `json:"ua"`
|
||||||
|
LocalIP string `json:"localIp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 长连接接入点参数
|
// 长连接接入点参数
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetFirstLanIP() (string, error) {
|
||||||
|
addresses, err := net.InterfaceAddrs()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if len(addresses) == 0 {
|
||||||
|
return "", errors.New("empty interfaces")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, addr := range addresses {
|
||||||
|
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||||
|
if ipnet.IP.To4() != nil {
|
||||||
|
return ipnet.IP.String(), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", errors.New("no valid interfaces")
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetFirstLanIP(t *testing.T) {
|
||||||
|
ip, err := GetFirstLanIP()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.NotEmpty(t, ip)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue