nacos

package
v0.0.0-...-83b9770 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NS_PROD = "dunyu-server-prod" // PROD namespace id
	NS_DEV  = "dunyu-server-dev"  // DEV  namespace id
)

Nacos namespace string for xcore/nacos

View Source
const (
	DID_ACC_CONFIGS  = "dunyu.acc.configs"  // Fixed group, data id of accservice cofnigs
	DID_API_ROUTERS  = "dunyu.api.routers"  // Fixed group, data id of swagger restful routers
	DID_DTALK_NTFERS = "dunyu.dtalk.ntfers" // Fixed group, data id of dingtalk notifiers
	DID_ES_AGENTS    = "dunyu.es.agents"    // Fixed group, data id of elastic search agents
	DID_GRPC_CERTS   = "dunyu.grpc.certs"   // Fixed group, data id of grpc certs that datas format as xml
	DID_MIO_PATHS    = "dunyu.mio.paths"    // Fixed group, data id of minio source paths
	DID_MIO_USERS    = "dunyu.mio.users"    // Fixed group, data id of minio account key
	DID_MQTT_AGENTS  = "dunyu.mqtt.agents"  // Fixed group, data id of mqtt agents
	DID_OTA_BUILDS   = "dunyu.ota.builds"   // Fixed group, data id of all projects OTA infos, get data from mc.OTA maps
	DID_WX_AGENTS    = "dunyu.wx.agents"    // Fixed group, data id of wechat agents
	DID_QK_WORDS     = "dunyu.qk.words"     // Fixed group, data id for excel words to parse rules
)

Nacos data id for xcore/nacos

View Source
const GP_WENGOLD = "group.wengold"

Fixed all registered servers and configs named 'wengold' group

Variables

This section is empty.

Functions

This section is empty.

Types

type AccConfs

type AccConfs struct {

	// Email sender service
	Email struct {
		Host     string `json:"host"`
		Port     int    `json:"port"`
		Identity string `json:"identity"`
	} `json:"email"`

	// SMS sender service
	Sms struct {
		Secret    string `json:"secret"`
		KeyID     string `json:"keyid"`
		URLFormat string `json:"urlformat"`
	} `json:"sms"`

	// Account secure settings
	Secures struct {
		SecureSalt   string `json:"secureSalt"`   // Secure salt key to decode account login token
		ApiTaxCode   string `json:"apiTaxCode"`   // Auth code to access API of check company tax code
		ApiIDViaCode string `json:"apiIDViaCode"` // Auth code to access API of identification check
		PageLimits   int    `json:"pageLimits"`   // One times to get list item counts on a page
	} `json:"secure"`

	// Mall account settings
	MallAccs map[string]*MallAcc `json:"mallaccs"`
}

Nacos config for data id DID_ACC_CONFIGS

type ConfigKey

type ConfigKey struct {
	DataID string // config data id
	Group  string // config group name
}

Nacos config keyword datas

type ConfigStub

type ConfigStub struct {
	Namespace   string                      // Namespace id, it defined on console at first
	NacosServer string                      // Nacos server host ip
	Stub        config_client.IConfigClient // Nacos configs client instance
}

Nacos config client stub

func NewConfigStub

func NewConfigStub(ns, svr string) *ConfigStub

Create a new ConfigStub instance.

@params ns  string config namespace id
@params svr string remote nacos server ip address
@return - *ConfigStub config stub instance

func (*ConfigStub) CancelListens

func (c *ConfigStub) CancelListens(keys []ConfigKey) error

Cancel listen configs changed

@params keys []ConfigKey configs keywords
@return - error handle exception

func (*ConfigStub) Delete

func (c *ConfigStub) Delete(did, group string) error

Delete registered config

@params did   string data id of nacos defined
@params group string group name of nacos defined
@return - error handle exception

func (*ConfigStub) Deletes

func (c *ConfigStub) Deletes(keys []ConfigKey) error

Delete registered configs

@params keys []ConfigKey configs keywords
@return - error handle exception

func (*ConfigStub) GetString

func (c *ConfigStub) GetString(did, group string) (string, error)

Get string config content

@params did   string data id of nacos defined
@params group string group name of nacos defined
@return - string config content string
		- error  handle exception

func (*ConfigStub) GetStruct

func (c *ConfigStub) GetStruct(did, group string, out any) error

Get struct config content from josn string

@params did   string data id of nacos defined
@params group string group name of nacos defined
@return - out   config struct data
		- error handle exception

func (*ConfigStub) Listen

func (c *ConfigStub) Listen(did, group string, cb ListenCallback) error

Listen same one config changed, and notify to update

@params did   string         data id of nacos defined
@params group string         group name of nacos defined
@params cb    ListenCallback config changed callback
@return - error handle exception

func (*ConfigStub) Listens

func (c *ConfigStub) Listens(keys []ConfigKey, cb ListenCallback) error

Listen multiple configs changed, and using same callback to update

@params keys []ConfigKey    configs keywords
@params cb   ListenCallback config changed callback
@return - error handle exception

func (*ConfigStub) Publish

func (c *ConfigStub) Publish(did, group string, config any) error

