utils

package
v1.13.4 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 17 Imported by: 15

Documentation

Overview

Package utils contains common utility functions

Index

Constants

View Source
const (
	// QueryDefaultOffset default query offset
	QueryDefaultOffset = 0
	// QueryDefaultLimit default query limit
	QueryDefaultLimit = 100
	// QueryMaxLimit default query max
	QueryMaxLimit = 100
	// MaxBatchSize max batch size
	MaxBatchSize = 100
	// MaxQuerySize max query size
	MaxQuerySize = 100

	// MaxMetadataLength metadata max length
	MaxMetadataLength = 64

	MaxBusinessLength   = 64
	MaxOwnersLength     = 1024
	MaxDepartmentLength = 1024
	MaxCommentLength    = 1024
	MaxNameLength       = 64

	// service表
	MaxDbServiceNameLength      = 128
	MaxDbServiceNamespaceLength = 64
	MaxDbServicePortsLength     = 8192
	MaxDbServiceBusinessLength  = 128
	MaxDbServiceDeptLength      = 1024
	MaxDbServiceCMDBLength      = 1024
	MaxDbServiceCommentLength   = 1024
	MaxDbServiceOwnerLength     = 1024
	MaxDbServiceToken           = 2048

	// instance表
	MaxDbInsHostLength     = 128
	MaxDbInsProtocolLength = 32
	MaxDbInsVersionLength  = 32
	MaxDbInsLogicSetLength = 128

	// circuitbreaker表
	MaxDbCircuitbreakerName       = 32
	MaxDbCircuitbreakerNamespace  = 64
	MaxDbCircuitbreakerBusiness   = 64
	MaxDbCircuitbreakerDepartment = 1024
	MaxDbCircuitbreakerComment    = 1024
	MaxDbCircuitbreakerOwner      = 1024
	MaxDbCircuitbreakerVersion    = 32
)

some options config

View Source
const (
	// ReleaseTypeNormal 发布类型,全量发布
	ReleaseTypeNormal = "normal"
	// ReleaseTypeDelete 发布类型,删除配置文件
	ReleaseTypeDelete = "delete"

	// ReleaseStatusSuccess 发布成功状态
	ReleaseStatusSuccess = "success"
	// ReleaseStatusFail 发布失败状态
	ReleaseStatusFail = "failure"
	// ReleaseStatusToRelease 待发布状态
	ReleaseStatusToRelease = "to-be-released"

	// 文件格式
	FileFormatText       = "text"
	FileFormatYaml       = "yaml"
	FileFormatXml        = "xml"
	FileFormatJson       = "json"
	FileFormatHtml       = "html"
	FileFormatProperties = "properties"

	FileIdSeparator = "+"
)
View Source
const (
	// PolarisCode polaris code
	PolarisCode = "X-Polaris-Code"
	// PolarisMessage polaris message
	PolarisMessage = "X-Polaris-Message"
	// PolarisRequestID request_id
	PolarisRequestID = "Request-Id"
)
View Source
const (
	// HeaderAuthTokenKey auth token key
	HeaderAuthTokenKey string = "X-Polaris-Token"
	// HeaderIsOwnerKey is owner key
	HeaderIsOwnerKey string = "X-Is-Owner"
	// HeaderUserIDKey user id key
	HeaderUserIDKey string = "X-User-ID"
	// HeaderOwnerIDKey owner id key
	HeaderOwnerIDKey string = "X-Owner-ID"
	// HeaderUserRoleKey user role key
	HeaderUserRoleKey string = "X-Polaris-User-Role"

	// ContextAuthTokenKey auth token key
	ContextAuthTokenKey = StringContext(HeaderAuthTokenKey)
	// ContextIsOwnerKey is owner key
	ContextIsOwnerKey = StringContext(HeaderIsOwnerKey)
	// ContextUserIDKey user id key
	ContextUserIDKey = StringContext(HeaderUserIDKey)
	// ContextOwnerIDKey owner id key
	ContextOwnerIDKey = StringContext(HeaderOwnerIDKey)
	// ContextUserRoleIDKey user role key
	ContextUserRoleIDKey = StringContext(HeaderUserRoleKey)
	// ContextAuthContextKey auth context key
	ContextAuthContextKey = StringContext("X-Polaris-AuthContext")
	// ContextUserNameKey users name key
	ContextUserNameKey = StringContext("X-User-Name")
	// ContextClientAddress client address key
	ContextClientAddress = StringContext("client-address")
	// ContextOpenAsyncRegis open async register key
	ContextOpenAsyncRegis = StringContext("client-asyncRegis")
	// ContextGrpcHeader grpc header key
	ContextGrpcHeader = StringContext("grpc-header")
)
View Source
const (
	// EmptyErrString empty error string
	EmptyErrString = "empty"
	// NilErrString null pointer error string
	NilErrString = "nil"
)

