12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package c_nacos
- import (
- "github.com/nacos-group/nacos-sdk-go/clients"
- "github.com/nacos-group/nacos-sdk-go/common/constant"
- "github.com/nacos-group/nacos-sdk-go/vo"
- )
- func InitNacos() {
- sc := []constant.ServerConfig{
- {
- IpAddr: "36.110.106.156",
- Port: 8848,
- },
- }
- cc := constant.ClientConfig{
- NamespaceId: "7e6d8a49-995b-49a0-b43e-25c1de713a55", //namespace id
- TimeoutMs: 5000,
- NotLoadCacheAtStart: true,
- LogDir: "/tmp/nacos/log",
- CacheDir: "/tmp/nacos/cache",
- LogLevel: "debug",
- }
- //or a more graceful way to create ClientConfig
- _ = *constant.NewClientConfig(
- constant.WithNamespaceId("7e6d8a49-995b-49a0-b43e-25c1de713a55"),
- constant.WithTimeoutMs(5000),
- constant.WithNotLoadCacheAtStart(true),
- constant.WithLogDir("/tmp/nacos/log"),
- constant.WithCacheDir("/tmp/nacos/cache"),
- constant.WithLogLevel("debug"),
- constant.WithUsername("nacos"),
- constant.WithPassword("1qaz2wsx!"),
- )
- // a more graceful way to create naming client
- client, err := clients.NewNamingClient(
- vo.NacosClientParam{
- ClientConfig: &cc,
- ServerConfigs: sc,
- },
- )
- if err != nil {
- panic(err)
- }
- //Register with default cluster and group
- //ClusterName=DEFAULT,GroupName=DEFAULT_GROUP
- ExampleServiceClient_RegisterServiceInstance(client, vo.RegisterInstanceParam{
- Ip: "36.110.106.142",
- Port: 12340,
- ServiceName: "plugin-compile",
- Weight: 10,
- Enable: true,
- Healthy: true,
- Ephemeral: true,
- Metadata: map[string]string{"idc": "beijing", "开发者": "孟令鑫"},
- })
- }
|