model

package
v0.0.0-...-affc735 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParamCode              = "code"
	ParamServiceName       = "serviceName"
	ParamClusterList       = "clusters"
	ParamCluster           = "cluster"
	ParamClusterName       = "clusterName"
	ParamNamespaceID       = "namespaceId"
	ParamGroupName         = "groupName"
	ParamInstanceIP        = "ip"
	ParamInstancePort      = "port"
	ParamInstanceHealthy   = "healthy"
	ParamInstanceEphemeral = "ephemeral"
	ParamInstanceWeight    = "weight"
	ParamInstanceEnabled   = "enabled"
	ParamInstanceEnable    = "enable"
	ParamInstanceMetadata  = "metadata"
	ParamInstanceBeat      = "beat"
)
View Source
const (
	DefaultNacosNamespace       = "public"
	DefaultServiceGroup         = "DEFAULT_GROUP"
	DefaultServiceClusterName   = "DEFAULT"
	DefaultNacosGroupConnectStr = "@@"
	ReplaceNacosGroupConnectStr = "__"
)
View Source
const (
	InstanceMaxWeight     = float64(1000)
	InstanceMinWeight     = float64(0)
	InstanceDefaultWeight = float64(1)

	ClientBeatIntervalMill = 5000
)
View Source
const (
	InternalNacosCluster                 = "internal-nacos-cluster"
	InternalNacosServiceName             = "internal-nacos-service"
	InternalNacosServiceProtectThreshold = "internal-nacos-protectThreshold"
	InternalNacosServiceType             = "internal-nacos-service"
	InternalNacosClientConnectionID      = "internal-nacos-clientconnId"
)
View Source
const (
	MIME = "application/x-www-form-urlencoded"
)
View Source
const (
	NacosServicesChangeEventTopic = "NacosServicesChangeEvent"
)

Variables

View Source
var (
	/**
	 *  success.
	 */
	ErrorCode_Success = NacosErrorCode{Code: 0, Desc: "success"}

	/**
	 *  parameter missing.
	 */
	ErrorCode_ParameterMissing = NacosErrorCode{Code: 10000, Desc: "parameter missing"}

	/**
	 *  access denied.
	 */
	ErrorCode_AccessDenied = NacosErrorCode{Code: 10001, Desc: "access denied"}

	/**
	 *  data access error.
	 */
	ErrorCode_DataAccessError = NacosErrorCode{Code: 10002, Desc: "data access error"}

	/**
	 *  'tenant' parameter error.
	 */
	ErrorCode_TenantParameterError = NacosErrorCode{Code: 20001, Desc: "'tenant' parameter error"}

	/**
	 *  parameter validate error.
	 */
	ErrorCode_ParameterValidateError = NacosErrorCode{Code: 20002, Desc: "parameter validate error"}

	/**
	 *  MediaType Error.
	 */
	ErrorCode_MediaTypeError = NacosErrorCode{Code: 20003, Desc: "MediaType Error"}

	/**
	 *  resource not found.
	 */
	ErrorCode_ResourceNotFound = NacosErrorCode{Code: 20004, Desc: "resource not found"}

	/**
	 *  resource conflict.
	 */
	ErrorCode_ResourceConflict = NacosErrorCode{Code: 20005, Desc: "resource conflict"}

	/**
	 *  config listener is null.
	 */
	ErrorCode_ConfigListenerIsNull = NacosErrorCode{Code: 20006, Desc: "config listener is null"}

	/**
	 *  config listener error.
	 */
	ErrorCode_ConfigListenerError = NacosErrorCode{Code: 20007, Desc: "config listener error"}

	/**
	 *  invalid dataId.
	 */
	ErrorCode_InvalidDataID = NacosErrorCode{Code: 20008, Desc: "invalid dataId"}

	/**
	 *  parameter mismatch.
	 */
	ErrorCode_ParameterMismatch = NacosErrorCode{Code: 20009, Desc: "parameter mismatch"}

	/**
	 *  service name error.
	 */
	ErrorCode_ServiceNameError = NacosErrorCode{Code: 21000, Desc: "service name error"}

	/**
	 *  weight error.
	 */
	ErrorCode_WeightError = NacosErrorCode{Code: 21001, Desc: "weight error"}

	/**
	 *  instance metadata error.
	 */
	ErrorCode_InstanceMetadataError = NacosErrorCode{Code: 21002, Desc: "instance metadata error"}

	/**
	 *  instance not found.
	 */
	ErrorCode_InstanceNotFound = NacosErrorCode{Code: 21003, Desc: "instance not found"}

	/**
	 *  instance error.
	 */
	ErrorCode_InstanceError = NacosErrorCode{Code: 21004, Desc: "instance error"}

	/**
	 *  service metadata error.
	 */
	ErrorCode_ServiceMetadataError = NacosErrorCode{Code: 21005, Desc: "service metadata error"}

	/**
	 *  selector error.
	 */
	ErrorCode_SelectorError = NacosErrorCode{Code: 21006, Desc: "selector error"}

	/**
	 *  service already exist.
	 */
	ErrorCode_ServiceAlreadyExist = NacosErrorCode{Code: 21007, Desc: "service already exist"}

	/**
	 *  service not exist.
	 */
	ErrorCode_ServiceNotExist = NacosErrorCode{Code: 21008, Desc: "service not exist"}

	/**
	 *  service delete failure.
	 */
	ErrorCode_ServiceDeleteFailure = NacosErrorCode{Code: 21009, Desc: "service delete failure"}

	/**
	 *  healthy param miss.
	 */
	ErrorCode_HealthyParamMiss = NacosErrorCode{Code: 21010, Desc: "healthy param miss"}

	/**
	 *  health check still running.
	 */
	ErrorCode_HealthCheckStillRuning = NacosErrorCode{Code: 21011, Desc: "health check still running"}

	/**
	 *  illegal namespace.
	 */
	ErrorCode_IllegalNamespace = NacosErrorCode{Code: 22000, Desc: "illegal namespace"}

	/**
	 *  namespace not exist.
	 */
	ErrorCode_NamespaceNotExist = NacosErrorCode{Code: 22001, Desc: "namespace not exist"}

	/**
	 *  namespace already exist.
	 */
	ErrorCode_NamespaceAlreadyExist = NacosErrorCode{Code: 22002, Desc: "namespace already exist"}

	/**
	 *  illegal state.
	 */
	ErrorCode_IllegalState = NacosErrorCode{Code: 23000, Desc: "illegal state"}

	/**
	 *  node info error.
	 */
	ErrorCode_NodeInfoError = NacosErrorCode{Code: 23001, Desc: "node info error"}

	/**
	 *  node down failure.
	 */
	ErrorCode_NodeDownFailure = NacosErrorCode{Code: 23001, Desc: "node down failure"}

	/**
	 *  server error.
	 */
	ErrorCode_ServerError = NacosErrorCode{Code: 30000, Desc: "server error"}
)
View Source
var (
	Response_Success = ResponseCode{
		Code: 200,
		Desc: "Response ok",
	}

	Response_Fail = ResponseCode{
		Code: 500,
		Desc: "Response fail",
	}
)

