braid

package module
v0.0.0-...-b45ec87 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

README

Braid

Documentation Build Status Coverage Status

A Go library for fetching a HTTP resource using parallel GET requests

Example:

	var b *braid.Request
	var f *os.File

	b, err = braid.NewRequest()
	if err != nil {
		os.Exit(err)
	}
	b.SetJobs(3) // set number of parallel requests. Defaults to 5
	ctx := context.Background()
	f, err = b.FetchFile(ctx, url, filename)
	if err != nil {
		os.Exit(err)
	}
	f.Close()

See cmd/braid/braid.go for a working example.

Documentation

Overview

Package braid provides a way to GET a single HTTP resource using multiple parallel requests.

Index

Constants

View Source
const DefaultJobs = 5

DefaultJobs is the number of parallel HTTP requests to be made by default.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l Logger)

SetLogger sets where log should be sent. By default log is muted

Types

type Logger

type Logger func(string, ...interface{})

type Request

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

func NewRequest

func NewRequest() (*Request, error)

NewRequest returns a new request.

func (*Request) FetchFile

func (r *Request) FetchFile(ctx context.Context, url, filename string) (*os.File, error)

FetchFile fetches the resource, returning the result as an *os.File The caller is responsible for closing the returned file. Filename must be writable, will be created if missing and will be truncated.

func (*Request) SetJobs

func (r *Request) SetJobs(jobs int)

SetJobs sets the number of parallel requests that will be made. DefaultJobs is used by default.

func (*Request) SetUserAgent

func (r *Request) SetUserAgent(userAgent string)

SetUserAgent sets the 'User-Agent' HTTP header used when making requests

func (*Request) Stats

func (r *Request) Stats() Stat

Stats retrieves current statistics. It is thread safe and can be called from a goroutine.

type Stat

type Stat struct {
	TotalBytes int64
	ReadBytes  int64
}

Directories

Path Synopsis
cmd
braid command

Jump to

Keyboard shortcuts

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