rest

package
v0.0.0-...-45da7de Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 23 Imported by: 11

Documentation

Index

Constants

View Source
const ContentTypeJSON = "application/json; charset=utf-8"

Variables

View Source
var Client = &http.Client{

	Transport: &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	},
}

Functions

func DiscardCloseBody

func DiscardCloseBody(r *http.Response) error

func DurationOr

func DurationOr(a, b time.Duration) time.Duration

func If

func If(condition bool, a, b string) string

If tests condition to return a or b.

func IsJSONBytes

func IsJSONBytes(b []byte) bool

IsJSONBytes tests bytes b is in JSON format.

func JoinURL

func JoinURL(base *url.URL, target string) (string, error)

func LogRequest

func LogRequest(r *http.Request, verbose string)

func LogResponse

func LogResponse(r *http.Response, verbose string)

func MaybeURL

func MaybeURL(out string) (string, bool)

func ReadCloseBody

func ReadCloseBody(r *http.Response) ([]byte, error)

Types

type FixURIConfig

type FixURIConfig struct {
	DefaultScheme string
	DefaultHost   string
	DefaultPort   int
	FatalErr      bool
	Auth          string
}

type FixURIConfigFn

type FixURIConfigFn func(*FixURIConfig)

func WithAuth

func WithAuth(v string) FixURIConfigFn

func WithDefaultHost

func WithDefaultHost(v string) FixURIConfigFn

func WithDefaultPort

func WithDefaultPort(v int) FixURIConfigFn

func WithDefaultScheme

func WithDefaultScheme(v string) FixURIConfigFn

func WithFatalErr

func WithFatalErr(v bool) FixURIConfigFn

type FixURIConfigFns

type FixURIConfigFns []FixURIConfigFn

func (FixURIConfigFns) Create

func (fns FixURIConfigFns) Create() *FixURIConfig

type FixURIResult

type FixURIResult struct {
	Data *url.URL
	Err  error
}

func FixURI

func FixURI(uri string, fns ...FixURIConfigFn) (rr FixURIResult)

func (FixURIResult) OK

func (r FixURIResult) OK() bool

type Rest

type Rest struct {
	Body             []byte
	Method, Addr     string
	Headers          map[string]string
	Result           interface{}
	DisableKeepAlive bool
	Context          context.Context
	Timeout          time.Duration
	BasicAuth        string
}

func (Rest) Delete

func (r Rest) Delete() (*Rsp, error)

Delete execute HTTP GET request.

func (Rest) Do

func (r Rest) Do() (*Rsp, error)

Do execute HTTP method request.

func (Rest) Get

func (r Rest) Get() (*Rsp, error)

Get execute HTTP GET request.

func (Rest) Post

func (r Rest) Post() (*Rsp, error)

Post execute HTTP POST request.

func (Rest) Upload

func (r Rest) Upload(filename string, fileData []byte) (*Rsp, error)

Upload execute HTTP GET request.

type Rsp

type Rsp struct {
	Body   []byte
	Status int
	Header http.Header
	Cost   time.Duration
}

type URL

type URL struct {
	Base        string
	SubPaths    []string
	QueryValues url.Values
}

func NewURL

func NewURL(base string) URL

func (URL) Build

func (u URL) Build() (string, error)

func (URL) Paths

func (u URL) Paths(paths ...string) URL

func (URL) Query

func (u URL) Query(k, v string, kvs ...string) URL

func (URL) QueryMap

func (u URL) QueryMap(m map[string]string) URL

func (URL) String

func (u URL) String() string

Jump to

Keyboard shortcuts

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