mirror of
https://github.com/go-kratos/kratos.git
synced 2025-11-06 08:59:18 +02:00
style(contrib/config): code style modify (#2475)
This commit is contained in:
@@ -97,5 +97,4 @@ config := map[string]interface{}{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = config
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -3,15 +3,14 @@ package apollo
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"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"
|
||||||
"github.com/apolloconfig/agollo/v4/constant"
|
"github.com/apolloconfig/agollo/v4/constant"
|
||||||
apolloConfig "github.com/apolloconfig/agollo/v4/env/config"
|
apolloConfig "github.com/apolloconfig/agollo/v4/env/config"
|
||||||
"github.com/apolloconfig/agollo/v4/extension"
|
"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/encoding"
|
||||||
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type apollo struct {
|
type apollo struct {
|
||||||
|
|||||||
@@ -4,12 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strings"
|
"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/config"
|
||||||
|
"github.com/go-kratos/kratos/v2/encoding"
|
||||||
"github.com/go-kratos/kratos/v2/log"
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
|
|
||||||
"github.com/apolloconfig/agollo/v4/storage"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type watcher struct {
|
type watcher struct {
|
||||||
|
|||||||
@@ -2,20 +2,21 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"github.com/go-kratos/kratos/contrib/config/consul/v2"
|
|
||||||
"github.com/hashicorp/consul/api"
|
"github.com/hashicorp/consul/api"
|
||||||
)
|
|
||||||
func main() {
|
|
||||||
|
|
||||||
|
"github.com/go-kratos/kratos/contrib/config/consul/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
consulClient, err := api.NewClient(&api.Config{
|
consulClient, err := api.NewClient(&api.Config{
|
||||||
Address: "127.0.0.1:8500",
|
Address: "127.0.0.1:8500",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cs, err := consul.New(consulClient, consul.WithPath("app/cart/configs/"))
|
cs, err := consul.New(consulClient, consul.WithPath("app/cart/configs/"))
|
||||||
//consul中需要标注文件后缀,kratos读取配置需要适配文件后缀
|
// consul中需要标注文件后缀,kratos读取配置需要适配文件后缀
|
||||||
//The file suffix needs to be marked, and kratos needs to adapt the file suffix to read the configuration.
|
// The file suffix needs to be marked, and kratos needs to adapt the file suffix to read the configuration.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
import (
|
import (
|
||||||
"log"
|
"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"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
"google.golang.org/grpc"
|
"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
|
// create an etcd client
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-kratos/kratos/v2/config"
|
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
"k8s.io/client-go/util/homedir"
|
"k8s.io/client-go/util/homedir"
|
||||||
|
|
||||||
|
"github.com/go-kratos/kratos/v2/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
kconfig "github.com/go-kratos/kratos/v2/config"
|
|
||||||
"github.com/nacos-group/nacos-sdk-go/clients"
|
"github.com/nacos-group/nacos-sdk-go/clients"
|
||||||
"github.com/nacos-group/nacos-sdk-go/common/constant"
|
"github.com/nacos-group/nacos-sdk-go/common/constant"
|
||||||
|
|
||||||
|
kconfig "github.com/go-kratos/kratos/v2/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ go 1.16
|
|||||||
require (
|
require (
|
||||||
github.com/go-kratos/kratos/v2 v2.4.0
|
github.com/go-kratos/kratos/v2 v2.4.0
|
||||||
github.com/nacos-group/nacos-sdk-go v1.0.9
|
github.com/nacos-group/nacos-sdk-go v1.0.9
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,24 +2,23 @@
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/polarismesh/polaris-go"
|
"github.com/polarismesh/polaris-go"
|
||||||
"github.com/go-kratos/kratos/contrib/config/polaris/v2"
|
|
||||||
|
"github.com/go-kratos/kratos/contrib/config/polaris/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
configApi, err := polaris.NewConfigAPI()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
configApi, err := polaris.NewConfigAPI()
|
source, err := New(&configApi, WithNamespace("default"), WithFileGroup("default"), WithFileName("default.yaml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
source.Load()
|
||||||
source, err := New(&configApi, WithNamespace("default"), WithFileGroup("default"), WithFileName("default.yaml"))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
source.Load()
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-kratos/kratos/v2/config"
|
|
||||||
|
|
||||||
"github.com/polarismesh/polaris-go"
|
"github.com/polarismesh/polaris-go"
|
||||||
|
|
||||||
|
"github.com/go-kratos/kratos/v2/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option is polaris config option.
|
// Option is polaris config option.
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"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"
|
||||||
"github.com/polarismesh/polaris-go/pkg/model"
|
"github.com/polarismesh/polaris-go/pkg/model"
|
||||||
|
|
||||||
|
"github.com/go-kratos/kratos/v2/config"
|
||||||
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Watcher struct {
|
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)
|
return fmt.Sprintf("%s/%s/%s", namespace, fileGroup, fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func recieve(event model.ConfigFileChangeEvent) {
|
func receive(event model.ConfigFileChangeEvent) {
|
||||||
meta := event.ConfigFileMetadata
|
meta := event.ConfigFileMetadata
|
||||||
ec := eventChanMap[getFullPath(meta.GetNamespace(), meta.GetFileGroup(), meta.GetFileName())]
|
ec := eventChanMap[getFullPath(meta.GetNamespace(), meta.GetFileGroup(), meta.GetFileName())]
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -42,7 +42,7 @@ func recieve(event model.ConfigFileChangeEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newWatcher(configFile polaris.ConfigFile) *Watcher {
|
func newWatcher(configFile polaris.ConfigFile) *Watcher {
|
||||||
configFile.AddChangeListener(recieve)
|
configFile.AddChangeListener(receive)
|
||||||
|
|
||||||
fullPath := getFullPath(configFile.GetNamespace(), configFile.GetFileGroup(), configFile.GetFileName())
|
fullPath := getFullPath(configFile.GetNamespace(), configFile.GetFileGroup(), configFile.GetFileName())
|
||||||
if _, ok := eventChanMap[fullPath]; !ok {
|
if _, ok := eventChanMap[fullPath]; !ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user