Documentation ¶
Overview ¶
Package utils contains common utility functions
Index ¶
- Constants
- Variables
- func BoolPtr(v bool) *bool
- func CalculateInstanceID(namespace string, service string, vpcID string, host string, port uint32) (string, error)
- func CalculateRuleID(name, namespace string) string
- func CheckContractInterfaceTetrad(contractId string, source apiservice.InterfaceDescriptor_Source, ...) (string, *apiservice.Response)
- func CheckContractTetrad(req *apiservice.ServiceContract) (string, *apiservice.Response)
- func CheckDbMetaDataFieldLen(metaData map[string]string) error
- func CheckDbRawStrFieldLen(param string, dbLen int) error
- func CheckDbStrFieldLen(param *wrappers.StringValue, dbLen int) error
- func CheckInstanceHost(host *wrappers.StringValue) error
- func CheckInstancePort(port *wrappers.UInt32Value) error
- func CheckInstanceTetrad(req *apiservice.Instance) (string, *apiservice.Response)
- func CheckMetadata(meta map[string]string) error
- func CheckQueryLimit(limit []string) (int, error)
- func CheckQueryOffset(offset []string) (int, error)
- func CheckResourceName(name *wrappers.StringValue) error
- func CheckResourceOwners(owners *wrappers.StringValue) error
- func CollectMapKeys(filters map[string]string) []string
- func ConvertFilter(filters map[string]string) map[string][]string
- func ConvertGRPCContext(ctx context.Context) context.Context
- func ConvertStringValuesToSlice(vals []*wrapperspb.StringValue) []string
- func DefaultString(v, d string) string
- func GenFileId(namespace, group, fileName string) string
- func GetUnexportedField(field reflect.Value) interface{}
- func IsMatchAll(v string) bool
- func IsNotEqualMap(req map[string]string, old map[string]string) bool
- func IsPrefixWildName(name string) bool
- func IsSuffixWildName(name string) bool
- func IsWildMatch(name, pattern string) bool
- func IsWildMatchIgnoreCase(name, pattern string) bool
- func IsWildName(name string) bool
- func IsWildNotMatch(name, pattern string) bool
- func MarshalToJsonString(message proto.Message) (string, error)
- func MatchString(srcMetaValue string, matchValule *apimodel.MatchString, ...) bool
- func MustJson(v interface{}) string
- func NewBoolValue(value bool) *wrappers.BoolValue
- func NewRoutingV2UUID() string
- func NewStringValue(value string) *wrappers.StringValue
- func NewUInt32Value(value uint32) *wrappers.UInt32Value
- func NewUInt64Value(value uint64) *wrappers.UInt64Value
- func NewUUID() string
- func NewV2Revision() string
- func ParseAuthToken(ctx context.Context) string
- func ParseClientAddress(ctx context.Context) string
- func ParseClientIP(ctx context.Context) string
- func ParseFileId(fileId string) (namespace, group, fileName string)
- func ParseIsOwner(ctx context.Context) bool
- func ParseOffsetAndLimit(query map[string]string) (uint32, uint32, error)
- func ParseOperator(ctx context.Context) string
- func ParseOwnerID(ctx context.Context) string
- func ParsePlatformID(ctx context.Context) string
- func ParsePlatformToken(ctx context.Context) string
- func ParseQueryLimit(limit string) (uint32, error)
- func ParseQueryOffset(offset string) (uint32, error)
- func ParseRequestID(ctx context.Context) string
- func ParseToken(ctx context.Context) string
- func ParseUserID(ctx context.Context) string
- func ParseUserName(ctx context.Context) string
- func ParseWildName(name string) (string, bool)
- func ParseWildNameForSql(name string) string
- func RequestID(ctx context.Context) zap.Field
- func SetUnexportedField(field reflect.Value, value interface{})
- func StringSliceDeDuplication(s []string) []string
- func UnmarshalFromJsonString(message proto.Message, text string) error
- func ValueLocalhost(ctx context.Context) string
- func WithLocalhost(ctx context.Context, localhost string) context.Context
- func ZapFileName(fileName string) zap.Field
- func ZapGroup(group string) zap.Field
- func ZapInstanceID(id string) zap.Field
- func ZapNamespace(namespace string) zap.Field
- func ZapPlatformID(id string) zap.Field
- func ZapReleaseName(fileName string) zap.Field
- func ZapRequestID(id string) zap.Field
- type AtomicValue
- type ConfigFileMeta
- type ContextAPIServerSlot
- type Map
- type SegmentMap
- func (s *SegmentMap[K, V]) ComputeIfAbsent(k K, supplier func(k K) V) (V, bool)
- func (s *SegmentMap[K, V]) Count() uint64
- func (s *SegmentMap[K, V]) Del(k K) bool
- func (s *SegmentMap[K, V]) Get(k K) (V, bool)
- func (s *SegmentMap[K, V]) Put(k K, v V)
- func (s *SegmentMap[K, V]) PutIfAbsent(k K, v V) (V, bool)
- func (s *SegmentMap[K, V]) Range(f func(k K, v V))
- type Set
- type StringContext
- type SyncMap
- func (s *SyncMap[K, V]) ComputeIfAbsent(k K, supplier func(k K) V) (V, bool)
- func (s *SyncMap[K, V]) Delete(key K) (V, bool)
- func (s *SyncMap[K, V]) Len() int
- func (s *SyncMap[K, V]) Load(key K) (V, bool)
- func (s *SyncMap[K, V]) Range(f func(key K, val V))
- func (s *SyncMap[K, V]) ReadRange(f func(key K, val V))
- func (s *SyncMap[K, V]) Store(key K, val V)
- func (s *SyncMap[K, V]) ToMap() map[K]V
- func (s *SyncMap[K, V]) Values() []V
- type SyncSet
- type WatchTimeoutCtx
Constants ¶
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
const ( // ReleaseTypeNormal 发布类型,全量发布 ReleaseTypeNormal = "normal" // ReleaseTypeGray 灰度发布 ReleaseTypeGray = "betaing" // ReleaseTypeCancelGray 取消灰度发布 ReleaseTypeCancelGray = "cancel-gray" // ReleaseTypeDelete 发布类型,删除配置发布 ReleaseTypeDelete = "delete" // ReleaseTypeRollback 发布类型 回滚 ReleaseTypeRollback = "rollback" // ReleaseTypeClean 发布类型,清空配置发布 ReleaseTypeClean = "clean" // ReleaseStatusSuccess 发布成功状态 ReleaseStatusSuccess = "success" // ReleaseStatusFail 发布失败状态 ReleaseStatusFail = "failure" // ReleaseStatusToRelease 待发布状态 ReleaseStatusToRelease = "to-be-released" // 文件格式 FileFormatText = "text" FileFormatYaml = "yaml" FileFormatXml = "xml" FileFormatJson = "json" FileFormatHtml = "html" FileFormatProperties = "properties" FileIdSeparator = "+" // MaxRequestBodySize 导入配置文件请求体最大 4M MaxRequestBodySize = 4 * 1024 * 1024 // ConfigFileFormKey 配置文件表单键 ConfigFileFormKey = "config" // ConfigFileMetaFileName 配置文件元数据文件名 ConfigFileMetaFileName = "META" // ConfigFileImportConflictSkip 导入配置文件发生冲突跳过 ConfigFileImportConflictSkip = "skip" // ConfigFileImportConflictOverwrite 导入配置文件发生冲突覆盖原配置文件 ConfigFileImportConflictOverwrite = "overwrite" )
const ( // PolarisCode polaris code PolarisCode = "X-Polaris-Code" // PolarisMessage polaris message PolarisMessage = "X-Polaris-Message" // PolarisRequestID request_id PolarisRequestID = "Request-Id" )
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") // ContextIsFromClient is from client ContextIsFromClient = StringContext("from-client") // ContextIsFromSystem is from polaris system ContextIsFromSystem = StringContext("from-system") // ContextOperator operator info ContextOperator = StringContext("operator") )
const ( // EmptyErrString empty error string EmptyErrString = "empty" // NilErrString null pointer error string NilErrString = "nil" // MatchAll rule match all service or namespace value MatchAll = "*" )
Variables ¶
var ( // LocalHost local host LocalHost = "127.0.0.1" // LocalPort default listen port LocalPort = 8091 // ConfDir default config dir ConfDir = "conf/" )
Functions ¶
func CalculateInstanceID ¶
func CalculateInstanceID(namespace string, service string, vpcID string, host string, port uint32) (string, error)
CalculateInstanceID 计算实例ID
func CheckContractInterfaceTetrad ¶ added in v1.18.0
func CheckContractInterfaceTetrad(contractId string, source apiservice.InterfaceDescriptor_Source, req *apiservice.InterfaceDescriptor) (string, *apiservice.Response)
func CheckContractTetrad ¶ added in v1.18.0
func CheckContractTetrad(req *apiservice.ServiceContract) (string, *apiservice.Response)
CheckContractTetrad 根据服务实例四元组计算ID
func CheckDbMetaDataFieldLen ¶
CheckDbMetaDataFieldLen 检查metadata的K,V是否超过DB中对应字段的最大字符长度限制
func CheckDbRawStrFieldLen ¶ added in v1.14.0
CheckDbRawStrFieldLen 检查name字段是否超过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 *apiservice.Instance) (string, *apiservice.Response)
CheckInstanceTetrad 根据服务实例四元组计算ID
func CheckMetadata ¶
CheckMetadata check metadata 检查metadata的个数 最大是64个 key/value是否符合要求
func CheckQueryLimit ¶
CheckQueryLimit 检查查询参数Limit
func CheckQueryOffset ¶
CheckQueryOffset 检查查询参数Offset
func CheckResourceName ¶
func CheckResourceName(name *wrappers.StringValue) error
CheckResourceName 检查资源Name
func CheckResourceOwners ¶
func CheckResourceOwners(owners *wrappers.StringValue) error
CheckResourceOwners 检查资源Owners
func CollectMapKeys ¶
CollectMapKeys collect filters key to slice
func ConvertFilter ¶
ConvertFilter map[string]string to map[string][]string
func ConvertGRPCContext ¶ added in v1.18.0
ConvertGRPCContext 将GRPC上下文转换成内部上下文
func ConvertStringValuesToSlice ¶
func ConvertStringValuesToSlice(vals []*wrapperspb.StringValue) []string
ConvertStringValuesToSlice 转换StringValues为字符串切片
func DefaultString ¶ added in v1.18.0
func GetUnexportedField ¶ added in v1.18.0
func IsMatchAll ¶ added in v1.18.0
func IsNotEqualMap ¶ added in v1.17.3
IsNotEqualMap metadata need update
func IsPrefixWildName ¶ added in v1.16.0
IsPrefixWildName 判断名字是否为通配名字,只支持前缀索引(名字最后为*)
func IsSuffixWildName ¶ added in v1.16.0
IsSuffixWildName 判断名字是否为通配名字,只支持后缀索引(名字第一个字符为*)
func IsWildMatch ¶ added in v1.16.0
IsWildMatch 判断 name 是否匹配 pattern,pattern 可以是前缀或者后缀
func IsWildMatchIgnoreCase ¶ added in v1.16.0
IsWildMatchIgnoreCase 判断 name 是否匹配 pattern,pattern 可以是前缀或者后缀,忽略大小写
func IsWildNotMatch ¶ added in v1.17.3
IsWildNotMatch .
func MarshalToJsonString ¶ added in v1.14.0
MarshalToJsonString marshal json message to string
func MatchString ¶ added in v1.18.0
func NewBoolValue ¶
NewBoolValue returns a new BoolValue with the given value.
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 ParseClientAddress ¶
ParseClientAddress 从ctx中获取客户端地址
func ParseClientIP ¶ added in v1.18.0
ParseClientIP .
func ParseFileId ¶
ParseFileId 解析文件 Id
func ParseOffsetAndLimit ¶
ParseOffsetAndLimit 统一格式化处理Offset和limit参数
func ParsePlatformID ¶
ParsePlatformID 从ctx中获取Platform-Id
func ParsePlatformToken ¶
ParsePlatformToken 从ctx中获取Platform-Token
func ParseQueryLimit ¶
ParseQueryLimit 格式化处理limit参数
func ParseQueryOffset ¶
ParseQueryOffset 格式化处理offset参数
func ParseRequestID ¶
ParseRequestID 从ctx中获取Request-ID
func ParseWildName ¶
ParseWildName 判断是否为格式化查询条件并且返回真正的查询信息
func ParseWildNameForSql ¶ added in v1.16.0
ParseWildNameForSql 如果 name 是通配字符串,将通配字符*替换为sql中的%
func SetUnexportedField ¶ added in v1.18.0
func StringSliceDeDuplication ¶
StringSliceDeDuplication 字符切片去重
func UnmarshalFromJsonString ¶ added in v1.14.0
UnmarshalFromJsonString unmarshal message from json string
func WithLocalhost ¶
WithLocalhost 存储localhost
func ZapFileName ¶ added in v1.17.2
ZapFileName 生成fileName的日志描述
func ZapNamespace ¶ added in v1.17.2
ZapNamespace 生成namespace的日志描述
func ZapReleaseName ¶ added in v1.17.3
ZapReleaseName 生成fileName的日志描述
Types ¶
type AtomicValue ¶ added in v1.17.3
type AtomicValue[V any] struct { // contains filtered or unexported fields }
func NewAtomicValue ¶ added in v1.17.3
func NewAtomicValue[V any](v V) *AtomicValue[V]
func (*AtomicValue[V]) Load ¶ added in v1.17.3
func (a *AtomicValue[V]) Load() V
func (*AtomicValue[V]) Store ¶ added in v1.17.3
func (a *AtomicValue[V]) Store(val V)
type ConfigFileMeta ¶ added in v1.15.0
ConfigFileMeta 导入配置文件ZIP包中的元数据结构
type ContextAPIServerSlot ¶ added in v1.18.0
type ContextAPIServerSlot struct{}
ContextAPIServerSlot
type Map ¶ added in v1.17.3
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map
type SegmentMap ¶ added in v1.17.0
type SegmentMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewSegmentMap ¶ added in v1.17.0
func NewSegmentMap[K comparable, V any](soltNum int, hashFunc func(k K) int) *SegmentMap[K, V]
func (*SegmentMap[K, V]) ComputeIfAbsent ¶ added in v1.17.3
func (s *SegmentMap[K, V]) ComputeIfAbsent(k K, supplier func(k K) V) (V, bool)
func (*SegmentMap[K, V]) Count ¶ added in v1.17.0
func (s *SegmentMap[K, V]) Count() uint64
func (*SegmentMap[K, V]) Del ¶ added in v1.17.0
func (s *SegmentMap[K, V]) Del(k K) bool
func (*SegmentMap[K, V]) Get ¶ added in v1.17.0
func (s *SegmentMap[K, V]) Get(k K) (V, bool)
func (*SegmentMap[K, V]) Put ¶ added in v1.17.0
func (s *SegmentMap[K, V]) Put(k K, v V)
func (*SegmentMap[K, V]) PutIfAbsent ¶ added in v1.17.0
func (s *SegmentMap[K, V]) PutIfAbsent(k K, v V) (V, bool)
func (*SegmentMap[K, V]) Range ¶ added in v1.17.0
func (s *SegmentMap[K, V]) Range(f func(k K, v V))
type Set ¶ added in v1.17.3
type Set[K comparable] struct { // contains filtered or unexported fields }
type StringContext ¶
type StringContext string
StringContext is a context key that carries a string.
type SyncMap ¶ added in v1.17.3
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
SyncMap
func (*SyncMap[K, V]) ComputeIfAbsent ¶ added in v1.17.3
ComputeIfAbsent
func (*SyncMap[K, V]) Range ¶ added in v1.17.3
func (s *SyncMap[K, V]) Range(f func(key K, val V))
Range
type SyncSet ¶ added in v1.17.3
type SyncSet[K comparable] struct { // contains filtered or unexported fields }
func NewSyncSet ¶ added in v1.17.3
func NewSyncSet[K comparable]() *SyncSet[K]
NewSyncSet returns a new Set
func (*SyncSet[K]) Add ¶ added in v1.17.3
func (set *SyncSet[K]) Add(val K)
Add adds a string to the set