tool

package
v0.0.0-...-c6e1f3d Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(cip string) (ip string)

ClientIP

func DeepCopy

func DeepCopy(value interface{}) interface{}

Map / Slice 深度copy

func DrainBody

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

DrainBody

func ExecShell

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

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

func FileIsExist

func FileIsExist(path string) bool

检查文件是否存在

func GetIPByPconline

func GetIPByPconline(ip string) string

GetIPByPconline

func Graceful

func Graceful(srv *http.Server, zl *zap.Logger, timeout time.Duration)

func HttpRequestWithSign

func HttpRequestWithSign(url string, data map[string]interface{}, params ...interface{}) string

带签名http请求

func InArray

func InArray(needle interface{}, haystack interface{}) bool

InArray in_array() haystack supported types: slice, array or map

func MD5

func MD5(str string) string

MD5

func NewGoCurl

func NewGoCurl() *goCurl

func NewSafeGo

func NewSafeGo() *panicGroup

func Nl2br

func Nl2br(str string, isXhtml bool) string

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

func NowMemStats

func NowMemStats() string

NowMemStats

func PhpSerialize

func PhpSerialize(vars map[string]interface{}) (str string)

PhpSerialize

func PhpUnserialize

func PhpUnserialize(str string) map[string]interface{}

PhpUnserialize

func PublicIP

func PublicIP() (ip string)

PublicIP

func PushContextMessage

func PushContextMessage(ctx *gin.Context, msg string, reqStr string, stack string, isAtAll bool)

PushContextMessage

func PushSimpleMessage

func PushSimpleMessage(msg string, isAtAll bool)

PushSimpleMessage

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 SafeCloseChan

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

SafeCloseChan

func SafeDefer

func SafeDefer(params ...interface{})

func SafeGo

func SafeGo(params ...interface{})

func SafeSendChan

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

SafeSendChan

func SortMapByKey

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

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

func StrFirstToLower

func StrFirstToLower(str string) string

StrFirstToLower 字符串首字母转成小写

func StrFirstToUpper

func StrFirstToUpper(str string) string

StrFirstToUpper 字符串首字母转成大写

func Struct2Map

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

结构体转为map

func SystemIP

func SystemIP() string

SystemIP

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
}

Request构造类

func NewRequest

func NewRequest(url string) *Request

创建一个Request实例

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

设置请求cookies

func (*Request) SetHeaders

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

设置请求头

func (*Request) SetMethod

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

设置请求方法

func (*Request) SetPostData

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

设置post请求的提交数据

func (*Request) SetQueries

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

设置url查询参数

func (*Request) SetTimeOut

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

SetDialTimeOut

func (*Request) SetUrl

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

设置请求地址

type Response

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

Response 构造类

func NewResponse

func NewResponse() *Response

func (*Response) IsOk

func (r *Response) IsOk() bool

func (*Response) StatusCode

func (r *Response) StatusCode() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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