Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: correct incorrect readme file and tidy up the file #16

Merged
merged 3 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ func main() {
}
// ...
}

```

Refer to [example](https://github.com/kitex-contrib/registry-nacos/blob/main/example/basic/server/main.go) for more usage.
justlorain marked this conversation as resolved.
Show resolved Hide resolved

### Client

```go
Expand Down Expand Up @@ -68,9 +69,12 @@ func main() {
}
```

Refer to [example](https://github.com/kitex-contrib/registry-nacos/blob/main/example/basic/client/main.go) for more usage.

## Custom Nacos Client Configuration

### Server

```go
import (
// ...
Expand All @@ -79,13 +83,12 @@ import (
"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
"github.com/cloudwego/kitex/pkg/rpcinfo"
// ...
)
func main() {
// ...
sc := []constant.ServerConfig{
*constant.NewServerConfig("127.0.0.1", 8848),
*constant.NewServerConfig("127.0.0.1", 8848),
}

cc := constant.ClientConfig{
Expand All @@ -96,36 +99,36 @@ func main() {
CacheDir: "/tmp/nacos/cache",
LogLevel: "info",
Username: "your-name",
Password: "your-password"
Password: "your-password",
}

cli, err := clients.NewNamingClient(
vo.NacosClientParam{
vo.NacosClientParam{
ClientConfig: &cc,
ServerConfigs: sc,
},
)
if err != nil {
panic(err)
}

svr := echo.NewServer(
new(EchoImpl),
server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "echo"}),
justlorain marked this conversation as resolved.
Show resolved Hide resolved
server.WithRegistry(r),

svr := echo.NewServer(new(EchoImpl),
server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "echo"}),
server.WithRegistry(registry.NewNacosRegistry(cli)),
)

if err := svr.Run(); err != nil {
log.Println("server stopped with error:", err)
} else {
log.Println("server stopped")
}
// ...
}

```

Refer to [example](https://github.com/kitex-contrib/registry-nacos/blob/main/example/custom-config/server/main.go) for more usage.
justlorain marked this conversation as resolved.
Show resolved Hide resolved

### Client

```go
import (
// ...
Expand All @@ -139,23 +142,25 @@ import (
func main() {
// ...
sc := []constant.ServerConfig{
*constant.NewServerConfig("127.0.0.1", 8848)}
*constant.NewServerConfig("127.0.0.1", 8848),
}
cc := constant.ClientConfig{
NamespaceId: "public",
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
LogLevel: "info",
Username: "your-name",
Password: "your-password"
NamespaceId: "public",
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
LogLevel: "info",
Username: "your-name",
Password: "your-password",
}

cli,err := clients.NewNamingClient(
cli, err := clients.NewNamingClient(
vo.NacosClientParam{
ClientConfig: &cc,
ServerConfigs: sc,
},)
},
)
if err != nil {
panic(err)
}
Expand All @@ -167,6 +172,7 @@ func main() {
}
```

Refer to [example](https://github.com/kitex-contrib/registry-nacos/blob/main/example/custom-config/client/main.go) for more usage.

## Environment Variable

Expand All @@ -176,10 +182,8 @@ func main() {
| serverPort | 8848 | nacos server port |
| namespace | | the namespaceId of nacos |



## Compatibility
The server of Nacos2.0 is fully compatible with 1.X nacos-sdk-go. [see](https://nacos.io/en-us/docs/2.0.0-compatibility.html)

The server of Nacos2.0 is fully compatible with 1.X nacos-sdk-go. [see](https://nacos.io/en-us/docs/2.0.0-compatibility.html)

maintained by: [baiyutang](https://github.com/baiyutang)
76 changes: 42 additions & 34 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

### 服务端

**registry-nacos/example/server/main.go**

```go
import (
// ...
Expand All @@ -18,33 +16,33 @@ import (
"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
"github.com/cloudwego/kitex/pkg/rpcinfo"
// ...
)

func main() {
// ...

r, err := registry.NewDefaultNacosRegistry()
if err != nil {
panic(err)
}

svr := echo.NewServer(new(EchoImpl), server.WithRegistry(r))
svr := echo.NewServer(
new(EchoImpl),
server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "echo"}),
server.WithRegistry(r),
)
if err := svr.Run(); err != nil {
log.Println("server stopped with error:", err)
} else {
log.Println("server stopped")
}
// ...
}

