helper

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHttpClientTimeout = 10 * time.Second
)

Variables

View Source
var HttpClient = (func() *http.Client {
	t := http.DefaultTransport.(*http.Transport).Clone()
	t.MaxIdleConns = 100
	t.MaxConnsPerHost = 100
	t.MaxIdleConnsPerHost = 100
	return &http.Client{Transport: t, Timeout: httpClientTimeout}
})()

自定义http.Client,在原来http.DefaultTransport的基础上进行性能优化 @see https://www.loginradius.com/blog/async/tune-the-go-http-client-for-high-performance

Functions

func BirthdayToAge

func BirthdayToAge(birthday string) (age int)

BirthdayToAge 根据生日算年龄

func Bytes2String

func Bytes2String(b []byte) string

Bytes2String ... @author Cloud|2021-12-12 18:24:20 @param b []byte ... @return string ...

func ClientIP

func ClientIP(ip string) string

func CreateCaptcha

func CreateCaptcha(num int) string

生成指定位数的随机数

func CurrentFileName

func CurrentFileName() string

func CurrentMethodName

func CurrentMethodName() string

func DeepCopy

func DeepCopy(value interface{}) interface{}

深度copy(Map/Slice)

func Difference

func Difference(slice1, slice2 []int) []int

取要校验的和已经校验过的差集,找出需要校验的切片IP(找出slice1中 slice2中没有的)

func DrainBody

func DrainBody(b io.ReadCloser) (r1, r2 io.ReadCloser, err error)

func ExecShell

func ExecShell(name string, arg ...string) ([]byte, error)

阻塞式的执行外部shell命令的函数, 等待执行完毕并返回标准输出

func FileIsExist

func FileIsExist(path string) bool

检查文件是否存在

func FirstDayOfISOWeek

func FirstDayOfISOWeek(year int, week int, timezone *time.Location) time.Time

通过ISOWeek翻转得到周的日期时间 @see https://blog.csdn.net/pingD/article/details/60964306

func GetIPByPconline

func GetIPByPconline(ip string) string

func GetMondayOfWeek

func GetMondayOfWeek(t time.Time, fmtStr string) (dayStr string)

获取本周周一的日期

func GetNextWeekMonday

func GetNextWeekMonday(t time.Time, fmtStr string) (day string, err error)

获取上周周日日期

func GetTimeRemainSeconds

func GetTimeRemainSeconds(startTimeStr, endTimeStr string) int

获取两个时间的秒数差

func GetWeekDay

func GetWeekDay(date string) string

输入日期转周几

func GetZeroTime

func GetZeroTime(t time.Time) time.Time

获取某一天的0点时间

func InArray

func InArray(val interface{}, array interface{}) (exists bool, index int)

判断某一个值是否含在切片之中

func Intersect

func Intersect(slice1 []int, slice2 []int) []int

取两个切片的交集

func IoCopy

func IoCopy(r io.Reader) ([]byte, error)

func MD5

func MD5(str string) string

MD5

func Nl2br

func Nl2br(str string, isXhtml bool) string

Nl2br nl2br() \n\r, \r\n, \r, \n

func NowTime

func NowTime(format ...string) string

NowTime 当前时间 @author Cloud|2021-12-13 09:40:41 @param format ...string ... @return string ...

func PublicIP

func PublicIP() string

func RandFloat64

func RandFloat64(min, max float64, decimalNum int) float64

RandFloat64 区间范围内获取随机数 min 最小值 max float64 最大值 decimalNum int 返回几位小数点

func RandIntn

func RandIntn(max int) int

RandIntn

func RemoveDuplicateWithInt

func RemoveDuplicateWithInt(arr []int) []int

RemoveDuplicateWithInt 去除重复值 @author Cloud|2021-12-12 18:20:52 @param arr []int ... @return []int ...

func RemoveDuplicateWithString

func RemoveDuplicateWithString(arr []string) []string

RemoveDuplicateWithString 去除重复值 @author Cloud|2021-12-13 09:33:05 @param arr []string ... @return []string ...

func RemoveWithInt

func RemoveWithInt(arr []int, in int) []int

RemoveWithInt 删除数组中的指定值 @author Cloud|2021-12-14 12:15:15 @param arr []int ... @param in int ... @return []int ...

func RemoveWithString

func RemoveWithString(arr []string, in string) []string

RemoveWithString 删除数组中的指定值 @author Cloud|2021-12-12 18:20:21 @param arr []string ... @param in string ... @return []string ...

func SafeCloseChan

func SafeCloseChan(ch chan interface{}) (closed bool)

func SafeSendChan

func SafeSendChan(ch chan<- interface{}, value interface{}) (closed bool)

func SortMapByKey

func SortMapByKey(mp map[string]interface{}) string

经典排序返回a=1&b=1

func StrFirstToLower

func StrFirstToLower(str string) string

字符串首字母转成小写

func StrFirstToUpper

func StrFirstToUpper(str string) string

字符串首字母转成大写

func String2Bytes

func String2Bytes(s string) []byte

String2Bytes ... @author Cloud|2021-12-12 18:24:23 @param s string ... @return []byte ...

func Struct2Map

func Struct2Map(obj interface{}) map[string]interface{}

结构体转为map

func SubString

func SubString(str string, begin, length int) string

截取字符串(支持中文)

func SystemIP

func SystemIP() string

func TodayRemainSecond

func TodayRemainSecond() time.Duration

TodayRemainSecond 获取当天剩余的秒数 @author Cloud|2021-12-12 12:49:41 @return time.Duration ...

Types

type Request

type Request struct {
	Method   string
	Url      string
	Timeout  time.Duration
	Headers  map[string]string
	Cookies  map[string]string
	Queries  map[string]string
	PostData map[string]interface{}
	Body     io.Reader
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(url string) *Request

NewRequest

func (*Request) Get

func (r *Request) Get() (*Response, error)

发起get请求

func (*Request) Post

func (r *Request) Post() (*Response, error)

发起post请求

func (*Request) Send

func (r *Request) Send() (*Response, error)

发起请求

func (*Request) SetBody

func (r *Request) SetBody(body io.Reader) *Request

SetBody

func (*Request) SetCookies

func (r *Request) SetCookies(cookies map[string]string) *Request

SetCookies

func (*Request) SetHeaders

func (r *Request) SetHeaders(headers map[string]string) *Request

SetHeaders

func (*Request) SetMethod

func (r *Request) SetMethod(method string) *Request

SetMethod

func (*Request) SetPostData

func (r *Request) SetPostData(postData map[string]interface{}) *Request

SetPostData

func (*Request) SetQueries

func (r *Request) SetQueries(queries map[string]string) *Request

设置url查询参数

func (*Request) SetTimeOut

func (r *Request) SetTimeOut(timeout time.Duration) *Request

SetTimeOut

func (*Request) SetUrl

func (r *Request) SetUrl(url string) *Request

SetUrl

type Response

type Response struct {
	Raw     *http.Response
	Headers map[string]string
	Body    string
}

Response 构造类

func NewResponse

func NewResponse() *Response

func SendMessage

func SendMessage(token, content string, isAtAll bool, timeout time.Duration) (*Response, error)

func (*Response) IsOk

func (r *Response) IsOk() bool

func (*Response) StatusCode

func (r *Response) StatusCode() int

Jump to

Keyboard shortcuts

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