Documentation ¶
Index ¶
- Constants
- type AccConfs
- type ConfigKey
- type ConfigStub
- func (c *ConfigStub) CancelListens(keys []ConfigKey) error
- func (c *ConfigStub) Delete(did, group string) error
- func (c *ConfigStub) Deletes(keys []ConfigKey) error
- func (c *ConfigStub) GetString(did, group string) (string, error)
- func (c *ConfigStub) GetStruct(did, group string, out any) error
- func (c *ConfigStub) Listen(did, group string, cb ListenCallback) error
- func (c *ConfigStub) Listens(keys []ConfigKey, cb ListenCallback) error
- func (c *ConfigStub) Publish(did, group string, config any) error
- func (c *ConfigStub) Setup() error
- type DTalkSender
- type GrpcCert
- type GrpcCerts
- type ListenCallback
- type MallAcc
- type MetaConfig
- func (mc *MetaConfig) GetConfig(dataId string) (string, error)
- func (mc *MetaConfig) ListenConfig(dataId string, cb MetaConfigCallback)
- func (mc *MetaConfig) ListenConfigs(dataIds []string, cb MetaConfigCallback)
- func (mc *MetaConfig) OnChanged(namespace, group, dataId, data string)
- func (mc *MetaConfig) PushConfig(dataId, data string) error
- func (mc *MetaConfig) UpdateChineses(descs []*utils.SvrDesc) error
- func (mc *MetaConfig) UploadRouters() error
- type MetaConfigCallback
- type OTAInfo
- type ServerCallback
- type ServerItem
- type ServerStub
- func (s *ServerStub) Deregister(name, host string, port uint64, opts ...string) error
- func (s *ServerStub) GetServer(name string, opts ...string) (*model.Service, error)
- func (ss *ServerStub) ListenServers(servers []*ServerItem)
- func (s *ServerStub) Register(name, host string, port uint64, opts ...string) error
- func (s *ServerStub) Setup() error
- func (s *ServerStub) Subscribe(name string, cb SubscribeCallback, opts ...string) error
- func (s *ServerStub) Unsubscribe(name string, cb SubscribeCallback, opts ...string) error
- type SubscribeCallback
Constants ¶
const ( NS_PROD = "dunyu-server-prod" // PROD namespace id NS_DEV = "dunyu-server-dev" // DEV namespace id )
Nacos namespace string for wcore/nacos
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 informations DID_WX_AGENTS = "dunyu.wx.agents" // Fixed group, data id of wechat agents DID_QKS_CERT = "dunyu.qks.cert" // Fixed group, data id of qks rsa cert public key )
Nacos data id for wcore/nacos
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 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
Generate a 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 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 MetaConfig ¶
type MetaConfig struct { Stub *ConfigStub // Nacos config client instance Callbacks map[string]MetaConfigCallback // Meta config changed callback maps, key is dataid }
Meta config informations
func GenMetaConfig ¶
func GenMetaConfig() *MetaConfig
Generate a 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 = "10.239.40.24"
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(dataIds []string, cb MetaConfigCallback)
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 ServerCallback ¶
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
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
Generate a 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 = "10.239.40.24" [dev] ; Inner net ideal address for dev servers access nacosaddr = "10.239.20.99" ; Inner net port for grpc access nacosport = 3000 [prod] ; Inner net ideal address for prod servers access nacosaddr = "10.239.40.64" ; 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 ¶
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 ¶
Callback to listen server register status changed