fetcher

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Path     string
	Interval time.Duration
	// contains filtered or unexported fields
}

File checks the provided Path, at the provided Interval for new Go binaries. When a new binary is found it will replace the currently running binary.

func (*File) Fetch

func (f *File) Fetch() (io.Reader, error)

Fetch file from the specified Path

func (*File) Init

func (f *File) Init() error

Init sets the Path and Interval options

type Github

type Github struct {
	//Github username and repository name
	User, Repo string
	//Interval between fetches
	Interval time.Duration
	//Asset is used to find matching release asset.
	//By default a file will match if it contains
	//both GOOS and GOARCH.
	Asset func(filename string) bool
	// contains filtered or unexported fields
}

Github uses the Github V3 API to retrieve the latest release of a given repository and enumerate its assets. If a release contains a matching asset, it will fetch and return its io.Reader stream.

func (*Github) Fetch

func (h *Github) Fetch() (io.Reader, error)

Fetch the binary from the provided Repository

func (*Github) Init

func (h *Github) Init() error

Init validates the provided config

type HTTP

type HTTP struct {
	//URL to poll for new binaries
	URL          string
	Interval     time.Duration
	CheckHeaders []string
	// contains filtered or unexported fields
}

HTTP fetcher uses HEAD requests to poll the status of a given file. If it detects this file has been updated, it will fetch and return its io.Reader stream.

func (*HTTP) Fetch

func (h *HTTP) Fetch() (io.Reader, error)

Fetch the binary from the provided URL

func (*HTTP) Init

func (h *HTTP) Init() error

Init validates the provided config

type Interface

type Interface interface {
	//Init should perform validation on fields. For
	//example, ensure the appropriate URLs or keys
	//are defined or ensure there is connectivity
	//to the appropriate web service.
	Init() error
	//Fetch should check if there is an updated
	//binary to fetch, and then stream it back the
	//form of an io.Reader. If io.Reader is nil,
	//then it is assumed there are no updates. Fetch
	//will be run repeatedly and forever. It is up the
	//implementation to throttle the fetch frequency.
	Fetch() (io.Reader, error)
}

Interface defines the required fetcher functions

func Func

func Func(fn func() (io.Reader, error)) Interface

Func converts a fetch function into the fetcher interface

type S3

type S3 struct {
	//Access key falls back to env AWS_ACCESS_KEY, then metadata
	Access string
	//Secret key falls back to env AWS_SECRET_ACCESS_KEY, then metadata
	Secret string
	//Region defaults to ap-southeast-2
	Region string
	Bucket string
	Key    string
	//Interval between checks
	Interval time.Duration
	//HeadTimeout defaults to 5 seconds
	HeadTimeout time.Duration
	//GetTimeout defaults to 5 minutes
	GetTimeout time.Duration
	// contains filtered or unexported fields
}

S3 uses authenticated HEAD requests to poll the status of a given object. If it detects this file has been updated, it will perform an object GET and return its io.Reader stream.

func (*S3) Fetch

func (s *S3) Fetch() (io.Reader, error)

Fetch the binary from S3

func (*S3) Init

func (s *S3) Init() error

Init validates the provided config

Jump to

Keyboard shortcuts

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