Skip to content

Commit

Permalink
refactor: all
Browse files Browse the repository at this point in the history
Automatic token refresh logic optimization
  • Loading branch information
chuntaojun committed Apr 11, 2020
1 parent c1a648d commit 56ea5a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 8 additions & 8 deletions clients/client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ func CreateConfigClient(properties map[string]interface{}) (iClient config_clien
nacosClient, errSetConfig := setConfig(properties)
if errSetConfig != nil {
err = errSetConfig
return nil, err
return
}
nacosClient.SetHttpAgent(&http_agent.HttpAgent{})
config, errNew := config_client.NewConfigClient(nacosClient)
if errNew != nil {
err = errNew
return nil, err
return
}
iClient = &config
return iClient, nil
return
}

// 创建服务发现相关的客户端
func CreateNamingClient(properties map[string]interface{}) (iClient naming_client.INamingClient, err error) {
nacosClient, errSetConfig := setConfig(properties)
if errSetConfig != nil {
err = errSetConfig
return nil, err
return
}
nacosClient.SetHttpAgent(&http_agent.HttpAgent{})
naming, errNew := naming_client.NewNamingClient(nacosClient)
if errNew != nil {
err = errNew
return nil, err
return
}
iClient = &naming
return iClient, nil
return
}

func setConfig(properties map[string]interface{}) (iClient nacos_client.INacosClient, err error) {
Expand Down Expand Up @@ -72,12 +72,12 @@ func setConfig(properties map[string]interface{}) (iClient nacos_client.INacosCl
clientConfig, _ := client.GetClientConfig()
if len(clientConfig.Endpoint) <= 0 {
err = errors.New("server configs not found in properties")
return nil, err
return
}
client.SetServerConfig([]constant.ServerConfig{})
}

iClient = &client

return iClient, nil
return
}
8 changes: 7 additions & 1 deletion common/security/security_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type AuthClient struct {
}

func NewAuthClient(clientCfg constant.ClientConfig, serverCfgs []constant.ServerConfig, agent http_agent.IHttpAgent) AuthClient {

client := AuthClient{
username: clientCfg.Username,
password: clientCfg.Password,
Expand All @@ -49,6 +48,13 @@ func (ac *AuthClient) GetAccessToken() string {
}

func (ac *AuthClient) AutoRefresh() {

// If the username is not set, the automatic refresh Token is not enabled

if ac.username == "" {
return
}

go func() {
ticker := time.NewTicker(time.Millisecond * 5)

Expand Down

0 comments on commit 56ea5a1

Please sign in to comment.