saHttp

package
v0.0.0-...-b2602dc Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 19 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(in Params, resPtr interface{}) (err error)

Do @Description: 发送请求 @param params 请求参数 @param resPtr 返回结果接收对象的指针,必须是指针或者空 @return err

func Download

func Download(url string, suffix string) (localFilePath string, err error)

func Get

func Get(url string, params map[string]string) (res string, err error)

func GetIpRegion

func GetIpRegion(ip string) *map[string]string

func GetLocalIP

func GetLocalIP() (ips []string, err error)

func IsIpAddress

func IsIpAddress(str string) bool

func JwtGenerate

func JwtGenerate(ptr interface{}, key string) (j string, err error)

func JwtParse

func JwtParse(token string, key string, ptr interface{}) (err error)

func Post

func Post(url string, params map[string]string) (res string, err error)

func PostJson

func PostJson(uri string, obj interface{}) (res string, err error)

func PostRequest

func PostRequest(uri string, obj interface{}, headers map[string]string) (res string, err error)

func SetErrCallback

func SetErrCallback(handle CallbackFun)

SetErrCallback @Description: 设置error时回调

func ToRequest

func ToRequest(method string, url string, params map[string]string, header map[string]string) (res string, err error)

func Upload

func Upload(url string, fileParams map[string]string, params map[string]string, headers map[string]string) (res string, err error)

Upload file -> name:文件参数名 path:本地文件路径

Types

type CallbackFun

type CallbackFun func(request string)

type Params

type Params struct {
	Method          string                 //默认GET,仅支持GET/POST方法
	Url             string                 //不能空
	Query           map[string]interface{} //interface部分json序列化后进行UrlEncode
	Header          map[string]interface{} //interface部分会json序列化
	Body            map[string]interface{} //会进行json序列化或者query序列化(form表单),取决于content-type;默认query序列化
	BodyString      string                 //string类型body,仅content-type为application-json,且Body为空时有效
	Timeout         time.Duration          //默认10秒
	CallbackWhenErr bool                   //是否在失败时回调,默认关闭
}

Jump to

Keyboard shortcuts

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