request

package
v0.0.0-...-23853e3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: GPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoUrl        = errors.New("no url informed")
	ErrPageNotExist = errors.New("page not exists")
)
View Source
var DefaultHeader = http.Header{
	"Accept": {"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"},

	"Accept-Language":           {"en-US;q=0.9,en;q=0.8"},
	"Sec-Ch-Ua":                 {`"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123\"`},
	"Sec-Ch-Ua-Mobile":          {"?0"},
	"Sec-Ch-Ua-Platform":        {`"Windows"`},
	"Sec-Fetch-Dest":            {"document"},
	"Sec-Fetch-Mode":            {"navigate"},
	"Sec-Fetch-Site":            {"none"},
	"Sec-Fetch-User":            {"?1"},
	"Upgrade-Insecure-Requests": {"1"},
	"User-Agent":                {"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"},
}

Functions

func HtmlNode

func HtmlNode(opt RequestOptions) (*goquery.Document, http.Response, error)

func Request

func Request(opt RequestOptions) (http.Response, error)

Make custom request and return request, response and error if exist

func RequestGithub

func RequestGithub(Repo, Release, Root string) error
func RequestHtmlLinks(opt RequestOptions) ([]string, http.Response, error)

func SaveFile

func SaveFile(filePath string, opt RequestOptions) (http.Response, error)

Types

type Link struct {
	URL    string
	Params map[string]string
}
func ParseLink(header string) []Link
func ParseMultipleLinks(ks ...string) []Link

func (*Link) HasKey

func (w *Link) HasKey(key string) bool

func (*Link) HasKeyValue

func (w *Link) HasKeyValue(key string, values ...string) (string, bool)

func (*Link) HasParam

func (w *Link) HasParam(key string) bool

func (*Link) Param

func (w *Link) Param(key string) string

type RequestOptions

type RequestOptions struct {
	Url         string            // Request url
	HttpError   bool              // Return if status code is equal or then 300
	Method      string            // Request Method
	Body        io.Reader         // Body Reader
	Headers     http.Header       // Extra HTTP Headers
	Querys      map[string]string // Default querys to set in url
	CodesRetrys []int             // Code to retrys in GET method
}

func (*RequestOptions) Do

func (opt *RequestOptions) Do(jsonInterface any) (http.Response, error)

func (*RequestOptions) File

func (opt *RequestOptions) File(filePath string) error

func (*RequestOptions) MD5

func (opt *RequestOptions) MD5() (string, error)

Create request and calculate MD5 for body response

func (*RequestOptions) Request

func (opt *RequestOptions) Request() (http.Response, error)

func (*RequestOptions) SHA1

func (opt *RequestOptions) SHA1() (string, error)

Create request and calculate SHA1 for body response, recomends use SHA256

func (*RequestOptions) SHA256

func (opt *RequestOptions) SHA256() (string, error)

Create request and calculate SHA256 for body response

func (*RequestOptions) String

func (w *RequestOptions) String() (string, error)

func (*RequestOptions) ToUrl

func (w *RequestOptions) ToUrl() (*url.URL, error)

func (*RequestOptions) WriteStream

func (opt *RequestOptions) WriteStream(writer io.Writer) error

Jump to

Keyboard shortcuts

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