common

package module
v0.0.0-...-adfb5ab Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	E_timeout = errors.New("request_timeout")
)

Functions

func CheckFor

func CheckFor(app string) error

func Chunk

func Chunk(slices []string, chunkSize int) (chunks [][]string)

func ChunkInt32

func ChunkInt32(slices []int32, chunkSize int) (chunks [][]int32)

func ChunkInt64

func ChunkInt64(slices []int64, chunkSize int) (chunks [][]int64)

func ContextValue

func ContextValue(ctx context.Context, out proto.Message) error

ContextValue func

func CreateZipWithPasswordFromFile

func CreateZipWithPasswordFromFile(password, zipPath, filename string) error

zip -P password F.zip F

func CreateZipWithPasswordFromFolder

func CreateZipWithPasswordFromFolder(password, zipPath, folder string) error

zip -P password -r F.zip F

func Err

func Err(code codes.Code, msg string) error

func Hash

func Hash(keys ...interface{}) string

Hash using sha1 to encoding

func HashRecord

func HashRecord(items ...interface{}) string

func I32Contains

func I32Contains(s []int32, e int32) bool

func I64Contains

func I64Contains(s []int64, e int64) bool

func IntContains

func IntContains(s []int, e int) bool

func MakeContext

func MakeContext(sec int, claims proto.Message) (context.Context, context.CancelFunc)

func MergeStructs

func MergeStructs(in ...interface{}) (map[string]interface{}, error)

func ParseContext

func ParseContext(ctx context.Context, out proto.Message) error

ParseContext func is new method replace ContextValue high performance, using smaller resource replace json marshall to proto marshall can support older

func RandStringRunes

func RandStringRunes(n int) string

func SendReqGet deprecated

func SendReqGet(url string, headers map[string]string, opts ...HttpOption) (int, []byte, error)

Deprecated: SendReqGet send http get

move to example

code, body, err := httpclient.New(url).WithMethod("GET").WithHeader(map[string]string{
	"content-type": "application/json",
}),

WithTimeout(time.Second)

func SendReqPost deprecated

func SendReqPost(url string, headers map[string]string, body []byte, opts ...HttpOption) (int, []byte, error)

Deprecated: SendReqPost send http post

move to example
code, body, err := httpclient.New(url).WithMethod("POST").WithHeader(map[string]string{
	"content-type": "application/json",
}),

WithTimeout(time.Second),

WithBody(map[string]any{
	"userId": 1,
	"id":     1,
	"title":  "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
}))

func SendReqPostWithRetry

func SendReqPostWithRetry(url string, headers map[string]string, body []byte, opts ...HttpOption) (int, []byte, error)

SendReqPostWithRetry send http post

func SendReqPut deprecated

func SendReqPut(url string, headers map[string]string, body []byte, opts ...HttpOption) (int, []byte, error)

Deprecated: SendReqPut send http put

move to example

code, body, err := httpclient.New(url).WithMethod("PUT").WithHeader(map[string]string{
	"content-type": "application/json",
}),

WithTimeout(time.Second),

WithBody(map[string]any{
	"userId": 1,
	"id":     1,
	"title":  "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
}))

func StrContains

func StrContains(s []string, e string) bool

func ToMs

func ToMs(timestamp int64) int64

ToMs convert time to milisecond

func ToNs

func ToNs(timestamp int64) int64

ToNs convert time to nanosecond

func UniqInt32

func UniqInt32(intSlice []int32) []int32

func UniqInt64

func UniqInt64(intSlice []int64) []int64

func ZipExtract

func ZipExtract(password, zipPath string) error

unzip -P your-password zipfile.zip

Types

type HttpOption

type HttpOption struct {
	Timeout time.Duration
}

type Retry

type Retry struct {
	http.RoundTripper
}

Retry - http client with retry support

func (*Retry) RoundTrip

func (r *Retry) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip Naive Retry - every 2 seconds

Jump to

Keyboard shortcuts

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