From 3c65f16737e3385fe3df5f91c403f292d5d400c1 Mon Sep 17 00:00:00 2001 From: jessetang <1430482733@qq.com> Date: Wed, 26 Oct 2022 14:24:14 +0800 Subject: [PATCH] style(contrib/config): code style modify (#2475) --- contrib/config/apollo/README.md | 1 - contrib/config/apollo/apollo.go | 5 ++-- contrib/config/apollo/watcher.go | 5 ++-- contrib/config/consul/README.md | 13 ++++++----- contrib/config/etcd/README.md | 5 ++-- contrib/config/kubernetes/config_test.go | 4 ++-- contrib/config/nacos/README.md | 3 ++- contrib/config/nacos/go.mod | 3 +++ contrib/config/polaris/README.md | 29 ++++++++++++------------ contrib/config/polaris/config.go | 4 ++-- contrib/config/polaris/watcher.go | 10 ++++---- 11 files changed, 42 insertions(+), 40 deletions(-) diff --git a/contrib/config/apollo/README.md b/contrib/config/apollo/README.md index c03cff0fd..a8eea4932 100644 --- a/contrib/config/apollo/README.md +++ b/contrib/config/apollo/README.md @@ -97,5 +97,4 @@ config := map[string]interface{}{ } } } -_ = config ``` diff --git a/contrib/config/apollo/apollo.go b/contrib/config/apollo/apollo.go index 259ed1a90..bd96ef11d 100644 --- a/contrib/config/apollo/apollo.go +++ b/contrib/config/apollo/apollo.go @@ -3,15 +3,14 @@ package apollo import ( "strings" - "github.com/go-kratos/kratos/v2/config" - "github.com/go-kratos/kratos/v2/log" - "github.com/apolloconfig/agollo/v4" "github.com/apolloconfig/agollo/v4/constant" apolloConfig "github.com/apolloconfig/agollo/v4/env/config" "github.com/apolloconfig/agollo/v4/extension" + "github.com/go-kratos/kratos/v2/config" "github.com/go-kratos/kratos/v2/encoding" + "github.com/go-kratos/kratos/v2/log" ) type apollo struct { diff --git a/contrib/config/apollo/watcher.go b/contrib/config/apollo/watcher.go index 94ef2ef0b..ea5ef1083 100644 --- a/contrib/config/apollo/watcher.go +++ b/contrib/config/apollo/watcher.go @@ -4,12 +4,11 @@ import ( "context" "strings" - "github.com/go-kratos/kratos/v2/encoding" + "github.com/apolloconfig/agollo/v4/storage" "github.com/go-kratos/kratos/v2/config" + "github.com/go-kratos/kratos/v2/encoding" "github.com/go-kratos/kratos/v2/log" - - "github.com/apolloconfig/agollo/v4/storage" ) type watcher struct { diff --git a/contrib/config/consul/README.md b/contrib/config/consul/README.md index a3d39a18a..9dc5a0666 100644 --- a/contrib/config/consul/README.md +++ b/contrib/config/consul/README.md @@ -2,20 +2,21 @@ ```go import ( - "github.com/go-kratos/kratos/contrib/config/consul/v2" "github.com/hashicorp/consul/api" -) -func main() { + "github.com/go-kratos/kratos/contrib/config/consul/v2" +) + +func main() { consulClient, err := api.NewClient(&api.Config{ - Address: "127.0.0.1:8500", + Address: "127.0.0.1:8500", }) if err != nil { panic(err) } cs, err := consul.New(consulClient, consul.WithPath("app/cart/configs/")) - //consul中需要标注文件后缀,kratos读取配置需要适配文件后缀 - //The file suffix needs to be marked, and kratos needs to adapt the file suffix to read the configuration. + // consul中需要标注文件后缀,kratos读取配置需要适配文件后缀 + // The file suffix needs to be marked, and kratos needs to adapt the file suffix to read the configuration. if err != nil { panic(err) } diff --git a/contrib/config/etcd/README.md b/contrib/config/etcd/README.md index d69edd82b..131619c1a 100644 --- a/contrib/config/etcd/README.md +++ b/contrib/config/etcd/README.md @@ -4,10 +4,11 @@ import ( "log" - cfg "github.com/go-kratos/kratos/contrib/config/etcd/v2" - "github.com/go-kratos/kratos/v2/config" clientv3 "go.etcd.io/etcd/client/v3" "google.golang.org/grpc" + + cfg "github.com/go-kratos/kratos/contrib/config/etcd/v2" + "github.com/go-kratos/kratos/v2/config" ) // create an etcd client diff --git a/contrib/config/kubernetes/config_test.go b/contrib/config/kubernetes/config_test.go index 6cdb1c98c..b110b634d 100644 --- a/contrib/config/kubernetes/config_test.go +++ b/contrib/config/kubernetes/config_test.go @@ -8,14 +8,14 @@ import ( "strings" "testing" - "github.com/go-kratos/kratos/v2/config" - v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/util/homedir" + + "github.com/go-kratos/kratos/v2/config" ) const ( diff --git a/contrib/config/nacos/README.md b/contrib/config/nacos/README.md index 71f186bf6..fa54caf07 100644 --- a/contrib/config/nacos/README.md +++ b/contrib/config/nacos/README.md @@ -2,9 +2,10 @@ ```go import ( - kconfig "github.com/go-kratos/kratos/v2/config" "github.com/nacos-group/nacos-sdk-go/clients" "github.com/nacos-group/nacos-sdk-go/common/constant" + + kconfig "github.com/go-kratos/kratos/v2/config" ) diff --git a/contrib/config/nacos/go.mod b/contrib/config/nacos/go.mod index 7890e0587..6917f24a4 100644 --- a/contrib/config/nacos/go.mod +++ b/contrib/config/nacos/go.mod @@ -5,6 +5,9 @@ go 1.16 require ( github.com/go-kratos/kratos/v2 v2.4.0 github.com/nacos-group/nacos-sdk-go v1.0.9 +) + +require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/contrib/config/polaris/README.md b/contrib/config/polaris/README.md index 4c2694c47..b39e78f22 100644 --- a/contrib/config/polaris/README.md +++ b/contrib/config/polaris/README.md @@ -2,24 +2,23 @@ ```go import ( - "log" - - "github.com/polarismesh/polaris-go" - "github.com/go-kratos/kratos/contrib/config/polaris/v2" + "log" + + "github.com/polarismesh/polaris-go" + + "github.com/go-kratos/kratos/contrib/config/polaris/v2" ) func main() { + configApi, err := polaris.NewConfigAPI() + if err != nil { + log.Fatalln(err) + } - configApi, err := polaris.NewConfigAPI() - if err != nil { - log.Fatalln(err) - } - - source, err := New(&configApi, WithNamespace("default"), WithFileGroup("default"), WithFileName("default.yaml")) - - if err != nil { - log.Fatalln(err) - } - source.Load() + source, err := New(&configApi, WithNamespace("default"), WithFileGroup("default"), WithFileName("default.yaml")) + if err != nil { + log.Fatalln(err) + } + source.Load() } ``` diff --git a/contrib/config/polaris/config.go b/contrib/config/polaris/config.go index c3c39ecee..288db4383 100644 --- a/contrib/config/polaris/config.go +++ b/contrib/config/polaris/config.go @@ -6,9 +6,9 @@ import ( "path/filepath" "strings" - "github.com/go-kratos/kratos/v2/config" - "github.com/polarismesh/polaris-go" + + "github.com/go-kratos/kratos/v2/config" ) // Option is polaris config option. diff --git a/contrib/config/polaris/watcher.go b/contrib/config/polaris/watcher.go index dcd890556..703055508 100644 --- a/contrib/config/polaris/watcher.go +++ b/contrib/config/polaris/watcher.go @@ -5,11 +5,11 @@ import ( "path/filepath" "strings" - "github.com/go-kratos/kratos/v2/config" - "github.com/go-kratos/kratos/v2/log" - "github.com/polarismesh/polaris-go" "github.com/polarismesh/polaris-go/pkg/model" + + "github.com/go-kratos/kratos/v2/config" + "github.com/go-kratos/kratos/v2/log" ) type Watcher struct { @@ -28,7 +28,7 @@ func getFullPath(namespace string, fileGroup string, fileName string) string { return fmt.Sprintf("%s/%s/%s", namespace, fileGroup, fileName) } -func recieve(event model.ConfigFileChangeEvent) { +func receive(event model.ConfigFileChangeEvent) { meta := event.ConfigFileMetadata ec := eventChanMap[getFullPath(meta.GetNamespace(), meta.GetFileGroup(), meta.GetFileName())] defer func() { @@ -42,7 +42,7 @@ func recieve(event model.ConfigFileChangeEvent) { } func newWatcher(configFile polaris.ConfigFile) *Watcher { - configFile.AddChangeListener(recieve) + configFile.AddChangeListener(receive) fullPath := getFullPath(configFile.GetNamespace(), configFile.GetFileGroup(), configFile.GetFileName()) if _, ok := eventChanMap[fullPath]; !ok {