Documentation ¶
Index ¶
- Constants
- Variables
- func DownloadHttpFile(url string, saveTo string, timeoutMs int) (int64, error)
- func GetHttpFile(url string, timeoutMs int) ([]byte, error)
- func ParseHttpRequestLine(line string) (method string, uri string, version string, err error)
- func ParseHttpStatusLine(line string) (version string, statusCode string, reason string, err error)
- func PostJson(url string, info interface{}, client *http.Client) (*http.Response, error)
- func ReadHttpHeader(r LineReader) (firstLine string, headers http.Header, err error)
- func UnmarshalRequestJsonBody(r *http.Request, info interface{}, keyFieldList ...string) error
- type HttpMsgCtx
- type HttpReader
- type HttpReqMsgCtx
- type HttpRespMsgCtx
- type LineReader
Constants ¶
View Source
const ( HeaderFieldContentLength = "Content-Length" HeaderFieldContentType = "application/json" )
Variables ¶
View Source
var ( ErrHttpHeader = errors.New("nazahttp: fxxk") ErrParamMissing = errors.New("nazahttp: param missing") )
Functions ¶
func DownloadHttpFile ¶
获取http文件保存至本地
func GetHttpFile ¶ added in v0.12.3
获取http文件保存至字节切片
func ParseHttpRequestLine ¶ added in v0.19.0
Request-Line = Method SP URI SP Version CRLF
func ParseHttpStatusLine ¶ added in v0.19.0
Status-Line = Version SP Status-Code SP Reason CRLF
func PostJson ¶ added in v0.15.3
@param url 地址 @param info 需要序列化的结构体 @param client 注意,如果为nil,则使用http.DefaultClient
func ReadHttpHeader ¶ added in v0.19.0
func ReadHttpHeader(r LineReader) (firstLine string, headers http.Header, err error)
@return firstLine: request的request line或response的status line @return headers: request header fileds的键值对
Types ¶
type HttpMsgCtx ¶ added in v0.19.0
type HttpMsgCtx struct { ReqMethodOrRespVersion string ReqUriOrRespStatusCode string ReqVersionOrRespReason string Headers http.Header Body []byte }
func ReadHttpMessage ¶ added in v0.19.0
func ReadHttpMessage(r HttpReader) (ctx HttpMsgCtx, err error)
注意,如果HTTP Header中不包含`Content-Length`,则不会读取HTTP Body,并且err返回值为nil
type HttpReader ¶ added in v0.19.0
type HttpReader interface { LineReader io.Reader }
e.g. bufio.Reader
type HttpReqMsgCtx ¶ added in v0.19.0
type HttpReqMsgCtx struct { Method string Uri string Version string Headers http.Header Body []byte }
func ReadHttpRequestMessage ¶ added in v0.19.0
func ReadHttpRequestMessage(r HttpReader) (ctx HttpReqMsgCtx, err error)
type HttpRespMsgCtx ¶ added in v0.19.0
type HttpRespMsgCtx struct { Version string StatusCode string Reason string Headers http.Header Body []byte }
func ReadHttpResponseMessage ¶ added in v0.19.0
func ReadHttpResponseMessage(r HttpReader) (ctx HttpRespMsgCtx, err error)
type LineReader ¶ added in v0.13.0
Click to show internal directories.
Click to hide internal directories.