Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateURL(url string) (*urlpkg.URL, error)
- func HasPort(s string) bool
- func Json[T any](job *Job) (out T)
- func ModifyURL(req *http.Request, url string) error
- func RemoveEmptyPort(host string) string
- func SplitName(name string) (protocol, path string)
- type Cookie
- type CookieJar
- type DownloadSystem
- type Downloader
- type DownloaderInterface
- type Job
- func (job *Job) Do() *Response
- func (job *Job) DoWithContext(ctx ...context.Context) *Response
- func (job *Job) Plain() (*http.Response, error)
- func (job *Job) Request() (req *http.Request, err error)
- func (job *Job) SetCookie(cookie string) *Job
- func (job *Job) SetData(data M) *Job
- func (job *Job) SetHeader(header M) *Job
- func (job *Job) SetQuery(query M) *Job
- func (job *Job) SetReferer(referer string) *Job
- func (job *Job) SetURL(url string) *Job
- type M
- func (m M) Add(k, v string)
- func (m M) Clone() (p M)
- func (m M) Data(job *Job)
- func (m M) Del(k string)
- func (m M) Encode() string
- func (m M) GormDataType() string
- func (m M) Header(job *Job)
- func (m M) Query(job *Job)
- func (m M) Read(p []byte) (int, error)
- func (m *M) Scan(val any) error
- func (m M) Set(k, v string)
- func (m M) SetAll(s ...string) error
- func (m M) SetAny(k string, v any) error
- func (m M) SetMap(p M)
- func (m M) SetTrimmed(k, v string)
- func (m M) Value() (driver.Value, error)
- func (m M) WriteHeader(header http.Header)
- type Option
- type Response
- func (r *Response) Content() []byte
- func (r *Response) Data() map[string]any
- func (r *Response) Error() error
- func (r *Response) Json(out any) error
- func (r *Response) MarshalJSON() ([]byte, error)
- func (r *Response) ReadCloser() io.ReadCloser
- func (r *Response) Text() string
- func (r *Response) Write(name string) error
- func (r *Response) Yaml(out any) error
- type ScanValuer
- type Session
- type TypeSession
Constants ¶
View Source
const UserAgent = "" /* 129-byte string literal not displayed */
Variables ¶
View Source
var ( ErrType = errors.New("request: failed to unmarshal JSONB value") ErrOddArgs = errors.New("request: odd number of parameters passed in") )
View Source
var DefaultDownloader = &Downloader{ Sinaimg: New(http.MethodGet, "").SetReferer("https://weibo.com/"), Default: &http.Request{ Method: http.MethodGet, Header: http.Header{"User-Agent": {UserAgent}}, }, }
View Source
var Headers = M{ "Accept-Language": "zh-CN,zh;q=0.9", "Accept-Encoding": "gzip, deflate, br", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "User-Agent": UserAgent, }
View Source
var UserAgentHeader = M{"User-Agent": UserAgent}
Functions ¶
func HasPort ¶ added in v0.10.0
Given a string of the form "host", "host:port", or "[ipv6::address]:port", return true if the string includes a port.
func RemoveEmptyPort ¶ added in v0.10.0
removeEmptyPort strips the empty port in ":port" to "" as mandated by RFC 3986 Section 6.2.3.
Types ¶
type CookieJar ¶ added in v0.10.0
type CookieJar interface { ScanValuer http.CookieJar }
type DownloadSystem ¶ added in v0.11.0
type DownloadSystem struct { Root string Downloader DownloaderInterface }
func DefaultDownloadSystem ¶ added in v0.11.0
func DefaultDownloadSystem(root string) *DownloadSystem
type Downloader ¶ added in v0.11.0
type DownloaderInterface ¶ added in v0.11.0
type Job ¶
type Job struct { Method string `form:"method" yaml:"method" json:"method"` Url string `form:"url" yaml:"url" json:"url"` Data M `form:"data" yaml:"data" json:"data"` Query M `form:"query" yaml:"query" json:"query"` Header M `form:"header" yaml:"header" json:"header"` Cookie *Cookie `form:"cookie" yaml:"cookie" json:"cookie"` Client http.Client `form:"-" yaml:"-" json:"-" gorm:"-"` }
请求任务
func (*Job) DoWithContext ¶ added in v0.10.0
发送请求
func (*Job) SetReferer ¶ added in v0.10.0
type M ¶
func (M) GormDataType ¶ added in v0.1.1
GormDataType gorm common data type
func (M) SetTrimmed ¶ added in v0.10.0
func (M) WriteHeader ¶ added in v0.10.0
type Response ¶ added in v0.10.0
func NewResponse ¶ added in v0.10.0
func (*Response) MarshalJSON ¶ added in v0.10.0
func (*Response) ReadCloser ¶ added in v0.10.0
func (r *Response) ReadCloser() io.ReadCloser
type Session ¶ added in v0.10.0
func NewSessionFromJob ¶ added in v0.10.0
type TypeSession ¶ added in v0.10.0
func NewTypeSession ¶ added in v0.10.0
func NewTypeSession[T any](method, url string, opts ...Option) (*TypeSession[T], error)
func NewTypeSessionFromJob ¶ added in v0.10.0
func NewTypeSessionFromJob[T any](job *Job) (*TypeSession[T], error)
func (*TypeSession[T]) Do ¶ added in v0.10.0
func (t *TypeSession[T]) Do() (out T, err error)
func (*TypeSession[T]) Must ¶ added in v0.10.0
func (t *TypeSession[T]) Must() (out T)
func (*TypeSession[T]) Session ¶ added in v0.10.0
func (t *TypeSession[T]) Session() *Session
Click to show internal directories.
Click to hide internal directories.