...

Package http

import "golang.conradwood.net/go-easyops/http"
Overview
Index

Overview ▾

make http requests in a safe manner. optionally cache results

Index ▾

func Get(url string) ([]byte, error)
func Post(url string, body []byte) ([]byte, error)
func Put(url string, body string) ([]byte, error)
type Cookies
    func (c *Cookies) Cookies(u *url.URL) []*http.Cookie
    func (c *Cookies) Print()
    func (c *Cookies) SetCookies(u *url.URL, cookies []*http.Cookie)
type HTTP
    func WithAuth(username string, password string) *HTTP
    func (h *HTTP) Cookie(name string) *http.Cookie
    func (h *HTTP) Cookies() []*http.Cookie
    func (h *HTTP) Debugf(format string, args ...interface{})
    func (h *HTTP) Delete(url string, body []byte) *HTTPResponse
    func (h *HTTP) Get(url string) *HTTPResponse
    func (h *HTTP) GetStream(url string) *HTTPResponse
    func (h *HTTP) Head(url string) *HTTPResponse
    func (h *HTTP) Post(url string, body []byte) *HTTPResponse
    func (h *HTTP) Put(url string, body string) *HTTPResponse
    func (h *HTTP) SetCreds(username, password string)
    func (h *HTTP) SetDebug(b bool)
    func (h *HTTP) SetHeader(key string, value string)
    func (h *HTTP) SetTimeout(dur time.Duration)
type HTTPIF
    func NewCachingClient(ctx context.Context) HTTPIF
    func NewDirectClient() HTTPIF
type HTTPResponse
    func (h *HTTPResponse) AllHeaders() []*header
    func (h *HTTPResponse) Body() []byte
    func (h *HTTPResponse) BodyReader() io.Reader
    func (h *HTTPResponse) Cookies() []*http.Cookie
    func (h *HTTPResponse) Error() error
    func (h *HTTPResponse) FinalURL() string
    func (h *HTTPResponse) HTTPCode() int
    func (h *HTTPResponse) Header(name string) string
    func (h *HTTPResponse) IsSuccess() bool

Package files

cookies.go creds.go direct.go http.go http_caching.go http_response.go

func Get

func Get(url string) ([]byte, error)

************************* direct calls ***************************

func Post

func Post(url string, body []byte) ([]byte, error)

func Put

func Put(url string, body string) ([]byte, error)

type Cookies

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

func (*Cookies) Cookies

func (c *Cookies) Cookies(u *url.URL) []*http.Cookie

func (*Cookies) Print

func (c *Cookies) Print()

func (*Cookies) SetCookies

func (c *Cookies) SetCookies(u *url.URL, cookies []*http.Cookie)

type HTTP

type HTTP struct {
    MetricName string // if not "", will export metrics for this call
    // contains filtered or unexported fields
}

func WithAuth

func WithAuth(username string, password string) *HTTP

func (*HTTP) Cookie

func (h *HTTP) Cookie(name string) *http.Cookie

func (*HTTP) Cookies

func (h *HTTP) Cookies() []*http.Cookie

func (*HTTP) Debugf

func (h *HTTP) Debugf(format string, args ...interface{})

func (*HTTP) Delete

func (h *HTTP) Delete(url string, body []byte) *HTTPResponse

func (*HTTP) Get

func (h *HTTP) Get(url string) *HTTPResponse

func (*HTTP) GetStream

func (h *HTTP) GetStream(url string) *HTTPResponse

func (*HTTP) Head

func (h *HTTP) Head(url string) *HTTPResponse

func (*HTTP) Post

func (h *HTTP) Post(url string, body []byte) *HTTPResponse

func (*HTTP) Put

func (h *HTTP) Put(url string, body string) *HTTPResponse

func (*HTTP) SetCreds

func (h *HTTP) SetCreds(username, password string)

func (*HTTP) SetDebug

func (h *HTTP) SetDebug(b bool)

func (*HTTP) SetHeader

func (h *HTTP) SetHeader(key string, value string)

func (*HTTP) SetTimeout

func (h *HTTP) SetTimeout(dur time.Duration)

type HTTPIF

type HTTPIF interface {
    Cookie(name string) *http.Cookie
    Cookies() []*http.Cookie
    Delete(url string, body []byte) *HTTPResponse
    Get(url string) *HTTPResponse
    GetStream(url string) *HTTPResponse
    Head(url string) *HTTPResponse
    Post(url string, body []byte) *HTTPResponse
    Put(url string, body string) *HTTPResponse
    SetHeader(key string, value string)
    SetTimeout(dur time.Duration)
    SetDebug(b bool)
    SetCreds(username, password string)
}

func NewCachingClient

func NewCachingClient(ctx context.Context) HTTPIF

use urlcacher for the url (needs ctx to authenticate)

func NewDirectClient

func NewDirectClient() HTTPIF

retrieve directly from source

type HTTPResponse

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

func (*HTTPResponse) AllHeaders

func (h *HTTPResponse) AllHeaders() []*header

func (*HTTPResponse) Body

func (h *HTTPResponse) Body() []byte

func (*HTTPResponse) BodyReader

func (h *HTTPResponse) BodyReader() io.Reader

func (*HTTPResponse) Cookies

func (h *HTTPResponse) Cookies() []*http.Cookie

func (*HTTPResponse) Error

func (h *HTTPResponse) Error() error

func (*HTTPResponse) FinalURL

func (h *HTTPResponse) FinalURL() string

the final url (if we followed redirects the last one)

func (*HTTPResponse) HTTPCode

func (h *HTTPResponse) HTTPCode() int

func (*HTTPResponse) Header

func (h *HTTPResponse) Header(name string) string

func (*HTTPResponse) IsSuccess

func (h *HTTPResponse) IsSuccess() bool

if no error and http code indicates success, return true