1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-14 02:33:03 +02:00
kratos/contrib/config/nacos
2022-07-05 08:43:36 +08:00
..
config_test.go test(nacos): add nacos unit test and remove unused function (#2145) 2022-07-05 08:43:36 +08:00
config.go test(nacos): add nacos unit test and remove unused function (#2145) 2022-07-05 08:43:36 +08:00
go.mod test(nacos): add nacos unit test and remove unused function (#2145) 2022-07-05 08:43:36 +08:00
go.sum build(deps): bump gopkg.in/yaml.v3 in /contrib/config/nacos (#2067) 2022-05-31 10:01:31 +08:00
README.md fix doc (#1636) 2021-11-18 21:22:19 +08:00
watcher.go chore(contrib/config): uniformly canceled by CancelFunc (#2111) 2022-06-17 23:42:32 +08:00

Nacos Config

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"
)


sc := []constant.ServerConfig{
	*constant.NewServerConfig("127.0.0.1", 8848),
}

cc := &constant.ClientConfig{
	NamespaceId:         "public", //namespace id
	TimeoutMs:           5000,
	NotLoadCacheAtStart: true,
	LogDir:              "/tmp/nacos/log",
	CacheDir:            "/tmp/nacos/cache",
	RotateTime:          "1h",
	MaxAge:              3,
	LogLevel:            "debug",
}

// a more graceful way to create naming client
client, err := clients.NewConfigClient(
	vo.NacosClientParam{
		ClientConfig:  cc,
		ServerConfigs: sc,
	},
)
if err != nil {
	log.Panic(err)
}