fetch

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2023 License: Apache-2.0 Imports: 8 Imported by: 24

README

fetch -- Fetch Data from URL

check vulns lint status GitHub license GitHub release

This package is required Go 1.16 or later.

Migrated repository to github.com/goark/fetch

Import

import "github.com/goark/fetch"

Usage

package main

import (
    "context"
    "fmt"
    "io"
    "os"

    "github.com/goark/fetch"
)

func main() {
    u, err := fetch.URL("https://github.com/spiegel-im-spiegel.gpg")
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
        return
    }
    resp, err := fetch.New().GetWithContext(context.Background(), u)
    if err != nil {
        fmt.Fprintln(os.Stderr, err)
        return
    }
    defer resp.Close()
    if _, err := io.Copy(os.Stdout, resp.Body()); err != nil {
        fmt.Fprintln(os.Stderr, err)
    }
}

Modules Requirement Graph

dependency.png

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNullPointer    = errors.New("null reference instance")
	ErrInvalidRequest = errors.New("invalid HTTP request")
	ErrInvalidURL     = errors.New("invalid URL")
	ErrHTTPStatus     = errors.New("bad HTTP status")
)

Functions

func URL

func URL(rawURL string) (*url.URL, error)

URL function returns url.URL instance from string.

Types

type Client

type Client interface {
	// Deprecated: Should use GetWithContext() method instead of Get() method.
	Get(u *url.URL, opts ...RequestOpts) (Response, error)
	GetWithContext(ctx context.Context, u *url.URL, opts ...RequestOpts) (Response, error)
	// Deprecated: Should use PostWithContext() method instead of Post() method.
	Post(u *url.URL, payload io.Reader, opts ...RequestOpts) (Response, error)
	PostWithContext(ctx context.Context, u *url.URL, payload io.Reader, opts ...RequestOpts) (Response, error)
}

Client is inteface class for HTTP client.

func New

func New(opts ...ClientOpts) Client

New function returns Client instance.

type ClientOpts

type ClientOpts func(*client)

func WithHTTPClient

func WithHTTPClient(cli *http.Client) ClientOpts

WithProtocol returns function for setting http.Client.

type RequestOpts

type RequestOpts func(*http.Request) *http.Request

func WithContext

func WithContext(ctx context.Context) RequestOpts

WithProtocol returns function for setting context.Context. Deprecated: should not be used

func WithRequestHeaderAdd

func WithRequestHeaderAdd(name, value string) RequestOpts

WithRequestHeaderAdd returns function for adding request header in http.Request.

func WithRequestHeaderSet

func WithRequestHeaderSet(name, value string) RequestOpts

WithRequestHeaderSet returns function for setting request header in http.Request.

type Response

type Response interface {
	Request() *http.Request
	Header() http.Header
	Body() io.ReadCloser
	Close()
	DumpBodyAndClose() ([]byte, error)
}

Response is inteface class for HTTP response.

Jump to

Keyboard shortcuts

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