nacos

package module
v0.0.0-...-f8d5985 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2023 License: MIT Imports: 21 Imported by: 0

README

Quick Start

Prerequisites:

Download the module:

go get -u github.com/hewenyu/zero-contrib/zrpc/registry/nacos

fix config

Addr: nacos-cs.ops.svc.cluster.local
Port: 8848
Group: DEFAULT_GROUP
DataID: demo-api
ExtDataIDs:
  - mysql
  - auth
NamespaceID: demo

For example:

Service

  • main.go
import _ "github.com/hewenyu/zero-contrib/zrpc/registry/nacos"

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)

	server := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {

	})
	// register service to nacos
	sc := []constant.ServerConfig{
		*constant.NewServerConfig("192.168.100.15", 8848),
	}

	cc := &constant.ClientConfig{
		NamespaceId:         "public",
		TimeoutMs:           5000,
		NotLoadCacheAtStart: true,
		LogDir:              "/tmp/nacos/log",
		CacheDir:            "/tmp/nacos/cache",
		RotateTime:          "1h",
		MaxAge:              3,
		LogLevel:            "debug",
	}

	opts := nacos.NewNacosConfig("nacos.rpc", c.ListenOn, sc, cc)
	_ = nacos.RegisterService(opts)
	server.Start()
}

Client

  • main.go
import _ "github.com/hewenyu/zero-contrib/zrpc/registry/nacos"
  • etc/*.yaml
# nacos://[user:passwd]@host/service?param=value'
Target: nacos://192.168.100.15:8848/nacos.rpc?namespaceid=public&timeout=5000s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterService

func RegisterService(opts *Options) error

RegisterService register service to nacos

Types

type Option

type Option func(*Options)

func WithCluster

func WithCluster(cluster string) Option

func WithGroup

func WithGroup(group string) Option

func WithMetadata

func WithMetadata(metadata map[string]string) Option

func WithPrefix

func WithPrefix(prefix string) Option

func WithWeight

func WithWeight(weight float64) Option

type Options

type Options struct {
	ListenOn    string
	ServiceName string
	Prefix      string
	Weight      float64
	Cluster     string
	Group       string
	Metadata    map[string]string

	ServerConfig []constant.ServerConfig
	ClientConfig *constant.ClientConfig
}

options

func NewNacosConfig

func NewNacosConfig(serviceName, listenOn string, sc []constant.ServerConfig, cc *constant.ClientConfig, opts ...Option) *Options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL