Skip to content

Commit

Permalink
feat(opts): support customize the nacos param (#26)
Browse files Browse the repository at this point in the history
* feat(opts): support customize the nacos param

* add kitex prefix to avoid conflic with other project
  • Loading branch information
whalecold committed Dec 14, 2023
1 parent 0ac4fe9 commit 6fc2d1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions nacos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ import (
"github.com/nacos-group/nacos-sdk-go/vo"
)

// Option is the way to config a client.
type Option struct {
F func(o *vo.NacosClientParam)
}

// NewDefaultNacosClient Create a default Nacos client
// It can create a client with default config by env variable.
// See: env.go
func NewDefaultNacosClient() (naming_client.INamingClient, error) {
func NewDefaultNacosClient(opts ...Option) (naming_client.INamingClient, error) {
sc := []constant.ServerConfig{
*constant.NewServerConfig(NacosAddr(), uint64(NacosPort())),
}
Expand All @@ -34,12 +39,14 @@ func NewDefaultNacosClient() (naming_client.INamingClient, error) {
NotLoadCacheAtStart: true,
CustomLogger: NewCustomNacosLogger(),
}
cli, err := clients.NewNamingClient(
vo.NacosClientParam{
ClientConfig: &cc,
ServerConfigs: sc,
},
)
param := vo.NacosClientParam{
ClientConfig: &cc,
ServerConfigs: sc,
}
for _, opt := range opts {
opt.F(&param)
}
cli, err := clients.NewNamingClient(param)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion nacos/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
const (
NACOS_ENV_SERVER_ADDR = "serverAddr"
NACOS_ENV_PORT = "serverPort"
NACOS_ENV_TAGS = "NACOS_ENV_TAGS"
NACOS_ENV_TAGS = "KITEX_NACOS_ENV_TAGS"
NACOS_ENV_NAMESPACE_ID = "namespace"
NACOS_DEFAULT_SERVER_ADDR = "127.0.0.1"
NACOS_DEFAULT_PORT = 8848
Expand Down

0 comments on commit 6fc2d1b

Please sign in to comment.