Publish config to nacos server, just support string and json struct datas

@params did    string    data id of nacos defined
@params group  string    group name of nacos defined
@params config interface string or struct type config content
@return - error handle exception

func (*ConfigStub) Setup

func (c *ConfigStub) Setup() error

Setup config stub instance, it must set stub namespace and nacos server values before call this function

type DTalkSender

type DTalkSender struct {
	WebHook   string   `json:"webhook"`   // DingTalk group chat session webhook
	Secure    string   `json:"secure"`    // DingTalk group chat senssion secure key
	Receivers []string `json:"receivers"` // The target @ users
}

Nacos config for DingTalk notify sender

type EConflicts

type EConflicts struct {
	Older   string `json:"older"`
	Version string `json:"version"`
	Broker  string `json:"broker"`
	Topics  string `json:"topics"`
	Dicts   string `json:"dicts"`
	Devices string `json:"devices"`
}

Conflicts format string for excel rules join

type ESConfig

type ESConfig struct {
	Address []string `json:"address"`
	User    string   `json:"user"`
	Pwd     string   `json:"pwd"`
	CFP     string   `json:"cfp"`
}

Elastic agent configs

type EWords

type EWords struct {
	Instruct  string            `json:"instruct"`  // sheet name of instruct
	Broker    string            `json:"broker"`    // sheet name of broker
	Topics    string            `json:"topics"`    // sheet name of topics
	Dicts     string            `json:"dicts"`     // sheet name of dicts
	Devices   string            `json:"devices"`   // sheet name of devices
	Prefix    string            `json:"prefix"`    // sheets perfix of topics rule
	Sheets    []string          `json:"sheets"`    // sheets seqence for parse rule
	StartCell string            `json:"startcell"` // rule policy start cell label
	Threshold string            `json:"threshold"` // threshold mark
	Conflicts EConflicts        `json:"conflicts"` // conflicts format strings for join multiple excels
	Policies  map[string]int    `json:"policies"`  // excel words to policy types
	Keeps     map[string]int    `json:"keeps"`     // excel words to save keeping mintues
	Purposes  map[string]int    `json:"purposes"`  // excel words to purposes types
	Analysis  map[string]int    `json:"analysis"`  // excel words to analysis types
	Actions   map[string]int    `json:"actions"`   // excel words to action types
	StartEnd  map[string]string `json:"startend"`  // excel words to start and end keywords
}

Excel rule words

type GrpcCert

type GrpcCert struct {
	Svr string `xml:"Server"` // GRPC cert server name
	Key string `xml:"Key"`    // GRPC cert key data
	Pem string `xml:"Pem"`    // GRPC cert pem data
}

Nacos config for GRPC cert content

type GrpcCerts

type GrpcCerts struct {
	Certs []GrpcCert `xml:"Cert"` // GRPC certs
}

Nacos config for GRPC certs

type ListenCallback

type ListenCallback func(namespace, group, dataId, data string)

Callback to listen config changed

type MallAcc

type MallAcc struct {
	User string `json:"user"`
	Pwd  string `json:"pwd"`
}

Nacos config for mall account settings

type MetaConfig

type MetaConfig struct {
	Stub      *ConfigStub                   // Nacos config client instance
	Callbacks map[string]MetaConfigCallback // Meta config changed callback maps, key is dataid

	// Custom datas when project register data ids, see parseXxxx inner functions.
	Conf    AccConfs                     // DID_ACC_CONFIGS  : Account configs
	OTA     map[string]*OTAInfo          // DID_OTA_BUILDS   : Projects OTA infos
	Senders map[string]*DTalkSender      // DID_DTALK_NTFERS : DingTalk senders
	Agents  map[string]*wechat.WxIFAgent // DID_WX_AGENTS    : Wechat agents
	Paths   map[string][]*ResPath        // DID_MIO_PATHS    : MinIO export resource paths
	Users   map[string]string            // DID_MIO_USERS    : MinIO access service users
	Words   EWords                       // DID_QK_WORDS     : Excel rule words
}

Meta config informations

func GenMetaConfig deprecated

func GenMetaConfig() *MetaConfig

Deprecated: use utils.NewMetaConfig instead it.

func NewMetaConfig

func NewMetaConfig() *MetaConfig

Create meta config client to get or listen configs changes

@return - *MetaConfig nacos config client instance

`NOTICE` : nacos config as follows.

----

; Nacos remote server host
nacossvr = "xx.xxx.40.218"

func (*MetaConfig) GetConfig

func (mc *MetaConfig) GetConfig(dataId string) (string, error)

Get config data from nacos server by given data id

func (*MetaConfig) ListenConfig

func (mc *MetaConfig) ListenConfig(dataId string, cb MetaConfigCallback)

Get and listing the config of indicated dataId

func (*MetaConfig) ListenConfigs

func (mc *MetaConfig) ListenConfigs(cb MetaConfigCallback, dataIds ...string)

Get and listing the configs of indicated dataIds

func (*MetaConfig) OnChanged

func (mc *MetaConfig) OnChanged(namespace, group, dataId, data string)

Listing callback called when target configs changed

