nacos

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultGroup   = "DEFAULT_GROUP"
	DefaultCluster = "DEFAULT"
	ClientVersion  = "1.1.3"
)
View Source
const (
	// GET http method GET
	GET = "GET"
	// POST http method POST
	POST = "POST"
	// DELETE http method DELETE
	DELETE = "DELETE"
	// PUT http method PUT
	PUT = "PUT"
)
View Source
const (
	SelectorTypeNone    = "none"
	SelectorTypeUnknown = "unknown"
	SelectorTypeLabel   = "label"
)

Variables

View Source
var (
	GZIP_MAGIC = []byte("\x1F\x8B")
)
View Source
var LogTag = []string{"[ERROR]", "[WARN ]", "[INFO ]", "[DEBUG]"}

Functions

func DefaultClient

func DefaultClient() *http.Client

DefaultClient returns a new http.Client with similar default values to http.Client, but with a non-shared Transport, idle connections disabled, and keepalives disabled.

func DefaultPooledClient

func DefaultPooledClient() *http.Client

DefaultPooledClient returns a new http.Client with similar default values to http.Client, but with a shared Transport. Do not use this function for transient clients as it can leak file descriptors over time. Only use this for clients that will be re-used for the same host(s).

func DefaultPooledTransport

func DefaultPooledTransport() *http.Transport

DefaultPooledTransport returns a new http.Transport with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).

func DefaultTransport

func DefaultTransport() *http.Transport

DefaultTransport returns a new http.Transport with default value, but with idle connections and keepalives disabled.

func GetLocalIP

func GetLocalIP() string

func IsGzipFile

func IsGzipFile(data []byte) bool

Types

type Client

type Client interface {
	Naming() NamingClient
	Config() ConfigClient
	Logger() Logger
}

Client provides a client to the Nacos API

func NewClient

func NewClient(config *Config) (Client, error)

NewClient returns a new nacos client

type Config

type Config struct {
	Scheme      string
	Hosts       []string
	ContextPath string
	AppName     string
	Namespace   string
	Endpoint    string
	Username    string
	Password    string
	AccessKey   string
	SecretKey   string
	Metadata    map[string]string
	HttpClient  *http.Client
	CacheDir    string
	LogDir      string
	LogLevel    LogLevel
}

Config is used to configure the creation of a client

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a new default config

type ConfigClient

type ConfigClient interface {
	GetConfig(dataID, group string) string

	GetConfigAndSignListener(dataID, group string, listener EventListener) string

	AddListener(dataID, group string, listener EventListener)

	PublishConfig(dataID, group, content string)

	RemoveConfig(dataID, group string)

	RemoveListener(dataID, group string)

	GetServerStatus() string

	Shutdown()
}

ConfigClient provides a client to the Nacos config API

type EventListener

type EventListener interface {
	OnEvent(*ServiceInfo)
}

type Instance

type Instance struct {
	GroupName   string
	ServiceName string
	ClusterName string
	InstanceID  string
	IP          string
	Port        int
	Weight      float64
	Healthy     bool
	Enable      bool
	Ephemeral   bool
	Metadata    *Metadata
}

func NewInstance

func NewInstance(serviceName, groupName, clusterName string, ip string, port int, weight float64, enable, ephemeral bool, metadata *Metadata) *Instance

type InstanceQueryOptions

type InstanceQueryOptions struct {
	ServiceName string
	GroupName   string
	ClusterName []string
	Subscribe   bool
	Healthy     bool
}

type LogLevel

type LogLevel int
const (
	LogOff LogLevel = iota + 1
	LogError
	LogWarn
	LogInfo
	LogDebug
)

type Logger

type Logger interface {
	Error(format string, args ...interface{})
	Warn(format string, args ...interface{})
	Info(format string, args ...interface{})
	Debug(format string, args ...interface{})
	IsDebugEnable() bool
	IsInfoEnable() bool
	IsErrorEnable() bool
	IsWarnEnable() bool
}

func NewLogger

func NewLogger(file string, level LogLevel) (Logger, error)

type Metadata

type Metadata struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMetadata

func NewMetadata(m map[string]string) *Metadata

func (Metadata) Contains

func (m Metadata) Contains(key string) bool

func (*Metadata) Encode

func (m *Metadata) Encode() string

func (*Metadata) Get

func (m *Metadata) Get(key string) string

func (*Metadata) GetOrDefault

func (m *Metadata) GetOrDefault(key string, defaultValue string) string

func (*Metadata) GetWithDefault

func (m *Metadata) GetWithDefault(key string, defaultValue interface{}, convertFn func(value string) (interface{}, error)) interface{}

func (*Metadata) Put

func (m *Metadata) Put(key, value string) *Metadata

type NamingClient

type NamingClient interface {
	SelectServices(ServiceQueryOptions) (*ServiceList, error)

	SelectService(ServiceQueryOptions) (*Service, error)

	CreateService(ServiceOptions) (*Response, error)

	DeleteService(ServiceOptions) (*Response, error)

	UpdateService(ServiceOptions) (*Response, error)

	RegisterInstance(*Instance) (*Response, error)

	DeRegisterInstance(serviceName, groupName, clusterName, ip string, port int, ephemeral bool) (*Response, error)

	SelectInstance(InstanceQueryOptions) []*Instance

	Subscribe(serviceName, groupName string, clusters []string, listener EventListener)

	Unsubscribe(serviceName, groupName string, clusters []string, listener EventListener)

	Shutdown()
}

NamingClient provides a client to the Nacos naming API

type Request

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

type Response

type Response struct {
	Code    int    `json:"code"`
	Message string `json:"message,omitempty"`
	Data    string `json:"data"`
}

func (*Response) BodyTo

func (r *Response) BodyTo(obj interface{}) bool

func (*Response) Ok

func (r *Response) Ok() bool

type Selector

type Selector struct {
	Type SelectorType `json:"type"`
}

type SelectorType

type SelectorType string

type Service

type Service struct {
	Name             string
	GroupName        string
	AppName          string
	Metadata         map[string]string
	ProtectThreshold float64
}

type ServiceInfo

type ServiceInfo struct {
	Name           string
	GroupName      string
	Clusters       string
	JsonFromServer string
	CacheMillis    int64
	Hosts          []*Instance
	LastRefTime    int64
	Checksum       string
	AllIPs         bool
}

func NewServiceInfo

func NewServiceInfo(name, groupName, clusters string) *ServiceInfo

func NewServiceInfoByKey

func NewServiceInfoByKey(key string) *ServiceInfo

func (*ServiceInfo) GetKey

func (s *ServiceInfo) GetKey() string

func (*ServiceInfo) Validate

func (s *ServiceInfo) Validate() bool

type ServiceList

type ServiceList struct {
	Service []string `json:"doms"`
	Count   int      `json:"count"`
}

type ServiceOptions

type ServiceOptions struct {
	// name of service
	ServiceName string
	// group of service
	GroupName string
	// expression of selector
	Expression string
	// protectThreshold of service
	ProtectThreshold float64
	// metadata of service
	Metadata *Metadata
	Selector *Selector
}

ServiceOptions options

type ServiceQueryOptions

type ServiceQueryOptions struct {
	Page        int
	Size        int
	GroupName   string
	ServiceName string
	Selector    Selector
}

ServiceQueryOptions query options

Jump to

Keyboard shortcuts

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