Skip to content

Commit

Permalink
update: simplify the conversion from int to time.Duration as suggeste…
Browse files Browse the repository at this point in the history
…d by the golang offical doc.

https://pkg.go.dev/time#pkg-constants

Signed-off-by: Cattī Crūdēlēs <[email protected]>
  • Loading branch information
wzy9607 committed Feb 14, 2024
1 parent f147bf5 commit 7e5c6ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
8 changes: 1 addition & 7 deletions component/remote/abs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package remote

import (
"strconv"
"time"

"github.com/apolloconfig/agollo/v4/component/log"
Expand Down Expand Up @@ -47,12 +46,7 @@ func (a *AbsApolloConfig) SyncWithNamespace(namespace string, appConfigFunc func
IsRetry: true,
}
if appConfig.SyncServerTimeout > 0 {
duration, err := time.ParseDuration(strconv.Itoa(appConfig.SyncServerTimeout) + "s")
if err != nil {
log.Errorf("parse sync server timeout %s fail, error:%v", appConfig.SyncServerTimeout, err)
return nil
}
c.Timeout = duration
c.Timeout = time.Duration(appConfig.SyncServerTimeout) * time.Second
}

callback := a.remoteApollo.CallBack(namespace)
Expand Down
17 changes: 6 additions & 11 deletions component/serverlist/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package serverlist

import (
"encoding/json"
"strconv"
"time"

"github.com/apolloconfig/agollo/v4/env/server"
Expand Down Expand Up @@ -66,10 +65,10 @@ func (s *SyncServerIPListComponent) Start() {
}
}

//SyncServerIPList sync ip list from server
//then
//1.update agcache
//2.store in disk
// SyncServerIPList sync ip list from server
// then
// 1.update agcache
// 2.store in disk
func SyncServerIPList(appConfigFunc func() config.AppConfig) (map[string]*config.ServerInfo, error) {
if appConfigFunc == nil {
panic("can not find apollo config!please confirm!")
Expand All @@ -80,12 +79,8 @@ func SyncServerIPList(appConfigFunc func() config.AppConfig) (map[string]*config
AppID: appConfig.AppID,
Secret: appConfig.Secret,
}
if appConfigFunc().SyncServerTimeout > 0 {
duration, err := time.ParseDuration(strconv.Itoa(appConfigFunc().SyncServerTimeout) + "s")
if err != nil {
return nil, err
}
c.Timeout = duration
if appConfig.SyncServerTimeout > 0 {
c.Timeout = time.Duration(appConfig.SyncServerTimeout) * time.Second
}
serverMap, err := http.Request(appConfig.GetServicesConfigURL(), c, &http.CallBack{
SuccessCallBack: SyncServerIPListSuccessCallBack,
Expand Down

0 comments on commit 7e5c6ae

Please sign in to comment.