modulepackage
0.0.0-20241209191153-ccdca6be7cb8
Repository: https://github.com/gofika/httputil.git
Documentation: pkg.go.dev
# README
httputil
golang http utils for common use
Basic Usage
Installation
To get the package, execute:
go get github.com/gofika/httputil
Example
package main
import (
"fmt"
"github.com/gofika/httputil"
)
func main() {
resp, err := httputil.Get("https://httpbin.org/get")
if err != nil {
panic(err)
}
type GetResp struct {
URL string `json:"url"`
}
res, err := httputil.ReadJSON[GetResp](resp)
fmt.Printf("url=%s\n", res.URL)
}
# Functions
Delete issues a DELETE to the specified URL.
Get issues a GET to the specified URL.
Head issues a HEAD to the specified URL.
NewClient new client.
Patch issues a PATCH to the specified URL.
PatchJSON issues a PATCH to the specified URL with the given body as JSON.
Post issues a POST to the specified URL.
PostForm issues a POST to the specified URL, with data's keys and values URL-encoded as the request body.
PostFormFiles issues a POST to the specified URL, with data's keys and values URL-encoded as the request body, and files as multipart form.
PostJSON issues a POST to the specified URL with the given body as JSON.
Put issues a PUT to the specified URL.
PutJSON issues a PUT to the specified URL with the given body as JSON.
ReadAll read all data from resp.
ReadAnyJSON read json from resp.Body.
ReadJSON read json from resp.Body.
ReadString read string from resp.Body and auto convert encoding.
SaveFile save file from resp.Body.
WithContentType If a content type is set, each HTTP request will use this content type to make the request.
WithDialTimeout If a dial timeout is set, each HTTP request will use this time as the maximum limit for establishing a connection.
WithHeaders If headers are set, each HTTP request will use these headers to make the request.
WithKeepAliveTimeout If a keep-alive timeout is set, each HTTP request will use this time as the maximum limit for keeping the connection alive.
WithProxy If a proxy is set, each HTTP request will use this proxy to make the request.
WithReferer If a referer is set, each HTTP request will use this referer to make the request.
WithTLSHandshakeTimeout If a TLS handshake timeout is set, each HTTP request will use this time as the maximum limit for completing the TLS handshake.
WithUserAgent sed to replace the default UserAgent when making a request.
# Structs
No description provided by the author
ClientOptions http client options.
RequestOptions http request options.
UploadFile upload file struct.