http

package
Version: v0.0.0-...-2443ee7 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 8 Imported by: 0

README

http

A simple http requester

Usage

resp, err := http.Get("url")
if err != nil {
    // err handling
}
fmt.Println(string(resp))

With headers

resp, err := http.SetHeaders(map[string]string{}).Post("url", []byte{})
if err != nil {
    // err handling
}
fmt.Println(string(resp))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(url string) ([]byte, error)

Get by dfault requester

func Post

func Post(url string, body []byte) ([]byte, error)

Post by default requester

Types

type Req

type Req struct {
	// contains filtered or unexported fields
}

Req sends http request

func SetCookies

func SetCookies(cookies []http.Cookie) *Req

SetCookies by default requester

func SetHeaders

func SetHeaders(headers map[string]string) *Req

SetHeaders by default requester

func SetTimeout

func SetTimeout(timeout int) *Req

SetTimeout by default requester

func (*Req) Get

func (r *Req) Get(url string) ([]byte, error)

Get implements HTTPRequester interface

func (*Req) Post

func (r *Req) Post(url string, body []byte) ([]byte, error)

Post implements HTTPRequester interface

func (*Req) SetCookies

func (r *Req) SetCookies(cookies []http.Cookie) *Req

SetCookies sets cookies, which overwrites existing cookies

func (*Req) SetHeaders

func (r *Req) SetHeaders(headers map[string]string) *Req

SetHeaders sets headers, which overwrites existing headers

func (*Req) SetTimeout

func (r *Req) SetTimeout(timeout int) *Req

SetTimeout sets timeout, which overwrites existing timeout

type Requester

type Requester interface {
	Post(url string, body []byte) ([]byte, error)
	Get(url string) ([]byte, error)
}

Requester interface

func NewHTTPRequester

func NewHTTPRequester(timeout int, headers map[string]string, cookies []http.Cookie) Requester

NewHTTPRequester Factory

Source Files

Jump to

Keyboard shortcuts

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