util

package
v0.0.0-...-2acabb3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const RemoteHost = "X-REMOTE-EDGEPROXY"

RemoteHost RemoteHost

View Source
const SCPrefix = "sc_"

SCPrefix SCPrefix

Variables

View Source
var DevZero = io.Reader(devZero(0))

DevZero /dev/zero

Functions

func AESDecrypt

func AESDecrypt(crypt, iv, key []byte) ([]byte, error)

AESDecrypt secret byte to byte

func AESEncrypt

func AESEncrypt(origData, iv, key []byte) ([]byte, error)

AESEncrypt byte to secret byte return data length may be different with input, be careful

func Abs

func Abs(x int) int

Abs returns abs int value

func AppendToIncomingContext

func AppendToIncomingContext(ctx context.Context, k, v string) context.Context

AppendToIncomingContext append `k`, `v` to incoming context

func AppendToOutgoingContext

func AppendToOutgoingContext(ctx context.Context, k, v string) context.Context

AppendToOutgoingContext append `k`, `v` to incoming context

func AppendToOutgoingContextByHeader

func AppendToOutgoingContextByHeader(ctx context.Context, header http.Header) context.Context

AppendToOutgoingContextByHeader AppendToOutgoingContextByHeader

func Assert

func Assert(b bool, v ...interface{})

Assert b, if not, panic and log

func Assertf

func Assertf(b bool, format string, v ...interface{})

Assertf b, if not, panic and log

func Base64Decode

func Base64Decode(input string) ([]byte, error)

Base64Decode is Base64Decode

func Base64Encode

func Base64Encode(input []byte) string

Base64Encode is Base64Encode

func CheckEnvKey

func CheckEnvKey(key string) bool

CheckEnvKey checks the user key of environment variable whether or not is conflict with system Ignore the user one if conflict

func ChkErr

func ChkErr(e error)

ChkErr ChkErr

func Close

func Close(c Closer)

Close is a convenience function to close a object that has a Close() method, ignoring any errors Used to satisfy errcheck lint

func ConvertBoolToInt

func ConvertBoolToInt(b bool) int

ConvertBoolToInt ConvertBoolToInt

func ConvertIntToBool

func ConvertIntToBool(i int) bool

ConvertIntToBool ConvertIntToBool

func ConvertPeerID2SCId

func ConvertPeerID2SCId(peerID string) string

ConvertPeerID2SCId Convert peerID to SC id The convert rule is to remove the prefix "sc_" (if exists) of the peerID to get the scID

func ConvertSCId2PeerID

func ConvertSCId2PeerID(scID string) string

ConvertSCId2PeerID Convert SC id to peerID The convert rule is to add the prefix "sc_" (if exists) of the peerID to the scID

func Decrypt

func Decrypt(cipherText string) (string, error)

Decrypt Decrypt

func Encrypt

func Encrypt(plainText string) (string, error)

Encrypt Encrypt

func FirstOfMonth

func FirstOfMonth() time.Time

FirstOfMonth get the start timestamp of current month

func GetFuncName

func GetFuncName(i interface{}) string

GetFuncName get function name

func GetGOPATHs

func GetGOPATHs() []string

GetGOPATHs returns all paths in GOPATH variable.

func GetInMetadata

func GetInMetadata(ctx context.Context, key string) (string, error)

GetInMetadata returns metadata

func GetOutMetadata

func GetOutMetadata(ctx context.Context, key string) (string, error)

GetOutMetadata return metadata

func GoVersionCompare

func GoVersionCompare(a, b string) (bool, error)

GoVersionCompare returns a bool comparing two strings lexicographically. The result will be false if a < b, and true if a >= b

func HMACSHA1Encrypt

func HMACSHA1Encrypt(origData, key []byte) []byte

HMACSHA1Encrypt encrype data as hmac-sha1

func HeaderFromIncomingContext

func HeaderFromIncomingContext(ctx context.Context) http.Header

HeaderFromIncomingContext HeaderFromIncomingContext

func MD5

func MD5(s string) string

MD5 sum input string's md5

func MaxInt64

func MaxInt64(a, b int64) (c int64)

MaxInt64 return the max(a, b)

func MustParseJSON

func MustParseJSON(v interface{}) (s string)

func PKCS5Padding

func PKCS5Padding(cipherText []byte, blockSize int) []byte

PKCS5Padding is padding byte

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

PKCS5UnPadding is un padding byte

func ParseTimeDuration

func ParseTimeDuration(t string) (time.Duration, error)

ParseTimeDuration parses strings like 1-00:00:00 or 01:23:55

func RandomData

func RandomData(byteNum int) ([]byte, error)

RandomData gen random data len by byte num

func RandomString

func RandomString(strLen int) string

RandomString is get random string

func ReplaceLinuxLineBreak

func ReplaceLinuxLineBreak(input string) string

ReplaceLinuxLineBreak replace the Windows line break character '\n'

func ReplaceWindowsLineBreak

func ReplaceWindowsLineBreak(input string) string

ReplaceWindowsLineBreak replace the Windows line break character '\r'

func SetInMetadata

func SetInMetadata(ctx context.Context, key, value string) context.Context

SetInMetadata SetInMetadata

func SpaceTrimmedSplit

func SpaceTrimmedSplit(s string, sep string) []string

SpaceTrimmedSplit splits a string with a separator It trims white space from all elements in the result array

func TimeTrack

func TimeTrack(start time.Time, ctx string)

TimeTrack measures time consuming

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

Utf8ToGbk encode utf8 strings to gbk

func WaitTimeout

func WaitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool

waitTimeout waits for the waitgroup for the specified max timeout. Returns true if waiting timed out.

Types

type Closer

type Closer interface {
	Close() error
}

Closer Closer

type ErrorArray

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

ErrorArray is lots of error

func (*ErrorArray) Error

func (p *ErrorArray) Error() string

Error Error

type ErrorArrayBuilder

type ErrorArrayBuilder ErrorArray

ErrorArrayBuilder build ErrorArray

func NewErrorArrayBuilder

func NewErrorArrayBuilder() *ErrorArrayBuilder

NewErrorArrayBuilder create ErrorArrayBuilder

func (*ErrorArrayBuilder) Append

func (p *ErrorArrayBuilder) Append(err error) *ErrorArrayBuilder

Append : append a error to ErrorArray

func (*ErrorArrayBuilder) Err

func (p *ErrorArrayBuilder) Err() error

Err : wrap as error

Directories

Path Synopsis
Package snowflake is a generated GoMock package.
Package snowflake is a generated GoMock package.

Jump to

Keyboard shortcuts

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