request

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2020 License: MIT Imports: 10 Imported by: 2

README

request

Build Status Coverage Status License GoDoc

A concise HTTP request client for Go.

Installation

go get github.com/mushroomsir/request

Feature

  • Easy to use.
  • Support gzip、deflate decompress.

Usage

package main

import (
	"github.com/mushroomsir/request"
)

func main() {
	url := "https://github.com"

	body := struct {
		Any interface{} `json:"Any"`
	}{
		Any: "",
	}

	result := struct {
		Any interface{} `json:"Any"`
	}{}

	request.Post(url).Body(&body).Result(&result).Do()
}

Header
request.Get("url").Set("Content-Type", "application/json").Result(&result).Do()

or

header := http.Header{}
header.Set("Content-Type", "application/json")

request.Get("url").Header(header).Result(&result).Do()

Licenses

All source code is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetHttpClient

func SetHttpClient(client *http.Client)

SetHttpClient ...

func SetUserAgent

func SetUserAgent(ua string)

SetUserAgent ...

Types

type Request

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

Request ...

func Delete

func Delete(url string) *Request

Delete ...

func Get

func Get(url string) *Request

Get ...

func Method

func Method(method string) *Request

Method ...

func New

func New() *Request

New ...

func Post

func Post(url string) *Request

Post ...

func Put

func Put(url string) *Request

Put ...

func Url

func Url(url string) *Request

Url ...

func (*Request) Body

func (a *Request) Body(body interface{}) *Request

Body ...

func (*Request) Delete

func (a *Request) Delete(url string) *Request

Delete ...

func (*Request) Do

func (a *Request) Do() (*Response, error)

Do ...

func (*Request) Get

func (a *Request) Get(url string) *Request

Get ...

func (*Request) Header

func (a *Request) Header(h http.Header) *Request

Header ...

func (*Request) Method

func (a *Request) Method(method string) *Request

Method ...

func (*Request) Post

func (a *Request) Post(url string) *Request

Post ...

func (*Request) Put

func (a *Request) Put(url string) *Request

Put ...

func (*Request) RawBody

func (a *Request) RawBody(body string) *Request

RawBody ...

func (*Request) Result

func (a *Request) Result(result interface{}) *Request

Result ...

func (*Request) SetHeader

func (a *Request) SetHeader(key, val string) *Request

SetHeader ...

func (*Request) Url

func (a *Request) Url(url string) *Request

Url ...

type Response

type Response struct {
	Request    *http.Request
	Response   *http.Response
	StatusCode int
	Content    []byte
}

Response ...

func (*Response) OK

func (a *Response) OK() bool

OK ...

func (*Response) String

func (a *Response) String() string

String deprecated

func (*Response) Text

func (a *Response) Text() string

Text ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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