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

docs(example): add more example #14

Merged
merged 7 commits into from
Jun 28, 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
25 changes: 0 additions & 25 deletions .github/workflows/release-check.yml

This file was deleted.

12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ func main() {
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
RotateTime: "1h",
MaxAge: 3,
LogLevel: "info",
Username: "test",
Password: "test"
Username: "your-name",
Password: "your-password"
}

cli, err := clients.NewNamingClient(
Expand Down Expand Up @@ -137,11 +135,9 @@ func main() {
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
RotateTime: "1h",
MaxAge: 3,
LogLevel: "info",
Username: "test",
Password: "test"
Username: "your-name",
Password: "your-password"
}

cli,err := clients.NewNamingClient(
Expand Down
12 changes: 4 additions & 8 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ func main() {
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
RotateTime: "1h",
MaxAge: 3,
LogLevel: "info",
Username: "test",
Password: "test"
Username: "your-name",
Password: "your-password"
}

cli, err := clients.NewNamingClient(
Expand Down Expand Up @@ -147,11 +145,9 @@ func main() {
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
RotateTime: "1h",
MaxAge: 3,
LogLevel: "info",
Username: "test",
Password: "test"
Username: "your-name",
Password: "your-password"
}

cli,err := clients.NewNamingClient(
Expand Down
File renamed without changes.
File renamed without changes.
70 changes: 70 additions & 0 deletions example/custom-config/client/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2021 CloudWeGo Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"
"log"
"time"

"github.com/cloudwego/kitex-examples/hello/kitex_gen/api"
"github.com/cloudwego/kitex-examples/hello/kitex_gen/api/hello"
"github.com/cloudwego/kitex/client"
"github.com/kitex-contrib/registry-nacos/resolver"
"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 main() {
// the nacos server config
sc := []constant.ServerConfig{
*constant.NewServerConfig("127.0.0.1", 8848),
}

// the nacos client config
cc := constant.ClientConfig{
NamespaceId: "public",
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
LogLevel: "info",
// more ...
}

cli, err := clients.NewNamingClient(
vo.NacosClientParam{
ClientConfig: &cc,
ServerConfigs: sc,
},
)
if err != nil {
panic(err)
}
newClient := hello.MustNewClient(
"Hello",
client.WithResolver(resolver.NewNacosResolver(cli)),
client.WithRPCTimeout(time.Second*3),
)
for {
resp, err := newClient.Echo(context.Background(), &api.Request{Message: "Hello"})
if err != nil {
log.Fatal(err)
}
log.Println(resp)
time.Sleep(time.Second)
}
}
77 changes: 77 additions & 0 deletions example/custom-config/server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2021 CloudWeGo Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"
"log"

"github.com/cloudwego/kitex-examples/hello/kitex_gen/api"
"github.com/cloudwego/kitex-examples/hello/kitex_gen/api/hello"
kitexregistry "github.com/cloudwego/kitex/pkg/registry"
"github.com/cloudwego/kitex/server"
"github.com/kitex-contrib/registry-nacos/registry"
"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"
)

type HelloImpl struct{}

func (h *HelloImpl) Echo(_ context.Context, req *api.Request) (resp *api.Response, err error) {
resp = &api.Response{
Message: req.Message,
}
return
}

func main() {
// the nacos server config
sc := []constant.ServerConfig{
*constant.NewServerConfig("127.0.0.1", 8848),
}

// the nacos client config
cc := constant.ClientConfig{
NamespaceId: "public",
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
LogLevel: "info",
// more ...
}

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

svr := hello.NewServer(
new(HelloImpl),
server.WithRegistryInfo(&kitexregistry.Info{ServiceName: "Hello"}),
server.WithRegistry(registry.NewNacosRegistry(cli)),
)
if err := svr.Run(); err != nil {
log.Println("server stopped with error:", err)
} else {
log.Println("server stopped")
}
}
78 changes: 78 additions & 0 deletions example/custom-logger/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2021 CloudWeGo Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"
"log"

"github.com/cloudwego/kitex-examples/hello/kitex_gen/api"
"github.com/cloudwego/kitex-examples/hello/kitex_gen/api/hello"
kitexregistry "github.com/cloudwego/kitex/pkg/registry"
"github.com/cloudwego/kitex/server"
"github.com/kitex-contrib/registry-nacos/nacos"
"github.com/kitex-contrib/registry-nacos/registry"
"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"
)

type HelloImpl struct{}

func (h *HelloImpl) Echo(_ context.Context, req *api.Request) (resp *api.Response, err error) {
resp = &api.Response{
Message: req.Message,
}
return
}

func main() {
// the nacos server config
sc := []constant.ServerConfig{
*constant.NewServerConfig("127.0.0.1", 8848),
}

// the nacos client config
cc := constant.ClientConfig{
NamespaceId: "public",
TimeoutMs: 5000,
NotLoadCacheAtStart: true,
LogDir: "/tmp/nacos/log",
CacheDir: "/tmp/nacos/cache",
LogLevel: "info",
CustomLogger: nacos.NewCustomNacosLogger(), // With a custom Logger,you can use kitex `klog` or other.
}

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

svr := hello.NewServer(
new(HelloImpl),
server.WithRegistryInfo(&kitexregistry.Info{ServiceName: "Hello"}),
server.WithRegistry(registry.NewNacosRegistry(cli)),
)
if err := svr.Run(); err != nil {
log.Println("server stopped with error:", err)
} else {
log.Println("server stopped")
}
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module github.com/kitex-contrib/registry-nacos
go 1.16

require (
github.com/cloudwego/kitex v0.1.4
github.com/cloudwego/kitex v0.3.2
github.com/cloudwego/kitex-examples v0.0.0-20220119031419-496e8f89fe75
github.com/nacos-group/nacos-sdk-go v1.1.2-0.20220407143335-bff55a2174fc
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.2.8 // indirect
)
Loading