Functions

func BuildServiceName

func BuildServiceName(svcName, groupName string) string

func DefaultString

func DefaultString(s, d string) string

func GetGroupName

func GetGroupName(s string) string

GetGroupName 获取 nacos 服务中的 group 名称

func GetServiceName

func GetServiceName(s string) string

GetServiceName 获取 nacos 服务中的 service 名称

func PrepareSpecInstance

func PrepareSpecInstance(namespace, service string, ins *Instance) *apiservice.Instance

func ReplaceNacosService

func ReplaceNacosService(service string) string

func ToNacosNamespace

func ToNacosNamespace(ns string) string

ToNacosNamespace 替换 polaris namespace 为 nacos 的 namespace 信息,恢复下发 nacos 的数据包信息

func ToPolarisNamespace

func ToPolarisNamespace(ns string) string

ToPolarisNamespace 替换 nacos namespace 为 polaris 的 namespace 信息,主要是针对默认命令空间转为 polaris 的 default

Types

type ClientBeat

type ClientBeat struct {
	Namespace   string            `json:"namespace"`
	ServiceName string            `json:"serviceName"`
	Cluster     string            `json:"cluster"`
	Ip          string            `json:"ip"`
	Port        int               `json:"port"`
	Weight      float64           `json:"weight"`
	Ephemeral   bool              `json:"ephemeral"`
	Metadata    map[string]string `json:"metadata"`
}

func (*ClientBeat) ToSpecInstance

func (c *ClientBeat) ToSpecInstance() (*apiservice.Instance, error)

type ExceptionCode

