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 all 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
64 changes: 33 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Nacos as service discovery.

## How to use?

### Server
### Basic

#### Server

```go
import (
Expand Down Expand Up @@ -38,10 +40,9 @@ func main() {
}
// ...
}

```

### Client
#### Client

```go
import (
Expand All @@ -68,9 +69,10 @@ func main() {
}
```

## Custom Nacos Client Configuration
### Custom Nacos Client Configuration

#### Server

### Server
```go
import (
// ...
Expand All @@ -79,13 +81,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 +97,34 @@ 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")
}
// ...
}

```

### Client
#### Client

```go
import (
// ...
Expand All @@ -139,23 +138,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,19 +168,20 @@ func main() {
}
```


## Environment Variable
### Environment Variable

| Environment Variable Name | Environment Variable Default Value | Environment Variable Introduction |
| ------------------------- | ---------------------------------- | --------------------------------- |
| serverAddr | 127.0.0.1 | nacos server address |
| serverPort | 8848 | nacos server port |
| namespace | | the namespaceId of nacos |

### More Info

Refer to [example](example) for more usage.

## 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)
82 changes: 44 additions & 38 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

## 这个项目应当如何使用?

### 服务端
### 基本使用

**registry-nacos/example/server/main.go**
#### 服务端

```go
import (
Expand All @@ -18,33 +18,31 @@ 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**

****
#### 客户端

```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,10 @@ func main() {
}
```

## 自定义 Nacos Client 配置
### 自定义 Nacos Client 配置

#### 服务端

### 服务端
```go
import (
// ...
Expand All @@ -89,7 +86,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 +97,34 @@ 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")
}
// ...
}

```

### 客户端
#### 客户端

```go
import (
// ...
Expand All @@ -138,25 +138,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,14 +168,18 @@ func main() {
}
```

## **环境变量**
### 环境变量

| 变量名 | 变量默认值 | 作用 |
| ------------------------- | ---------------------------------- | --------------------------------- |
| serverAddr | 127.0.0.1 | nacos 服务器地址 |
| serverPort | 8848 | nacos 服务器端口 |
| namespace | | nacos 中的 namespace Id |

### 更多信息

更多示例请参考 [example](example)

## 兼容性

Nacos 2.0 和 1.X 版本的 nacos-sdk-go 是完全兼容的,[详情](https://nacos.io/en-us/docs/2.0.0-compatibility.html)
Expand Down