model

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LineSeparatorRune = '\x01'
	WordSeparatorRune = '\x02'
)
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"
	ParamPageNo            = "pageNo"
	ParamPageSize          = "pageSize"
	ParamSelector          = "selector"
	ParamTenant            = "tenant"
)
View Source
const (
	DefaultNacosNamespace       = "public"
	DefaultNacosConfigNamespace = ""
	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"
	InternalNacosClientConnectionID      = "internal-nacos-clientconnId"
)
View Source
const (
	HeaderProbeModifyResponseNew = "Probe-Modify-Response-New"
	HeaderProbeModifyResponse    = "Probe-Modify-Response"
	HeaderContent                = "content"
	HeaderCacheControl           = "Cache-Control"
	HeaderPragma                 = "Pragma"
	HeaderExpires                = "Expires"
	HeaderLastModified           = "Last-Modified"
	HeaderContentMD5             = "Content-MD5"
)
View Source
const (
	ActionGetConfigFile         = "NACOS_GET_CONFIG"
	ActionPublishConfigFile     = "NACOS_PUBLISH_CONFIG"
	ActionGrpcGetConfigFile     = "NACOS_GRPC_GET_CONFIG"
	ActionGrpcPublishConfigFile = "NACOS_GRPC_PUBLISH_CONFIG"
	ActionGrpcPushConfigFile    = "NACOS_GRPC_PUSH_CONFIG"
)
View Source
const (
	DefaultListenPort = 8848
)
View Source
const (
	MIME = "application/x-www-form-urlencoded"
)
View Source
const (
	NacosClientAuthHeader = "accessToken"
)
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",
	}
)
View Source
var ConvertPolarisNamespaceVal = "default"
View Source
var (
	InvalidProbeModify = &NacosError{
		ErrCode: int32(http.StatusBadRequest),
		ErrMsg:  "invalid probeModify",
	}
)

Functions

func BuildServiceName

func BuildServiceName(svcName, groupName string) string

func GetGroupName

func GetGroupName(s string) string

GetGroupName 获取 nacos 服务中的 group 名称

func GetServiceName

func GetServiceName(s string) string

GetServiceName 获取 nacos 服务中的 service 名称

func HandleServiceListRequest

func HandleServiceListRequest(discoverSvr service.DiscoverServer, namespace string, groupName string,
	pageNo int, pageSize int) ([]string, int)

func PrepareSpecInstance

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

PrepareSpecInstance nacos instance 转为 polari instance,并填充元数据信息

func ReplaceNacosService

func ReplaceNacosService(service string) string

func ToNacosConfigNamespace

func ToNacosConfigNamespace(ns string) string

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

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"`
}

ClientBeat nacos v1 客户端心跳上报信息

type ConfigFile

type ConfigFile struct {
	ConfigFileBase
	Content          string `param:"content"`
	Tag              string `param:"tag"`
	AppName          string `param:"appName"`
	BetaIps          string `param:"betaIps"`
	CasMd5           string `param:"casMd5"`
	Type             string `param:"type"`
	SrcUser          string `param:"srcUser"`
	Labels           string `param:config_tags`
	Description      string `param:desc`
	EncryptedDataKey string `param:"encryptedDataKey"`
}

func (*ConfigFile) ToDeleteSpec

func (i *ConfigFile) ToDeleteSpec() *config_manage.ConfigFile

func (*ConfigFile) ToQuerySpec

func (i *ConfigFile) ToQuerySpec() *config_manage.ClientConfigFileInfo

func (*ConfigFile) ToSpecConfigFile

func (i *ConfigFile) ToSpecConfigFile() *config_manage.ConfigFilePublishInfo

type ConfigFileBase

type ConfigFileBase struct {
	Namespace string `param:"tenant"`
	Group     string `param:"group"`
	DataId    string `param:"dataId"`
}

type ConfigListenItem

type ConfigListenItem struct {
	Tenant string `json:"tenant"`
	Group  string `json:"group"`
	DataId string `json:"dataId"`
	Md5    string `json:"md5"`
}

func (*ConfigListenItem) Key

func (c *ConfigListenItem) Key() string

type ConfigWatchContext

type ConfigWatchContext struct {
	Request       *restful.Request
	ClientVersion string
	Items         []*ConfigListenItem
}

func ParseConfigListenContext

func ParseConfigListenContext(req *restful.Request, configKeysString string) (*ConfigWatchContext, error)

ParseConfigListenContext parse the transport protocol, which has two formats (W for field delimiter, L for each data delimiter) old: D w G w MD5 l new: D w G w MD5 w T l.

func (*ConfigWatchContext) IsNoHangUp

func (cw *ConfigWatchContext) IsNoHangUp() bool

func (*ConfigWatchContext) IsSupportLongPolling

func (cw *ConfigWatchContext) IsSupportLongPolling() (time.Duration, bool)

func (*ConfigWatchContext) ToSpecWatch

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 []*ServiceMetadata
}

type ResponseCode

type ResponseCode NacosErrorCode

type Service

type Service struct {
	CacheMillis              int64       `json:"cacheMillis"`
	Hosts                    []*Instance `json:"hosts"`
	Checksum                 string      `json:"checksum"`
	LastRefTime              int64       `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
}

func (ServiceKey) String

func (s ServiceKey) String() string

type ServiceMetadata

type ServiceMetadata struct {
	ServiceKey
	ServiceID           string
	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