type ExceptionCode int32
const (
	/**
	 * invalid param(参数错误).
	 */
	ExceptionCode_ClientInvalidParam ExceptionCode = -400

	/**
	 * client disconnect.
	 */
	ExceptionCode_ClientDisconnect ExceptionCode = -401

	/**
	 * over client threshold(超过client端的限流阈值).
	 */
	ExceptionCode_ClientOverThreshold ExceptionCode = -503

	/**
	 * invalid param(参数错误).
	 */
	ExceptionCode_InvalidParam ExceptionCode = 400

	/**
	 * no right(鉴权失败).
	 */
	ExceptionCode_NoRight ExceptionCode = 403

	/**
	 * not found.
	 */
	ExceptionCode_NotFound ExceptionCode = 404

	/**
	 * conflict(写并发冲突).
	 */
	ExceptionCode_Conflict ExceptionCode = 409

	/**
	 * server error(server异常,如超时).
	 */
	ExceptionCode_ServerError ExceptionCode = 500

	/**
	 * client error(client异常,返回给服务端).
	 */
	ExceptionCode_ClientError ExceptionCode = -500

	/**
	 * bad gateway(路由异常,如nginx后面的Server挂掉).
	 */
	ExceptionCode_BadGateway ExceptionCode = 502

	/**
	 * over threshold(超过server端的限流阈值).
	 */
	ExceptionCode_OverThreshold ExceptionCode = 503

	/**
	 * Server is not started.
	 */
	ExceptionCode_InvalidServerStatus ExceptionCode = 300

	/**
	 * Connection is not registered.
	 */
	ExceptionCode_UnRegister ExceptionCode = 301

	/**
	 * No Handler Found.
	 */
	ExceptionCode_NoHandler ExceptionCode = 302

	ExceptionCode_ResourceNotFound ExceptionCode = -404

	/**
	 * http client error code, ome exceptions that occurred when the use the Nacos RestTemplate and Nacos
	 * AsyncRestTemplate.
	 */
	ExceptionCode_HttpClientErrorCode ExceptionCode = -500
)

type Instance

type Instance struct {
	Id          string            `json:"instanceId"`
	IP          string            `json:"ip"`
	Port        int32             `json:"port"`
	Weight      float64           `json:"weight"`
	Healthy     bool              `json:"healthy"`
	Enabled     bool              `json:"enabled"`
	Ephemeral   bool              `json:"ephemeral"`
	ClusterName string            `json:"clusterName"`
	ServiceName string            `json:"serviceName"`
	Metadata    map[string]string `json:"metadata"`
}

func (*Instance) DeepClone

func (i *Instance) DeepClone() *Instance

func (*Instance) FromSpecInstance

func (i *Instance) FromSpecInstance(specIns *model.Instance)

func (*Instance) ToSpecInstance

func (i *Instance) ToSpecInstance() *apiservice.Instance

type NacosApiError

type NacosApiError struct {
	DetailErrCode int32
	ErrAbstract   string
	Err           *NacosError
}

func (*NacosApiError) Error

func (e *NacosApiError) Error() string

type NacosError

type NacosError struct {
	ErrCode  int32
	ErrMsg   string
	CauseErr error
}

func (*NacosError) Error

func (e *NacosError) Error() string

type NacosErrorCode

type NacosErrorCode struct {
	Code int32
	Desc string
}

type NacosServicesChangeEvent

type NacosServicesChangeEvent struct {
	Services []*model.Service
}

type ResponseCode

type ResponseCode NacosErrorCode

type Service

type Service struct {
	CacheMillis              uint64     `json:"cacheMillis"`
	Hosts                    []Instance `json:"hosts"`
	Checksum                 string     `json:"checksum"`
	LastRefTime              uint64     `json:"lastRefTime"`
	Clusters                 string     `json:"clusters"`
	Name                     string     `json:"name"`
	GroupName                string     `json:"groupName"`
	Valid                    bool       `json:"valid"`
	AllIPs                   bool       `json:"allIPs"`
	ReachProtectionThreshold bool       `json:"reachProtectionThreshold"`
}

type ServiceInfo

type ServiceInfo struct {
	Namespace                string      `json:"-"`
	Name                     string      `json:"name"`
	GroupName                string      `json:"groupName"`
	Clusters                 string      `json:"clusters"`
	Hosts                    []*Instance `json:"hosts"`
	Checksum                 string      `json:"checksum"`
	CacheMillis              int64       `json:"cacheMillis"`
	LastRefTime              int64       `json:"lastRefTime"`
	ReachProtectionThreshold bool        `json:"reachProtectionThreshold"`
}

func NewEmptyServiceInfo

func NewEmptyServiceInfo(name, group string) *ServiceInfo

NewEmptyServiceInfo .

type ServiceKey

type ServiceKey struct {
	Namespace string
	Group     string
	Name      string
}

type ServiceMetadata

type ServiceMetadata struct {
	ServiceKey
	Clusters            map[string]struct{}
	ProtectionThreshold float64
	ExtendData          map[string]string
}

type SimpleServiceInfo

type SimpleServiceInfo struct {
	Namespace string
	Name      string `json:"name"`
	GroupName string `json:"groupName"`
}

Jump to

Keyboard shortcuts

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