api

package
v0.0.0-...-8a9203b Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2015 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSONContentType = "application/json"
)

Variables

View Source
var (
	InvalidPort = errors.New("api: invalid port number 0")
	IPRegex     = regexp.MustCompile("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$")
)

Functions

func GetKeyHandler

func GetKeyHandler(req *http.Request) (int, interface{})

func Init

func Init(opts *Options, db storage.DB)

func SetKeyHandler

func SetKeyHandler(req *http.Request) (int, interface{})

func StatusHandler

func StatusHandler(req *http.Request) (int, interface{})

Types

type Middleware

type Middleware func(http.Handler) http.Handler

func Accept

func Accept(contentTypes ...string) Middleware

func Method

func Method(methods ...string) Middleware

func Trace

func Trace() Middleware

func WithContext

func WithContext(values map[int]interface{}) Middleware

type NewEntry

type NewEntry struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Options

type Options struct {
	IP   string `name:"ip" default:"127.0.0.1"`
	Port uint16 `name:"port" default:"4080"`
}

func (*Options) Address

func (opts *Options) Address() string

func (*Options) Validate

func (opts *Options) Validate() error

type Server

type Server struct {
	Opts        *Options
	Mux         *mux.Router
	Middlewares []Middleware
}

func MakeServer

func MakeServer(opts *Options, db storage.DB) *Server

func NewServer

func NewServer(opts *Options, middlewares ...Middleware) *Server

func (*Server) Handle

func (s *Server) Handle(route string, handler http.Handler, middlewares ...Middleware)

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

type SimpleHandler

type SimpleHandler func(*http.Request) (int, interface{})

func (SimpleHandler) ServeHTTP

func (h SimpleHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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