nacos

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NacosClientLogger seelog.LoggerInterface
	LogConfig         string
	GrpcClient        *NacosGrpcClient
)
View Source
var (
	DefaultCacheMillis = int64(5000)
	Version            = "Nacos-DNS:v1.0.1"
	CachePath          string
	LogPath            string
	SEPERATOR          = "@@"
	GZIP_MAGIC         = []byte("\x1F\x8B")
	EnableReceivePush  = true
	UDP_Port           = -1
	SERVER_PORT        = "8848"
)
View Source
var DNSDomains = make(map[string]string)
View Source
var DNSTTL uint32 = 1
View Source
var Inited = false
View Source
var SHARD_COUNT = 32

Functions

func CurrentMillis

func CurrentMillis() int64

func Exist

func Exist(path string) bool

func Get

func Get(url string, params map[string]string) string

func GetCacheKey

func GetCacheKey(dom, clientIP string) string

func GetCurrentDirectory

func GetCurrentDirectory() string

func Home

func Home() string

func IsGzipFile

func IsGzipFile(data []byte) bool

func LocalIP

func LocalIP() string

func TryDecompressData

func TryDecompressData(data []byte) string

Types

type AllDomNames

type AllDomNames struct {
	Doms        []string `json:"doms"`
	CacheMillis int      `json:"cacheMillis"`
}

type AllDomsMap

type AllDomsMap struct {
	Data         map[string]bool
	CacheSeconds int
	DLock        sync.RWMutex
}
var AllDoms AllDomsMap

type ConcurrentMap

type ConcurrentMap []*ConcurrentMapShared

A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (SHARD_COUNT) map shards.

func NewConcurrentMap

func NewConcurrentMap() ConcurrentMap

Creates a new concurrent map.

func (ConcurrentMap) Count

func (m ConcurrentMap) Count() int

Returns the number of elements within the map.

func (ConcurrentMap) Get

func (m ConcurrentMap) Get(key string) (interface{}, bool)

Retrieves an element from map under given key.

func (ConcurrentMap) GetShard

func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared

Returns shard under given key

func (ConcurrentMap) Has

func (m ConcurrentMap) Has(key string) bool

Looks up an item under specified key

func (ConcurrentMap) IsEmpty

func (m ConcurrentMap) IsEmpty() bool

Checks if map is empty.

func (ConcurrentMap) Items

func (m ConcurrentMap) Items() map[string]interface{}

Returns all items as map[string]interface{}

func (ConcurrentMap) Iter deprecated

func (m ConcurrentMap) Iter() <-chan Tuple

Returns an iterator which could be used in a for range loop.

Deprecated: using IterBuffered() will get a better performence

func (ConcurrentMap) IterBuffered

func (m ConcurrentMap) IterBuffered() <-chan Tuple

Returns a buffered iterator which could be used in a for range loop.

func (ConcurrentMap) IterCb

func (m ConcurrentMap) IterCb(fn IterCb)

Callback based iterator, cheapest way to read all elements in a map.

func (ConcurrentMap) Keys

func (m ConcurrentMap) Keys() []string

Return all keys as []string

func (ConcurrentMap) MSet

func (m ConcurrentMap) MSet(data map[string]interface{})

func (ConcurrentMap) MarshalJSON

func (m ConcurrentMap) MarshalJSON() ([]byte, error)

Reviles ConcurrentMap "private" variables to json marshal.

func (ConcurrentMap) Pop

func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool)

Removes an element from the map and returns it

func (ConcurrentMap) Remove

func (m ConcurrentMap) Remove(key string)

Removes an element from the map.

func (ConcurrentMap) Set

func (m ConcurrentMap) Set(key string, value interface{})

Sets the given value under the specified key.

func (ConcurrentMap) SetIfAbsent

func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool

Sets the given value under the specified key if no value was associated with it.

func (ConcurrentMap) Upsert

func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})

Insert or Update - updates existing element or inserts a new one using UpsertCb

type ConcurrentMapShared

type ConcurrentMapShared struct {
	sync.RWMutex // Read Write mutex, guards access to internal map.
	// contains filtered or unexported fields
}

A "thread" safe string to anything map.

type DnsCache

type DnsCache struct {
	Msg             *dns.Msg
	LastUpdateMills int64
}

func (*DnsCache) Updated

func (dnsCache *DnsCache) Updated() bool

type DomCache

type DomCache map[string]Domain

type Domain

