Skip to content

Commit

Permalink
add more comment
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed Sep 16, 2020
1 parent 1fe49dd commit 4ec1603
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions component/remote/abs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/zouyx/agollo/v4/protocol/http"
)

// AbsApolloConfig 抽象 apollo 配置
type AbsApolloConfig struct {
remoteApollo ApolloConfig
}
Expand Down
1 change: 1 addition & 0 deletions component/remote/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
defaultContentKey = "content"
)

// CreateAsyncApolloConfig 创建异步 apollo 配置
func CreateAsyncApolloConfig() ApolloConfig {
a := &asyncApolloConfig{}
a.remoteApollo = a
Expand Down
6 changes: 6 additions & 0 deletions component/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ import (
"github.com/zouyx/agollo/v4/protocol/http"
)

// ApolloConfig apollo 配置
type ApolloConfig interface {
// GetNotifyURLSuffix 获取异步更新路径
GetNotifyURLSuffix(notifications string, config config.AppConfig) string
// GetSyncURI 获取同步路径
GetSyncURI(config config.AppConfig, namespaceName string) string
// Sync 同步获取 Apollo 配置
Sync(appConfig *config.AppConfig) []*config.ApolloConfig
// CallBack 根据 namespace 获取 callback 方法
CallBack(namespace string) http.CallBack
// SyncWithNamespace 通过 namespace 同步 apollo 配置
SyncWithNamespace(namespace string, appConfig *config.AppConfig) *config.ApolloConfig
}
1 change: 1 addition & 0 deletions component/remote/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"path"
)

// CreateSyncApolloConfig 创建同步获取 Apollo 配置
func CreateSyncApolloConfig() ApolloConfig {
a := &syncApolloConfig{}
a.remoteApollo = a
Expand Down
2 changes: 1 addition & 1 deletion env/config/apollo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type ApolloConnConfig struct {
sync.RWMutex
}

//ApolloConfig apollo配置
// ApolloConfig apollo配置
type ApolloConfig struct {
ApolloConnConfig
Configurations map[string]interface{} `json:"configurations"`
Expand Down
4 changes: 2 additions & 2 deletions env/file/file_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ import (
//FileHandler 备份文件读写
type FileHandler interface {
WriteConfigFile(config *config.ApolloConfig, configPath string) error
GetConfigFile(configDir string, appId string, namespace string) string
LoadConfigFile(configDir string, appId string, namespace string) (*config.ApolloConfig, error)
GetConfigFile(configDir string, appID string, namespace string) string
LoadConfigFile(configDir string, appID string, namespace string) (*config.ApolloConfig, error)
}
8 changes: 4 additions & 4 deletions env/file/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func (fileHandler *FileHandler) WriteConfigFile(config *config.ApolloConfig, con
}

// GetConfigFile get real config file
func (fileHandler *FileHandler) GetConfigFile(configDir string, appId string, namespace string) string {
key := fmt.Sprintf("%s-%s", appId, namespace)
func (fileHandler *FileHandler) GetConfigFile(configDir string, appID string, namespace string) string {
key := fmt.Sprintf("%s-%s", appID, namespace)
fullPath := configFileMap[key]
if fullPath == "" {
filePath := fmt.Sprintf("%s%s", key, Suffix)
Expand All @@ -62,8 +62,8 @@ func (fileHandler *FileHandler) GetConfigFile(configDir string, appId string, na
}

//LoadConfigFile load config from file
func (fileHandler *FileHandler) LoadConfigFile(configDir string, appId string, namespace string) (*config.ApolloConfig, error) {
configFilePath := fileHandler.GetConfigFile(configDir, appId, namespace)
func (fileHandler *FileHandler) LoadConfigFile(configDir string, appID string, namespace string) (*config.ApolloConfig, error) {
configFilePath := fileHandler.GetConfigFile(configDir, appID, namespace)
log.Info("load config file from :", configFilePath)
c, e := jsonFileConfig.Load(configFilePath, func(b []byte) (interface{}, error) {
config := &config.ApolloConfig{}
Expand Down
4 changes: 2 additions & 2 deletions extension/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func (r *TestFileHandler) WriteConfigFile(config *config.ApolloConfig, configPat
}

//GetConfigFile 获得配置文件路径
func (r *TestFileHandler) GetConfigFile(configDir string, appId string, namespace string) string {
func (r *TestFileHandler) GetConfigFile(configDir string, appID string, namespace string) string {
return ""
}

func (r *TestFileHandler) LoadConfigFile(configDir string, appId string, namespace string) (*config.ApolloConfig, error) {
func (r *TestFileHandler) LoadConfigFile(configDir string, appID string, namespace string) (*config.ApolloConfig, error) {
return nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ func (fileHandler *testFileHandler) WriteConfigFile(config *config.ApolloConfig,
}

// GetConfigFile get real config file
func (fileHandler *testFileHandler) GetConfigFile(configDir string, appId string, namespace string) string {
func (fileHandler *testFileHandler) GetConfigFile(configDir string, appID string, namespace string) string {
return ""
}

// LoadConfigFile load config from file
func (fileHandler *testFileHandler) LoadConfigFile(configDir string, appId string, namespace string) (*config.ApolloConfig, error) {
func (fileHandler *testFileHandler) LoadConfigFile(configDir string, appID string, namespace string) (*config.ApolloConfig, error) {
return nil, nil
}

Expand Down

0 comments on commit 4ec1603

Please sign in to comment.