Variables

View Source
var (
	// LocalHost local host
	LocalHost = "127.0.0.1"
)

Functions

func CalculateInstanceID

func CalculateInstanceID(namespace string, service string, vpcID string, host string, port uint32) (string, error)

CalculateInstanceID 计算实例ID

func CalculateRuleID

func CalculateRuleID(name, namespace string) string

CalculateRuleID 计算规则ID

func CheckDbMetaDataFieldLen

func CheckDbMetaDataFieldLen(metaData map[string]string) error

CheckDbMetaDataFieldLen 检查metadata的K,V是否超过DB中对应字段的最大字符长度限制

func CheckDbStrFieldLen

func CheckDbStrFieldLen(param *wrappers.StringValue, dbLen int) error

CheckDbStrFieldLen 检查name字段是否超过DB中对应字段的最大字符长度限制

func CheckInstanceHost

func CheckInstanceHost(host *wrappers.StringValue) error

CheckInstanceHost 检查服务实例Host

func CheckInstancePort

func CheckInstancePort(port *wrappers.UInt32Value) error

CheckInstancePort 检查服务实例Port

func CheckInstanceTetrad

func CheckInstanceTetrad(req *api.Instance) (string, *api.Response)

CheckInstanceTetrad 根据服务实例四元组计算ID

func CheckMetadata

func CheckMetadata(meta map[string]string) error

CheckMetadata check metadata 检查metadata的个数 最大是64个 key/value是否符合要求

func CheckQueryLimit

func CheckQueryLimit(limit []string) (int, error)

CheckQueryLimit 检查查询参数Limit

func CheckQueryOffset

func CheckQueryOffset(offset []string) (int, error)

CheckQueryOffset 检查查询参数Offset

func CheckResourceName

func CheckResourceName(name *wrappers.StringValue) error

CheckResourceName 检查资源Name

func CheckResourceOwners

func CheckResourceOwners(owners *wrappers.StringValue) error

CheckResourceOwners 检查资源Owners

func CollectMapKeys

func CollectMapKeys(filters map[string]string) []string

CollectMapKeys collect filters key to slice

func ConvertFilter

func ConvertFilter(filters map[string]string) map[string][]string

ConvertFilter map[string]string to map[string][]string

func ConvertStringValuesToSlice

func ConvertStringValuesToSlice(vals []*wrapperspb.StringValue) []string

ConvertStringValuesToSlice 转换StringValues为字符串切片

func GenFileId

func GenFileId(namespace, group, fileName string) string

GenFileId 生成文件 Id

func IsWildName

func IsWildName(name string) bool

IsWildName 判断名字是否为通配名字,只支持前缀索引(名字最后为*)

func NewBoolValue

func NewBoolValue(value bool) *wrappers.BoolValue

NewBoolValue returns a new BoolValue with the given value.

func NewRoutingV2UUID

func NewRoutingV2UUID() string

NewUUID 返回一个随机的UUID

func NewStringValue

func NewStringValue(value string) *wrappers.StringValue

NewStringValue returns a new StringValue with the given value.

func NewUInt32Value

func NewUInt32Value(value uint32) *wrappers.UInt32Value

