tools

package module
v0.0.0-...-033bb3f Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

README

tools

A number of frequently used codes. We need to gradually move these codes to the utils repo.

Documentation

Overview

This package contains the tools that frequently used by other packages

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskForConfirmation

func AskForConfirmation(question string) (bool, error)

func GetUserIP

func GetUserIP(req *http.Request) string

func GrpcConnect

func GrpcConnect(addr string, tlsEnabled bool) (*grpc.ClientConn, error)

func HttpGetReqPersist

func HttpGetReqPersist(url string, opts ...ReqOption) ([]byte, error)

func HttpPostReqPersist

func HttpPostReqPersist(url string, payload io.Reader, opts ...ReqOption) ([]byte, error)

func HttpPutReqPersist

func HttpPutReqPersist(url string, payload io.Reader, opts ...ReqOption) ([]byte, error)

func HttpReqPersist

func HttpReqPersist(url string, payload io.Reader, method string, opts ...ReqOption) ([]byte, error)

func IsErrCode

func IsErrCode(err error, code int) bool

func IsErrNotfound

func IsErrNotfound(err error) bool

func IsErrTooManyRequests

func IsErrTooManyRequests(err error) bool

func NewError

func NewError(code int, text string) error

func NewErrorf

func NewErrorf(code int, format string, a ...interface{}) error

func PrettyPrint

func PrettyPrint(v any, prefix ...string)

useful for debugging

func PrintJson

func PrintJson(v any, prefix ...string)

func RandomBool

func RandomBool(chancePercent int) bool

It generates a random boolean status the `chancePercent` should be between 0 and 100

func RandomNumberF

func RandomNumberF(rangeLower float64, rangeUpper float64) float64

This function receives a pair of min and max float64 numbers and generates a random number in that range (inclusive)

func RandomNumberI

func RandomNumberI(rangeLower int64, rangeUpper int64) int64

This function receives a pair of min and max int64 numbers and generates a random number in that range (inclusive)

func RandomString

func RandomString(length int) string

This function receives the length of a string and generates a random string

func ReadAll

func ReadAll(rc io.ReadCloser) ([]byte, error)

func UniqueStringSlice

func UniqueStringSlice(input []string) []string

func WaitCountdown

func WaitCountdown(s time.Duration, msg string)

Types

type ClosingBuffer

type ClosingBuffer struct {
	*bytes.Buffer
}

func (*ClosingBuffer) Close

func (cb *ClosingBuffer) Close() error

type CodeError

type CodeError struct {
	Code int
	Text string
}

CodeError is a error with a code (like 404 Not Found).

func (CodeError) Error

func (e CodeError) Error() string

type ReqOption

type ReqOption interface {
	// contains filtered or unexported methods
}

func HttpAddHeader

func HttpAddHeader(key, value string) ReqOption

func HttpWithRetry

func HttpWithRetry(r uint) ReqOption

func HttpWithTimeout

func HttpWithTimeout(t time.Duration) ReqOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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