github.com/jtzjtz/kit@v1.0.2/balance/nacos.go (about) 1 package balance 2 3 import ( 4 "github.com/nacos-group/nacos-sdk-go/clients" 5 "github.com/nacos-group/nacos-sdk-go/clients/naming_client" 6 "github.com/nacos-group/nacos-sdk-go/common/constant" 7 "github.com/nacos-group/nacos-sdk-go/vo" 8 ) 9 10 var cli naming_client.INamingClient 11 12 type NacosConfig struct { 13 NacosIp string 14 NacosPort int 15 NamespaceId string 16 GroupName string 17 } 18 19 //创建nacos 客户端 20 func createNacosClient(conf NacosConfig) (naming_client.INamingClient, error) { 21 sc := []constant.ServerConfig{ 22 { 23 IpAddr: conf.NacosIp, 24 Port: uint64(conf.NacosPort), 25 }, 26 } 27 cc := constant.ClientConfig{ 28 NamespaceId: conf.NamespaceId, //namespace id 29 TimeoutMs: 5000, 30 NotLoadCacheAtStart: true, 31 LogDir: "./tmp/nacos/log", 32 CacheDir: "./tmp/nacos/cache", 33 RotateTime: "1h", 34 MaxAge: 3, 35 LogLevel: "error", 36 } 37 38 // a more graceful way to create naming client 39 return clients.NewNamingClient( 40 vo.NacosClientParam{ 41 ClientConfig: &cc, 42 ServerConfigs: sc, 43 }, 44 ) 45 46 }