Skip to content

Commit

Permalink
Merge branch 'admin_config' into 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ztelur authored Feb 8, 2021
2 parents c9c7271 + 446b783 commit cc456d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
8 changes: 6 additions & 2 deletions cmd/proxy/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ var (
}
logger.InitLog(logConfPath)

initFromRemote := false
if bootstrap.GetAPIMetaConfig() != nil {
if _, err := config.LoadAPIConfig(bootstrap.GetAPIMetaConfig()); err != nil {
logger.Errorf("load api config from etcd error:%+v", err)
return err
} else {
initFromRemote = true
}
} else {
}

if !initFromRemote {
if _, err := config.LoadAPIConfigFromFile(apiConfigPath); err != nil {
logger.Errorf("load api config error:%+v", err)
return err
Expand Down
24 changes: 23 additions & 1 deletion pkg/config/api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ func LoadAPIConfig(metaConfig *model.APIMetaConfig) (*fc.APIConfig, error) {
return nil, perrors.Errorf("Get remote config fail error %v", err)
}

initAPIConfigFromString(content)
if err = initAPIConfigFromString(content); err != nil {
return nil, err
}

return apiConfig, nil
}
Expand All @@ -96,11 +98,31 @@ func initAPIConfigFromString(content string) error {
if err != nil {
return perrors.Errorf("unmarshalYmlConfig error %v", perrors.WithStack(err))
}

valid := validateApiConfig(apiConf)
if !valid {
return perrors.Errorf("api config not valid error %v", perrors.WithStack(err))
}

apiConfig = apiConf
}
return nil
}

// validateApiConfig check api config valid
func validateApiConfig(conf *fc.APIConfig) bool {
if conf.Name == "" {
return false
}
if conf.Description == "" {
return false
}
if conf.Resources == nil || len(conf.Resources) == 0 {
return false
}
return true
}

func listenAPIConfigNodeEvent(key string) bool {
for {
wc, err := client.Watch(key)
Expand Down
1 change: 1 addition & 0 deletions samples/plugins/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module dubbo-go-proxy/samples/plugins

go 1.14


require (
github.com/dubbogo/dubbo-go-proxy-filter v0.1.0-rc3.0.20210206105825-798f95b07dfa
)

0 comments on commit cc456d6

Please sign in to comment.