api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package api provides common utility functions for working with HTTP(S) APIs

Index

Constants

This section is empty.

Variables

View Source
var RequestTemplates map[string]RequestTemplate

RequestTemplates provides a cache of RequestTemplates

Functions

func BuildBody

func BuildBody(templateName string, data interface{}) (io.Reader, error)

BuildBody returns the body of an API request built from the specified template and data

func BuildRequest

func BuildRequest(userAgent string, method string, reqPath string, reqBody io.Reader) (*http.Request, error)

BuildRequest assembles an API request ready for transport

func Do

func Do(client *http.Client, req *http.Request, logger Logger) (res *http.Response, readBody string, err error)

Do transports a single API request

func DoBatch

func DoBatch(client *http.Client, reqs []*http.Request, logger Logger) (resps []*http.Response, readBodies []string, errs []error)

DoBatch transports a sequence of API requests concurrently

Types

type Logger

type Logger interface {
	Log(m string) (err error)
}

Logger provides a simple interface for logging API calls

type LoggerFunc

type LoggerFunc func(m string) (err error)

LoggerFunc provides a simple type for single function implementations of the Logger interface

func (LoggerFunc) Log

func (f LoggerFunc) Log(m string) (err error)

Log defines the single method Logger interface

type RequestTemplate

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

RequestTemplate contains a *template.Template used to build API requests

Jump to

Keyboard shortcuts

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