Documentation ¶
Index ¶
- Constants
- Variables
- type AfterResponseHookFunc
- type BeforeRequestHookFunc
- type F
- type H
- type KV
- type Option
- type Response
- func Delete(url string, option Option) (*Response, error)
- func Get(url string, option Option) (*Response, error)
- func Head(url string, option Option) (*Response, error)
- func NewResponse(r *http.Response) (*Response, error)
- func Options(url string, option Option) (*Response, error)
- func Patch(url string, option Option) (*Response, error)
- func Post(url string, option Option) (*Response, error)
- func Put(url string, option Option) (*Response, error)
- type Session
- func (s *Session) Delete(url string, option Option) (*Response, error)
- func (s *Session) Get(url string, option Option) (*Response, error)
- func (s *Session) GetRequest() *http.Request
- func (s *Session) Head(url string, option Option) (*Response, error)
- func (s *Session) Options(url string, option Option) (*Response, error)
- func (s *Session) Patch(url string, option Option) (*Response, error)
- func (s *Session) Post(url string, option Option) (*Response, error)
- func (s *Session) Put(url string, option Option) (*Response, error)
- func (s *Session) RegisterAfterRespHook(fn AfterResponseHookFunc) error
- func (s *Session) RegisterBeforeReqHook(fn BeforeRequestHookFunc) error
- func (s *Session) Request(method string, urlStr string, option Option) (*Response, error)
- func (s *Session) ResetAfterRespHook()
- func (s *Session) ResetBeforeReqHook()
- func (s *Session) UnregisterAfterRespHook(index int) error
- func (s *Session) UnregisterBeforeReqHook(index int) error
Constants ¶
const ( HEAD = "HEAD" GET = "GET" POST = "POST" DELETE = "DELETE" OPTIONS = "OPTIONS" PUT = "PUT" PATCH = "PATCH" )
Variables ¶
var ( // ErrInvalidMethod will be throwed when method not in // [HEAD, GET, POST, DELETE, OPTIONS, PUT, PATCH, CONNECT, TRACE] ErrInvalidMethod = errors.New("nic: Method is invalid") // ErrFileInfo will be throwed when fileinfo is invalid ErrFileInfo = errors.New("nic: Invalid file information") // ErrParamConflict will be throwed when options params conflict // e.g. files + data // json + data // ... ErrParamConflict = errors.New("nic: Options param conflict") // ErrUnrecognizedEncoding will be throwed while changing response encoding // if encoding is not recognized ErrUnrecognizedEncoding = errors.New("nic: Unrecognized encoding") // ErrNotJsonResponse will be throwed when response not a json // but invoke Json() method ErrNotJsonResponse = errors.New("nic: Not a Json response") // ErrHookFuncMaxLimit will be throwed when the number of hook functions // more than MaxLimit = 8 ErrHookFuncMaxLimit = errors.New("nic: The number of hook functions must be less than 8") // ErrIndexOutofBound means the index out of bound ErrIndexOutofBound = errors.New("nic: Index out of bound") )
Functions ¶
This section is empty.
Types ¶
type AfterResponseHookFunc ¶ added in v0.3.1
type BeforeRequestHookFunc ¶ added in v0.3.1
type F ¶
when upload a file, we use nic.KV again nic.File returns F struct
nic.KV { "file1" :"file" : nic.FileFromPath("test.go"), "file2" : nic.File("test.go", []byte("package nic")). FName("nic.go"). MIME("text/plain"), "token" : "abc", }
the POST body is:
Content-Type: multipart/form-data; boundary=e7d105eae032bdc774a787f1d874269d04499cb284477d6d77889be73caf
--e7d105eae032bdc774a787f1d874269d04499cb284477d6d77889be73caf Content-Disposition: form-data; name="file1"; filename="test.go" Content-Type: application/octet-stream
package test --e7d105eae032bdc774a787f1d874269d04499cb284477d6d77889be73caf Content-Disposition: form-data; name="token"
abc --e7d105eae032bdc774a787f1d874269d04499cb284477d6d77889be73caf Content-Disposition: form-data; name="file2"; filename="nic.go" Content-Type: text/plain
package test --e7d105eae032bdc774a787f1d874269d04499cb284477d6d77889be73caf--
F struct saves file form information
func FileFromPath ¶ added in v0.2.1
FileFromPath returns a file struct from file path
type H ¶
type H struct { Params KV Data KV Raw string Headers KV Cookies KV Auth KV Proxy string JSON KV Files KV AllowRedirect bool Timeout int64 Chunked bool DisableKeepAlives bool DisableCompression bool SkipVerifyTLS bool }
H struct is options for request and http client
type Option ¶ added in v0.2.1
type Option interface {
// contains filtered or unexported methods
}
Option is the interface implemented by `H` and `*H`
type Response ¶
type Response struct { *http.Response Text string Bytes []byte // contains filtered or unexported fields }
Response is the wrapper for http.Response
type Session ¶
Session is the wrapper for http.Client and http.Request
func (*Session) GetRequest ¶ added in v0.1.1
GetRequest returns nic.Session.request
func (*Session) RegisterAfterRespHook ¶ added in v0.3.1
func (s *Session) RegisterAfterRespHook(fn AfterResponseHookFunc) error
Register the after response hook
func (*Session) RegisterBeforeReqHook ¶ added in v0.3.1
func (s *Session) RegisterBeforeReqHook(fn BeforeRequestHookFunc) error
Register the before request hook
func (*Session) ResetAfterRespHook ¶ added in v0.3.1
func (s *Session) ResetAfterRespHook()
Reset all after response hook
func (*Session) ResetBeforeReqHook ¶ added in v0.3.1
func (s *Session) ResetBeforeReqHook()
Reset all before request hook
func (*Session) UnregisterAfterRespHook ¶ added in v0.3.1
Unregister the response hook, pass the function's index(start at 0)
func (*Session) UnregisterBeforeReqHook ¶ added in v0.3.1
Unregister the request hook, pass the function's index(start at 0)