https

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: BSD-3-Clause Imports: 12 Imported by: 0

README

https

介绍

HTTPS网络请求仓库

依赖特点
  1. 基于Option模式进行选项式传参
使用方法
// 设置默认超时时间
https.SetDefaultTimeOut(time.Second * 20)

// GET请求
curl := https.New("https://baidu.com").Get()
if curl.Error != nil {
    // 错误处理
}
// 直接使用New进行创建
https.New("https://baidu.com",https.WithHttpsContinue(true))......
// 使用WithOption进行创建
https.New("https://baidu.com").WithOption(https.WithHttpsContinue(true))......

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearQuestLog

func ClearQuestLog()

清除Quest请求日志记录的函数列表

func SetDefaultCacheFunc

func SetDefaultCacheFunc(t CacheInterface)

设置缓存信息

t	实现缓存方法的接口信息

func SetDefaultCacheTime

func SetDefaultCacheTime(t time.Duration)

设置默认的缓存时间 不建议设置此值,若确实需要缓存的话,建议针对URL地址进行配置缓存时间

t	缓存时间

func SetDefaultTimeOut

func SetDefaultTimeOut(t time.Duration)

设置默认的超时时间

t	超时时间

func SetQuestLog

func SetQuestLog(f func(c *CURL))

设置Quest请求日志

f	日志记录函数【此函数会记录多个,所以请勿一直调用SetQuestLog进行插入日志记录函数】

Types

type CURL

type CURL struct {
	Uri             string            `json:"uri"`         // 请求网址
	Param_quest     map[string]string `json:"param"`       // 请求参数
	HttpCode        int               `json:"http_code"`   // HTTP返回的code值
	ParamJson_quest map[string]any    `json:"param_json"`  // JSON推送参数
	Body            string            `json:"body"`        // 返回值
	Error           error             `json:"error"`       // 错误信息
	Header_quest    map[string]string `json:"header"`      // 请求Header头
	CreateTime      time.Time         `json:"create_time"` // 实例创建时间
	StartTime       time.Time         `json:"start_time"`  // 请求开始时间
	EndTime         time.Time         `json:"end_time"`    // 请求结束时间
	ClientIp        string            `json:"client_ip"`   // 请求的客户端IP【兼容日志处理模块的预留字段】
	Cookie_quest    []string          `json:"cookie"`      // HTTP网址返回的Set-Cookie相应头
	// contains filtered or unexported fields
}

网址服务对象

func New

func New(url string, opts ...OptionFunc) *CURL

声明URL请求结构信息

url		要请求的网址信息
opts	可选参数,针对此网址进行的配置项追加

func (*CURL) Authorization

func (c *CURL) Authorization(token string) *CURL

追加Header请求头信息

token	JWT编码的Token加密信息

func (*CURL) Cookie

func (c *CURL) Cookie(cookie_param []string) *CURL

设置cookie集合

cookie_param	cookie参数值

func (*CURL) Download

func (c *CURL) Download(file string) *CURL

下载文件,将请求的内容保存到本地

file	保存文件名

func (*CURL) DownloadIO

func (c *CURL) DownloadIO(f io.Writer) *CURL

下载文件到对外IO中进行重定向

f	写入对象的IO方法

func (*CURL) Get

func (c *CURL) Get() *CURL

使用GET请求 此处仅能使用 `Param` 进行设置请求参数

func (*CURL) Header

func (c *CURL) Header(h map[string]string) *CURL

设置Header请求头

h	header请求头的键值对信息

func (*CURL) HeaderKV

func (c *CURL) HeaderKV(k, v string) *CURL

设置Header请求头

k	header下标
v	header下标对应的值

func (*CURL) Param

func (c *CURL) Param(m map[string]string) *CURL

追加请求参数

m	待追加的参数信息

func (*CURL) ParamJson

func (c *CURL) ParamJson(m map[string]any) *CURL

JSON格式的请求参数追加

m	追加的参数列表(可直接传入map[string]any{"_":xxx}(会在map最外层有且仅有_下标时才会直接取其内容进行传输))

func (*CURL) ParamKV

func (c *CURL) ParamKV(k, v string) *CURL

追加请求参数

k	请求参数的参数名
v	请求参数的参数值

func (*CURL) Post

func (c *CURL) Post() *CURL

使用POST请求 此处仅能使用 `Param` 进行设置请求参数

func (*CURL) PostJson

func (c *CURL) PostJson() *CURL

使用POST请求 此处使用 `ParamJson` 进行设置请求参数,支持使用 `Param` 设置的参数列表

func (*CURL) WithOption

func (c *CURL) WithOption(opts ...OptionFunc) *CURL

设置Option选项[此参数需要在Get/Post/PostJson之前进行调用,若在之后调用的话会失去作用]

opts	可选参数,针对此网址进行的配置项追加

type CacheInterface

type CacheInterface interface {
	Get(name string) string                       // 获取缓存值,缓存未找到的话请返回空字符串
	Set(name string, val string, t time.Duration) // 设置缓存值,可能存在部分无法在string中正常显示的字符串
}

缓存钩子

type Option

type Option struct {
	// contains filtered or unexported fields
}

外部选项传参结构[可选参数]

type OptionFunc

type OptionFunc func(c *Option)

选项设置参数,用于设置本次请求中的选项信息

func WithCache

func WithCache(t time.Duration) OptionFunc

设置缓存时间

t	设置缓存时间,0表示不设置缓存

func WithHttpsContinue

func WithHttpsContinue(c bool) OptionFunc

设置跳过https证书验证

c	是否跳过

func WithIgnoreHeader

func WithIgnoreHeader(k string) OptionFunc

func WithTimeOut

func WithTimeOut(t time.Duration) OptionFunc

设置请求的超时时间

t	设置超时时间

Jump to

Keyboard shortcuts

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