util

package
v0.0.0-...-cb472e6 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

* Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License.

* Tencent is pleased to support the open source community by making 蓝鲸 available. * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. * Licensed under the MIT License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * http://opensource.org/licenses/MIT * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddCommonFlags

func AddCommonFlags(cmdline *pflag.FlagSet) *bool

AddCommonFlags add common flags that is needed by all modules

func AddModelBizIDConditon

func AddModelBizIDConditon(cond mapstr.MapStr, modelBizID int64)

AddModelBizIDConditon add model bizID condition according to bizID value

func ArrayUnique

func ArrayUnique(a interface{}) (ret []interface{})

func BoolArrayUnique

func BoolArrayUnique(a []bool) (ret []bool)

func BuildMongoField

func BuildMongoField(key ...string) string

BuildMongoField build mongodb sub item field key

func BuildMongoSyncItemField

func BuildMongoSyncItemField(key string) string

BuildMongoSyncItemField build mongodb sub item synchronize field key

func CCHeader

func CCHeader(header http.Header) http.Header

func CalSliceDiff

func CalSliceDiff(oldSlice, newSlice []string) (subs, plugs []string)

func CalSliceInt64Diff

func CalSliceInt64Diff(oldSlice, newSlice []int64) (subs, inter, plugs []int64)

func CaseInsensitiveContains

func CaseInsensitiveContains(s string, substr string) bool

func CheckLen

func CheckLen(sInput string, min, max int) bool

字符串输入长度

func CloneHeader

func CloneHeader(src http.Header) http.Header

CloneHeader clone http header

func Contains

func Contains(set []string, substr string) bool

Contains if string target in array

func ContainsAnyString

func ContainsAnyString(s string, subs ...string) bool

func ContainsInt

func ContainsInt(set []int64, sub int64) bool

ContainsInt if int target in array

func ContainsInt64

func ContainsInt64(set []int64, sub int64) bool

ContainsInt64 if int64 target in array

func ConvParamsTime

func ConvParamsTime(data interface{}) interface{}

func ConverToInterfaceSlice

func ConverToInterfaceSlice(value interface{}) []interface{}

func CopyHeader

func CopyHeader(src http.Header, target http.Header)

CopyHeader copy http header into target

func CopyMap

func CopyMap(data map[string]interface{}, keys []string, ignores []string) map[string]interface{}

func CountDuration

func CountDuration(f func()) time.Duration

CountDuration count the duration of function f cost

func ExtractOwnerFromContext

func ExtractOwnerFromContext(ctx context.Context) string

func ExtractRequestIDFromContext

func ExtractRequestIDFromContext(ctx context.Context) string

func ExtractRequestUserFromContext

func ExtractRequestUserFromContext(ctx context.Context) string

func FirstNotEmptyString

func FirstNotEmptyString(strs ...string) string

FirstNotEmptyString return the first string in slice strs that is not empty

func FormatPeriod

func FormatPeriod(period string) (string, error)

00002H --> 2H 0000D/0M ---> ∞ empty string / ∞ ---> ∞ regexp matched: positive integer (include positive integer begin with more the one '0') + D/H/M/S eg. 0H, 000H, 0002H, 32M,34S... examples of no matched: 1.4H, -2H, +2H ...

func GenerateRID

func GenerateRID() string

func GetCurrentTimePtr

func GetCurrentTimePtr() *time.Time

func GetCurrentTimeStr

func GetCurrentTimeStr() string

func GetDailAddress

func GetDailAddress(URL string) (string, error)

GetDailAddress returns the address for net.Dail

func GetDefaultCCError

func GetDefaultCCError(header http.Header) errors.DefaultCCErrorIf

func GetFloat64ByInterface

func GetFloat64ByInterface(a interface{}) (float64, error)

func GetHTTPCCRequestID

func GetHTTPCCRequestID(header http.Header) string

GetHTTPCCRequestID return config center request id from http header

func GetInt64ByInterface

func GetInt64ByInterface(a interface{}) (int64, error)

func GetIntByInterface

func GetIntByInterface(a interface{}) (int, error)

func GetLanguage

func GetLanguage(header http.Header) string

func GetMapInterfaceByInerface

func GetMapInterfaceByInerface(data interface{}) ([]interface{}, error)

func GetOwnerID

func GetOwnerID(header http.Header) string

func GetStrByInterface

func GetStrByInterface(a interface{}) string

func GetStrValsFromArrMapInterfaceByKey

func GetStrValsFromArrMapInterfaceByKey(arrI []interface{}, key string) []string

GetStrValsFromArrMapInterfaceByKey get []string from []map[string]interface{}, Do not consider errors

func GetUser

func GetUser(header http.Header) string

func InArray

func InArray(obj interface{}, target interface{}) bool

func InStrArr

func InStrArr(arr []string, key string) bool

func InitFlags

func InitFlags()

InitFlags normalizes and parses the command line flags

func Int64Join

func Int64Join(data []int64, separator string) string

Int64Join []int64 to string

func IntArrIntersection

func IntArrIntersection(slice1 []int64, slice2 []int64) []int64

func IntArrayUnique

func IntArrayUnique(a []int64) (ret []int64)

IntArrayUnique get unique int array

func IsChar

func IsChar(sInput string) bool

是否大、小写字母组合

func IsDate

func IsDate(sInput string) bool

是否日期

func IsInnerObject

func IsInnerObject(objID string) bool

IsInnerObject is inner object model

func IsNumChar

func IsNumChar(sInput string) bool

是否字母、数字组合

func IsNumeric

func IsNumeric(val interface{}) bool