NewUInt32Value returns a new UInt32Value with the given value.

func NewUInt64Value

func NewUInt64Value(value uint64) *wrappers.UInt64Value

NewUInt64Value returns a new UInt64Value with the given value.

func NewUUID

func NewUUID() string

NewUUID 返回一个随机的UUID

func NewV2Revision

func NewV2Revision() string

NewV2Revision 返回一个随机的UUID

func ParseAuthToken

func ParseAuthToken(ctx context.Context) string

ParseAuthToken 从ctx中获取token

func ParseClientAddress

func ParseClientAddress(ctx context.Context) string

ParseClientAddress 从ctx中获取客户端地址

func ParseFileId

func ParseFileId(fileId string) (namespace, group, fileName string)

ParseFileId 解析文件 Id

func ParseInstanceArgs

func ParseInstanceArgs(query map[string]string) (*store.InstanceArgs, error)

ParseInstanceArgs 解析服务实例的 ip 和 port 查询参数

func ParseIsOwner

func ParseIsOwner(ctx context.Context) bool

ParseIsOwner 从ctx中获取token

func ParseOffsetAndLimit

func ParseOffsetAndLimit(query map[string]string) (uint32, uint32, error)

ParseOffsetAndLimit 统一格式化处理Offset和limit参数

func ParseOperator

func ParseOperator(ctx context.Context) string

ParseOperator 从ctx中获取operator

func ParseOwnerID

func ParseOwnerID(ctx context.Context) string

ParseOwnerID 从ctx解析Owner ID

func ParsePlatformID

func ParsePlatformID(ctx context.Context) string

ParsePlatformID 从ctx中获取Platform-Id

func ParsePlatformToken

func ParsePlatformToken(ctx context.Context) string

ParsePlatformToken 从ctx中获取Platform-Token

func ParseQueryLimit

func ParseQueryLimit(limit string) (uint32, error)

ParseQueryLimit 格式化处理limit参数

func ParseQueryOffset

func ParseQueryOffset(offset string) (uint32, error)

ParseQueryOffset 格式化处理offset参数

func ParseRequestID

func ParseRequestID(ctx context.Context) string

ParseRequestID 从ctx中获取Request-ID

func ParseToken

func ParseToken(ctx context.Context) string

ParseToken 从ctx中获取token

func ParseUserID

func ParseUserID(ctx context.Context) string

ParseUserID 从ctx中解析用户ID

func ParseUserName

func ParseUserName(ctx context.Context) string

ParseUserName 从ctx解析用户名称

func ParseWildName

func ParseWildName(name string) (string, bool)

ParseWildName 判断是否为格式化查询条件并且返回真正的查询信息

func StringSliceDeDuplication

func StringSliceDeDuplication(s []string) []string

StringSliceDeDuplication 字符切片去重

func ValueLocalhost

func ValueLocalhost(ctx context.Context) string

ValueLocalhost 获取localhost

func WithLocalhost

func WithLocalhost(ctx context.Context, localhost string) context.Context

WithLocalhost 存储localhost

func ZapInstanceID

func ZapInstanceID(id string) zap.Field

ZapInstanceID 生成instanceID的日志描述

func ZapPlatformID

func ZapPlatformID(id string) zap.Field

ZapPlatformID 生成Platform-ID的日志描述

func ZapRequestID

func ZapRequestID(id string) zap.Field

ZapRequestID 生成Request-ID的日志描述

func ZapRequestIDByCtx

func ZapRequestIDByCtx(ctx context.Context) zap.Field

ZapRequestIDByCtx 从ctx中获取Request-ID

Types

type StringContext

type StringContext string

StringContext is a context key that carries a string.

type StringSet

type StringSet interface {
	Add(val string)

	Remove(val string)

	ToSlice() []string

	Range(func(val string) bool)
}

StringSet is a set of strings

func NewStringSet

func NewStringSet() StringSet

NewStringSet returns a new StringSet

Jump to

Keyboard shortcuts

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