type Domain struct {
	Name          string `json:"dom"`
	Clusters      string
	CacheMillis   int64
	LastRefMillis int64
	Instances     []Instance `json:"hosts"`
	Env           string
	TTL           int
}

func ProcessDomainString

func ProcessDomainString(s string) (Domain, error)

func (Domain) SrvInstances

func (domain Domain) SrvInstances() []Instance

func (Domain) String

func (domain Domain) String() string

type Instance

type Instance struct {
	IP         string
	Port       int
	Weight     float64
	Valid      bool
	Unit       string
	AppUseType string
	Site       string
}

func (Instance) String

func (h Instance) String() string

type IterCb

type IterCb func(key string, v interface{})

Iterator callback,called for every key,value found in maps. RLock is held for all calls for a given shard therefore callback sess consistent view of a shard, but not across the shards

type Nacos

type Nacos struct {
	Next            plugin.Handler
	Zones           []string
	NacosClientImpl *NacosClient
	DNSCache        ConcurrentMap
}

func NacosParse

func NacosParse(c *caddy.Controller) (*Nacos, error)

func (*Nacos) Name

func (vs *Nacos) Name() string

func (*Nacos) ServeDNS

func (vs *Nacos) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

func (*Nacos) String

func (vs *Nacos) String() string

type NacosClient

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

func NewNacosClient

func NewNacosClient(namespaceId string, serverHosts []string) *NacosClient

func (*NacosClient) Contains

func (vc *NacosClient) Contains(dom, clientIP string, host model.Instance) bool

func (*NacosClient) GetDomain

func (vc *NacosClient) GetDomain(name string) (*Domain, error)

func (*NacosClient) GetDomainCache

func (vc *NacosClient) GetDomainCache() ConcurrentMap

func (*NacosClient) GetUdpServer

func (nacosClient *NacosClient) GetUdpServer() (us UDPServer)

func (*NacosClient) Registered

func (vc *NacosClient) Registered(dom string) bool

func (*NacosClient) SrvInstance

func (vc *NacosClient) SrvInstance(domainName, clientIP string) *model.Instance

func (*NacosClient) SrvInstances

func (vc *NacosClient) SrvInstances(domainName, clientIP string) []model.Instance

type NacosClientError

type NacosClientError struct {
	Msg string
}

func (NacosClientError) Error

func (err NacosClientError) Error() string

type NacosGrpcClient

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

func NewNacosGrpcClient

func NewNacosGrpcClient(namespaceId string, serverHosts []string, vc *NacosClient) (*NacosGrpcClient, error)

func (*NacosGrpcClient) Callback

func (ngc *NacosGrpcClient) Callback(instances []model.Instance, err error)

func (*NacosGrpcClient) GetAllServicesInfo

func (ngc *NacosGrpcClient) GetAllServicesInfo() []string

func (*NacosGrpcClient) GetService

func (ngc *NacosGrpcClient) GetService(serviceName string) model.Service

func (*NacosGrpcClient) Subscribe

func (ngc *NacosGrpcClient) Subscribe(serviceName string) error

type NewAllDomNames

type NewAllDomNames struct {
	Doms        map[string][]string `json:"doms"`
	CacheMillis int                 `json:"cacheMillis"`
}

type PushData

type PushData struct {
	PushType    string `json:"type"`
	Data        string `json:"data"`
	LastRefTime int64  `json:"lastRefTime"`
}

type ServerManager

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

func (*ServerManager) GetServerList

func (manager *ServerManager) GetServerList() []string

func (*ServerManager) NextServer

func (manager *ServerManager) NextServer() string

func (*ServerManager) RefreshServerListIfNeed

func (manager *ServerManager) RefreshServerListIfNeed() []string

get nacos ip list from address by env

func (*ServerManager) SetServers

func (manager *ServerManager) SetServers(servers []string)

type Servers

type Servers []string

type Tuple

type Tuple struct {
	Key string
	Val interface{}
}

Used by the Iter & IterBuffered functions to wrap two variables together over a channel,

type UDPServer

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

func (*UDPServer) SetNacosClient

func (us *UDPServer) SetNacosClient(nc *NacosClient)

func (*UDPServer) StartServer

func (us *UDPServer) StartServer()

type UpsertCb

type UpsertCb func(exist bool, valueInMap interface{}, newValue interface{}) interface{}

Callback to return new element to be inserted into the map It is called while lock is held, therefore it MUST NOT try to access other keys in same map, as it can lead to deadlock since Go sync.RWLock is not reentrant

Jump to

Keyboard shortcuts

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