func (*MetaConfig) PushConfig

func (mc *MetaConfig) PushConfig(dataId, data string) error

Push config data to indicated nacos config

func (*MetaConfig) UpdateChineses

func (mc *MetaConfig) UpdateChineses(descs []*utils.SvrDesc) error

Update routers chinese descriptions and upload to nacos

func (*MetaConfig) UploadRouters

func (mc *MetaConfig) UploadRouters() error

Parse local server swagger and upload routers to nacos

type MetaConfigCallback

type MetaConfigCallback func(dataId, data string)

Callback to listen server address and port changes

type OTAInfo

type OTAInfo struct {
	BuildVersion string  `json:"BuildVersion" description:"Build version string"`
	BuildNumber  int     `json:"BuildNumber"  description:"Build number, pase form BuildVersion string as version = major*10000 + middle*100 + minor"`
	DownloadUrl  string  `json:"DownloadUrl"  description:"Bin file download url"`
	UpdateDate   string  `json:"UpdateDate"   description:"Bin file update date"`
	HashSums     string  `json:"HashSums"     description:"Bin file hash sums"`
	BinSizes     float64 `json:"BinSizes"     description:"Bin file sizes in MB"`
}

Nacos config for OTA upgrade by using DID_OTA_BUILDS data id

type ResPath

type ResPath struct {
	Res  string `json:"res"`  // Resource number as unique id used by outside to bind real bucket path
	Path string `json:"path"` // Real bucket path of MinIO service
}

Bucket path bund resource number to export MinIO bucket paths

type ServerCallback

type ServerCallback func(svr, addr string, port int)

Callback to listen server address and port changes

type ServerItem

type ServerItem struct {
	Name     string         // Server name, same as beego app name
	Callback ServerCallback // Server register datas changed callback
}

Server register informations

func (*ServerItem) OnChanged

func (si *ServerItem) OnChanged(services []model.Instance, err error)

Subscribe callback called when target service address and port changed

type ServerStub

type ServerStub struct {
	Namespace   string                      // Namespace id, it defined on console at first
	NacosServer string                      // Nacos server host ip
	Stub        naming_client.INamingClient // Nacos naming client instance
}

Nacos naming client stub

func NewServerStub

func NewServerStub(ns, svr string) *ServerStub

Create a new ServerStub instance.

@params ns  string server namespace id
@params svr string remote nacos server ip address
@return - *ServerStub server stub instance

func RegisterServer

func RegisterServer() *ServerStub

Register current server to nacos, you must set configs in app.conf

@return - *ServerStub nacos server stub instance

`NOTICE` : nacos config as follows.

----

; Nacos remote server host
nacossvr = "xx.xxx.40.218"

[dev]
; Inner net ideal address for dev servers access
nacosaddr = "xx.xxx.20.239"

; Inner net port for grpc access
nacosport = 3000

[prod]
; Inner net ideal address for prod servers access
nacosaddr = "xx.xxx.40.199"

; Inner net port for grpc access
nacosport = 3000

func (*ServerStub) Deregister

func (s *ServerStub) Deregister(name, host string, port uint64, opts ...string) error

Deregister business server out of nacos remote server

@params name string   business server name
@params host string   business server deploied ip or domain
@params port uint64   business server port, must over 3000
@params opts []string 0:group name, 1:cluster name of business server
@return - error handle exception

func (*ServerStub) GetServer

func (s *ServerStub) GetServer(name string, opts ...string) (*model.Service, error)

Get business server registry informations from nacos remote server

@params name string   business server name
@params opts []string 0:group name, 1~n:clusters name of business server
@return - error handle exception

func (*ServerStub) ListenServers

func (ss *ServerStub) ListenServers(servers []*ServerItem)

Listing services address and port changes, it will call the callback immediately to return target service host when them allready registerd to service central of nacos.

@params servers []*ServerItem target server registry informations

func (*ServerStub) Register

func (s *ServerStub) Register(name, host string, port uint64, opts ...string) error

Register business server into nacos remote server

@params name string   business server name
@params host string   business server deploied ip or domain
@params port uint64   business server port, must over 3000
@params opts []string 0:group name, 1:cluster name of business server
@return - error handle exception

func (*ServerStub) Setup

func (s *ServerStub) Setup() error

Setup server stub instance, it must set stub namespace and nacos server values before call this function

func (*ServerStub) Subscribe

func (s *ServerStub) Subscribe(name string, cb SubscribeCallback, opts ...string) error

Subscribe business server registry changed event

@params name string            business server name
@params cb   SubscribeCallback server registry changed callback
@params opts []string          0:group name, 1~n:clusters name of business server
@return - error handle exception

func (*ServerStub) Unsubscribe

func (s *ServerStub) Unsubscribe(name string, cb SubscribeCallback, opts ...string) error

Unsubscribe business server registry changed event

@params name string            business server name
@params cb   SubscribeCallback server registry changed callback
@params opts []string          0:group name, 1~n:clusters name of business server
@return - error handle exception

type SubscribeCallback

type SubscribeCallback func(services []model.Instance, err error)

Callback to listen server register status changed

Jump to

Keyboard shortcuts

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