IsNumeric judges if value is a number

func IsStrProperty

func IsStrProperty(propertyType string) bool

IsStrProperty is string property

func IsTime

func IsTime(sInput string) bool

是否时间

func IsTimeZone

func IsTimeZone(sInput string) bool

是否时区

func IsUser

func IsUser(sInput string) bool

是否用户

func MergeMaps

func MergeMaps(maps ...map[string]interface{}) map[string]interface{}

func NewCloserWrapper

func NewCloserWrapper(r io.Reader, closeFunc func() error) io.ReadCloser

func NewContextFromGinContext

func NewContextFromGinContext(c *gin.Context) context.Context

func NewContextFromHTTPHeader

func NewContextFromHTTPHeader(header http.Header) context.Context

func Normalize

func Normalize(str string) string

Normalize to trim space of the str and get it's upper format for example, Normalize(" hello world") ==> "HELLO WORLD"

func PeekRequest

func PeekRequest(req *http.Request) (content []byte, err error)

func PrettyIPStr

func PrettyIPStr(ips []string) string

func RemoveDuplicatesAndEmpty

func RemoveDuplicatesAndEmpty(slice []string) (ret []string)

func SetModOwner

func SetModOwner(condition map[string]interface{}, ownerID string) map[string]interface{}

SetModOwner set condition equal owner id, the condition must be a map or struct

func SetOwnerIDAndAccount

func SetOwnerIDAndAccount(req *restful.Request)

set supplier id and account in head

func SetQueryOwner

func SetQueryOwner(condition map[string]interface{}, ownerID string) map[string]interface{}

SetQueryOwner returns condition that in default ownerID and request ownerID

func SliceInterfaceToBool

func SliceInterfaceToBool(faceSlice []interface{}) ([]bool, error)

SliceInterfaceToBool将interface切片转化为bool切片,且interface的真实类型必须是bool. 失败则返回nil,error.

func SliceInterfaceToInt64

func SliceInterfaceToInt64(faceSlice []interface{}) ([]int64, error)

SliceInterfaceToInt64 将interface切片转化为int64切片,且interface的真实类型可以是任何整数类型. 失败则返回nil,error.

func SliceInterfaceToString

func SliceInterfaceToString(faceSlice []interface{}) ([]string, error)

SliceInterfaceToBool将interface切片转化为string切片,且interface的真实类型必须是string. 失败则返回nil,error.

func SliceStrToInt

func SliceStrToInt(sliceStr []string) ([]int, error)

SliceStrToInt: 将字符串切片转换为整型切片

func SliceStrToInt64

func SliceStrToInt64(sliceStr []string) ([]int64, error)

SliceStrToInt64 将字符串切片转换为整型切片

func SplitStrField

func SplitStrField(str, sep string) []string

SplitStrField split string field, remove empty string

func Str2Time

func Str2Time(timeStr string) time.Time

str2time

func StrArrDiff

func StrArrDiff(slice1 []string, slice2 []string) []string

func StrArrayUnique

func StrArrayUnique(a []string) (ret []string)

StrArrayUnique get unique string array

func ToMillisecond

func ToMillisecond(d time.Duration) float64

func ValidFieldTypeEnumOption

func ValidFieldTypeEnumOption(option interface{}, errProxy errors.DefaultCCErrorIf) error

func ValidFieldTypeIntOption

func ValidFieldTypeIntOption(option interface{}, errProxy errors.DefaultCCErrorIf) error

func ValidFieldTypeListOption

func ValidFieldTypeListOption(option interface{}, errProxy errors.DefaultCCErrorIf) error

func ValidPropertyOption

func ValidPropertyOption(propertyType string, option interface{}, errProxy errors.DefaultCCErrorIf) error

ValidPropertyOption valid property field option

func WordSepNormalizeFunc

func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName

WordSepNormalizeFunc changes all flags that contain "_" separators

Types

type AtomicBool

type AtomicBool int32

func NewBool

func NewBool(yes bool) *AtomicBool

func (*AtomicBool) IsSet

func (b *AtomicBool) IsSet() bool

func (*AtomicBool) Set

func (b *AtomicBool) Set()

func (*AtomicBool) SetIfNotSet

func (b *AtomicBool) SetIfNotSet() bool

func (*AtomicBool) SetTo

func (b *AtomicBool) SetTo(yes bool)

func (*AtomicBool) UnSet

func (b *AtomicBool) UnSet()

type Int64Slice

type Int64Slice []int64

func (Int64Slice) Len

func (p Int64Slice) Len() int

func (Int64Slice) Less

func (p Int64Slice) Less(i, j int) bool

func (Int64Slice) Swap

func (p Int64Slice) Swap(i, j int)

type MapBuilder

type MapBuilder struct {
	// contains filtered or unexported fields
}

func NewMapBuilder

func NewMapBuilder(kvPairs ...interface{}) *MapBuilder

func (*MapBuilder) Append

func (m *MapBuilder) Append(k string, vs ...interface{})

func (*MapBuilder) Build

func (m *MapBuilder) Build() map[string]interface{}

func (*MapBuilder) Delete

func (m *MapBuilder) Delete(k string)

func (*MapBuilder) Set

func (m *MapBuilder) Set(k string, v interface{})

type Ticker

type Ticker struct {
	C chan time.Time
	// contains filtered or unexported fields
}

func NewTicker

func NewTicker(d time.Duration) *Ticker

func (*Ticker) Stop

func (t *Ticker) Stop()

func (*Ticker) Tick

func (t *Ticker) Tick()

Jump to

Keyboard shortcuts

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