Documentation ¶
Overview ¶
Package utils contains common utility functions
Index ¶
- Constants
- Variables
- func CalculateInstanceID(namespace string, service string, vpcID string, host string, port uint32) (string, error)
- func CalculateRuleID(name, namespace string) string
- func CheckDbMetaDataFieldLen(metaData map[string]string) error
- func CheckDbStrFieldLen(param *wrappers.StringValue, dbLen int) error
- func CheckInstanceHost(host *wrappers.StringValue) error
- func CheckInstancePort(port *wrappers.UInt32Value) error
- func CheckInstanceTetrad(req *api.Instance) (string, *api.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 ConvertStringValuesToSlice(vals []*wrapperspb.StringValue) []string
- func GenFileId(namespace, group, fileName string) string
- func IsWildName(name string) bool
- 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 ParseFileId(fileId string) (namespace, group, fileName string)
- func ParseInstanceArgs(query map[string]string) (*store.InstanceArgs, error)
- 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 StringSliceDeDuplication(s []string) []string
- func ValueLocalhost(ctx context.Context) string
- func WithLocalhost(ctx context.Context, localhost string) context.Context
- func ZapInstanceID(id string) zap.Field
- func ZapPlatformID(id string) zap.Field
- func ZapRequestID(id string) zap.Field
- func ZapRequestIDByCtx(ctx context.Context) zap.Field
- type StringContext
- type StringSet
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" // 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 = "+" )
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") )
const ( // EmptyErrString empty error string EmptyErrString = "empty" // NilErrString null pointer error string NilErrString = "nil" )
Variables ¶
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 CheckDbMetaDataFieldLen ¶
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 ¶
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 ConvertStringValuesToSlice ¶
func ConvertStringValuesToSlice(vals []*wrapperspb.StringValue) []string
ConvertStringValuesToSlice 转换StringValues为字符串切片
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 ParseFileId ¶
ParseFileId 解析文件 Id
func ParseInstanceArgs ¶
func ParseInstanceArgs(query map[string]string) (*store.InstanceArgs, error)
ParseInstanceArgs 解析服务实例的 ip 和 port 查询参数
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 StringSliceDeDuplication ¶
StringSliceDeDuplication 字符切片去重
func WithLocalhost ¶
WithLocalhost 存储localhost
Types ¶
type StringContext ¶
type StringContext string
StringContext is a context key that carries a string.