fetch

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 6 Imported by: 14

README

fetch

a http request lib with go

how to use

GET

url := "http://example.com"

result, err := fetch.Cmd(fetch.Request{
    Method: "GET",
    URL:    url,
})
fmt.Println(result, err)

DELETE

url := "http://example.com"

result, err := fetch.Cmd(fetch.Request{
    Method: "DELETE",
    URL:    url,
})
fmt.Println(result, err)

POST

url := "http://example.com"

data := map[string]string{
    "go":   "golang",
    "java": "javalang",
    "rust": "rustlang",
}
body, _ := json.Marshal(data)

header := http.Header{}
header.Add("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4")

result, err := fetch.Cmd(fetch.Request{
    Method: "POST",
    URL:    url,
    Body:   body,
    Header: header,
})
fmt.Println(result, err)

PUT

url := "http://example.com"

data := map[string]string{
    "go":   "golang",
    "java": "javalang",
    "rust": "rustlang",
}
body, _ := json.Marshal(data)

header := http.Header{}
header.Add("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4")

result, err := fetch.Cmd(fetch.Request{
    Method: "PUT",
    URL:    url,
    Body:   body,
    Header: header,
})
fmt.Println(result, err)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cmd

func Cmd(args *Request) ([]byte, error)

Cmd fetch command

func Do added in v1.0.4

func Do(args *Request) (*http.Response, error)

Do fetch do

Types

type Client added in v1.0.2

type Client struct {
	Cert string
	Key  string
	IP   string
}

Client client

func NewClient added in v1.0.2

func NewClient(args *Request) *Client

NewClient new client

func (*Client) Do added in v1.0.2

func (c *Client) Do() *http.Client

Do fetch do

func (*Client) Proxy added in v1.0.2

func (c *Client) Proxy() *http.Transport

Proxy fetch proxy

func (*Client) TLS added in v1.0.2

func (c *Client) TLS() *http.Transport

TLS fetch tls

type Fetch added in v1.0.2

type Fetch struct {
	Method string
	URL    string
	Body   []byte
	Header http.Header
}

Fetch Fetch

func NewFetch added in v1.0.2

func NewFetch(args *Request) *Fetch

NewFetch new fetch

func (*Fetch) Request added in v1.0.2

func (f *Fetch) Request() (*http.Request, error)

Request request

func (*Fetch) Response added in v1.0.2

func (f *Fetch) Response(args *http.Request, client *http.Client) (*http.Response, error)

Response response

type Request

type Request struct {
	Method string
	URL    string
	Body   []byte
	Header http.Header
	Cert   string
	Key    string
	IP     string
}

Request request

Jump to

Keyboard shortcuts

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