nacos

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 19 Imported by: 0

README

nacos-gf

install

go get -u -v github.com/LanceAdd/nacos-gf latest

config.yaml

nacos:
  cloud:
    config: true
    registry: true
  config:
    ip: "127.0.0.1"
    port: 8848
    nameSpaceId: "public"
    group: "default"
    dataId: "config.yaml"
    username: "nacos"
    password: "nacos"
  registry:
    ip: "127.0.0.1"
    port: 8848 s
    nameSpaceId: "public"
    group: "default"
    username: "nacos"
    password: "nacos"
    clusterName: "default"

Usage

package boot

import (
	"github.com/LanceAdd/nacos-gf"
)

func init() {
	// The parameters of LoadRemoteConfig are custom functions that are used to perform some custom operations after the remote configuration file is updated
	nacos.LoadRemoteConfig(ReInitAuth, ReInitSecurity, ReInitSnapShot)
	nacos.LoadRegisterConfig()
}

package main

import (
    _ "example/boot"
	"github.com/gogf/gf/v2/frame/g"
)

func main() {
	server := g.Server("example")
    server.Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadRegisterConfig

func LoadRegisterConfig()

func LoadRemoteConfig

func LoadRemoteConfig(actions ...func())

func NewConfig

func NewConfig(ctx context.Context, config Config, actions ...func()) (adapter gcfg.Adapter, err error)

NewConfig creates and returns gcfg.Adapter implementing using nacos service.

func NewServiceFromInstance

func NewServiceFromInstance(instance []model.Instance) gsvc.Service

NewServiceFromInstance new one service from instance

func NewServicesFromInstances

func NewServicesFromInstances(instances []model.Instance) []gsvc.Service

NewServicesFromInstances new some services from some instances

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements gcfg.Adapter implementing using nacos service.

func (*Client) Available

func (c *Client) Available(ctx context.Context, resource ...string) (ok bool)

Available checks and returns the backend configuration service is available. The optional parameter `resource` specifies certain configuration resource.

Note that this function does not return error as it just does simply check for backend configuration service.

func (*Client) Data

func (c *Client) Data(ctx context.Context) (data map[string]interface{}, err error)

Data retrieves and returns all configuration data in current resource as map. Note that this function may lead lots of memory usage if configuration data is too large, you can implement this function if necessary.

func (*Client) Get

func (c *Client) Get(ctx context.Context, pattern string) (value interface{}, err error)

Get retrieves and returns value by specified `pattern` in current resource. Pattern like: "x.y.z" for map item. "x.0.y" for slice item.

type Config

type Config struct {
	ServerConfigs []constant.ServerConfig `v:"required"` // See constant.ServerConfig
	ClientConfig  constant.ClientConfig   `v:"required"` // See constant.ClientConfig
	ConfigParam   vo.ConfigParam          `v:"required"` // See vo.ConfigParam
	Watch         bool                    // Watch watches remote configuration updates, which updates local configuration in memory immediately when remote configuration changes.
}

Config is the configuration object for nacos client.

type LocalNacosConfig

type LocalNacosConfig struct {
	Ip          string `v:"required#[nacos.config.ip] can not be empty"`
	Port        uint64 `v:"required#[nacos.config.port] can not be empty"`
	NameSpaceId string `v:"required#[nacos.config.name-space-id] can not be empty"`
	Group       string `v:"required#[nacos.config.group] can not be empty"`
	DataId      string `v:"required#[nacos.config.data-id] can not be empty"`
	Username    string `v:"required#[nacos.config.username] can not be empty"`
	Password    string `v:"required#[nacos.config.password] can not be empty"`
}

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry is nacos registry.

func NewRegistry

func NewRegistry(address []string, opts ...constant.ClientOption) (reg *Registry)

NewRegistry new a registry with address and opts

func NewWithClient

func NewWithClient(client naming_client.INamingClient) *Registry

NewWithClient new the instance with INamingClient

func NewWithConfig

func NewWithConfig(ctx context.Context, config RegistryConfig) (reg *Registry, err error)

NewConfig creates and returns registry with Config.

func (*Registry) Deregister

func (reg *Registry) Deregister(ctx context.Context, service gsvc.Service) (err error)

Deregister off-lines and removes `service` from the Registry.

func (*Registry) Register

func (reg *Registry) Register(ctx context.Context, service gsvc.Service) (registered gsvc.Service, err error)

Register registers `service` to Registry. Note that it returns a new Service if it changes the input Service with custom one.

func (*Registry) Search

func (reg *Registry) Search(ctx context.Context, in gsvc.SearchInput) (result []gsvc.Service, err error)

Search searches and returns services with specified condition.

func (*Registry) SetClusterName

func (reg *Registry) SetClusterName(clusterName string) *Registry

SetClusterName can set the clusterName. The default is 'DEFAULT'

func (*Registry) SetGroupName

func (reg *Registry) SetGroupName(groupName string) *Registry

SetGroupName can set the groupName. The default is 'DEFAULT_GROUP'

func (*Registry) Watch

func (reg *Registry) Watch(ctx context.Context, key string) (watcher gsvc.Watcher, err error)

Watch watches specified condition changes. The `key` is the prefix of service key.

type RegistryConfig

type RegistryConfig struct {
	ServerConfigs []constant.ServerConfig `v:"required"` // See constant.ServerConfig
	ClientConfig  *constant.ClientConfig  `v:"required"` // See constant.ClientConfig
}

RegistryConfig is the configuration object for nacos client.

type RemoteRegistryConfig

type RemoteRegistryConfig struct {
	Ip          string `v:"required#[nacos.registry.ip] can not be empty"`
	Port        uint64 `v:"required#[nacos.registry.port] can not be empty"`
	NameSpaceId string `v:"required#[nacos.registry.name-space-id] can not be empty"`
	Group       string `v:"required#[nacos.registry.group] can not be empty"`
	Username    string `v:"required#[nacos.registry.username] can not be empty"`
	Password    string `v:"required#[nacos.registry.password] can not be empty"`
	ClusterName string `v:"required#[nacos.registry.cluster-name] can not be empty"`
}

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher used to mange service event such as update.

func (*Watcher) Close

func (w *Watcher) Close() (err error)

Close closes the watcher.

func (*Watcher) Proceed

func (w *Watcher) Proceed() (services []gsvc.Service, err error)

Proceed proceeds watch in blocking way. It returns all complete services that watched by `key` if any change.

func (*Watcher) Push

func (w *Watcher) Push(services []model.Instance, err error)

Push add the services watchevent to event queue

func (*Watcher) SetCloseFunc

func (w *Watcher) SetCloseFunc(close func() error)

SetCloseFunc set the close callback function

Jump to

Keyboard shortcuts

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