```

### 客户端

**registry-nacos/example/client/main.go**
更多示例请参考 [example](https://github.com/kitex-contrib/registry-nacos/blob/main/example/basic/server/main.go)

****
### 客户端

```go
import (
Expand All @@ -58,13 +56,11 @@ import (
)

func main() {
// ...

// ...
r, err := resolver.NewDefaultNacosResolver()
if err != nil {
panic(err)
}

client, err := echo.NewClient("echo", client.WithResolver(r))
if err != nil {
log.Fatal(err)
Expand All @@ -73,9 +69,12 @@ func main() {
}
```

更多示例请参考 [example](https://github.com/kitex-contrib/registry-nacos/blob/main/example/basic/client/main.go)

## 自定义 Nacos Client 配置

### 服务端

```go
import (
// ...
Expand All @@ -89,7 +88,7 @@ import (
func main() {
// ...
sc := []constant.ServerConfig{
*constant.NewServerConfig("127.0.0.1", 8848),
*constant.NewServerConfig("127.0.0.1", 8848),
}

cc := constant.ClientConfig{
Expand All @@ -100,31 +99,36 @@ func main() {
CacheDir: "/tmp/nacos/cache",
LogLevel: "info",
Username: "your-name",
Password: "your-password"
Password: "your-password",
}

cli, err := clients.NewNamingClient(
vo.NacosClientParam{
vo.NacosClientParam{
ClientConfig: &cc,
ServerConfigs: sc,
},
)
if err != nil {
panic(err)
}

svr := echo.NewServer(new(EchoImpl), server.WithRegistry(registry.NewNacosRegistry(cli)))

svr := echo.NewServer(new(EchoImpl),
server.WithServerBasicInfo(&rpcinfo.EndpointBasicInfo{ServiceName: "echo"}),
server.WithRegistry(registry.NewNacosRegistry(cli)),
)
if err := svr.Run(); err != nil {
log.Println("server stopped with error:", err)
} else {
log.Println("server stopped")
}
// ...
}

```

更多示例请参考 [example](https://github.com/kitex-contrib/registry-nacos/blob/main/example/custom-config/server/main.go)

### 客户端

```go
import (
// ...
Expand All @@ -138,25 +142,27 @@ import (
func main() {
// ...
sc := []constant.ServerConfig{
*constant.NewServerConfig("127.0.0.1", 8848)}
*constant.NewServerConfig("127.0.0.1", 8848),
}
cc := constant.ClientConfig{
NamespaceId: "public",
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
LogLevel: "info",
Username: "your-name",
Password: "your-password"
NamespaceId: "public",
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
LogLevel: "info",
Username: "your-name",
Password: "your-password",
}

cli,err := clients.NewNamingClient(
cli, err := clients.NewNamingClient(
vo.NacosClientParam{
ClientConfig: &cc,
ServerConfigs: sc,
},)
ClientConfig: &cc,
ServerConfigs: sc,
},
)
if err != nil {
panic(err)
panic(err)
}
client, err := echo.NewClient("echo", client.WithResolver(resolver.NewNacosResolver(cli))
if err != nil {
Expand All @@ -166,7 +172,9 @@ func main() {
}
```

## **环境变量**
更多示例请参考 [example](https://github.com/kitex-contrib/registry-nacos/blob/main/example/custom-config/client/main.go)

## 环境变量

| 变量名 | 变量默认值 | 作用 |
| ------------------------- | ---------------------------------- | --------------------------------- |
Expand Down