api

package
v0.0.0-...-c2c271f Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2016 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JsonContentTypeKey   = "Content-Type"
	JsonContentTypeValue = "application/json"
)

Variables

This section is empty.

Functions

func AttachMiddleware

func AttachMiddleware(h http.Handler, middlewares ...Middleware) http.Handler

Types

type Api

type Api struct {
	Config   *config.Config
	Database *database.Database
	Logger   *logger.Logger
	Router   *mux.Router
	Writer   io.Writer
}

func New

func New() *Api

func (*Api) ConfigWith

func (a *Api) ConfigWith(filePath string) error

func (*Api) Route

func (a *Api) Route(path string, sr Subrouter)

func (*Api) Serve

func (a *Api) Serve()

func (*Api) Shutdown

func (a *Api) Shutdown()

type JsonError

type JsonError struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

func (JsonError) Error

func (e JsonError) Error() string

func (JsonError) String

func (e JsonError) String() string

type Middleware

type Middleware func(http.Handler) http.Handler

func Catch404Handler

func Catch404Handler() Middleware

func LoggingHandler

func LoggingHandler(out io.Writer) Middleware

type ServiceProvider

type ServiceProvider interface {
	ConfigWith(string) error
	Serve()
	Shutdown()
}

type Subroute

type Subroute struct {
	Config   *config.Config
	Database *database.Database
	Logger   *logger.Logger
	Router   *mux.Router
}

func (*Subroute) ConfigWith

func (sr *Subroute) ConfigWith(r *mux.Router, d *database.Database, c *config.Config, l *logger.Logger)

func (*Subroute) JsonBaseHandler

func (sr *Subroute) JsonBaseHandler(w http.ResponseWriter, r *http.Request, code int, data interface{})

func (*Subroute) JsonInternalErrorHandler

func (sr *Subroute) JsonInternalErrorHandler(w http.ResponseWriter, r *http.Request, err error)

func (*Subroute) JsonNotFoundHandler

func (sr *Subroute) JsonNotFoundHandler(w http.ResponseWriter, r *http.Request, err error)

func (*Subroute) JsonResponseHandler

func (sr *Subroute) JsonResponseHandler(w http.ResponseWriter, r *http.Request, data interface{})

type Subrouter

type Subrouter interface {
	ConfigWith(*mux.Router, *database.Database, *config.Config, *logger.Logger)
	Handle()
}

type Version1

type Version1 struct {
	Subroute
}

func (*Version1) Handle

func (v1 *Version1) Handle()

Jump to

Keyboard shortcuts

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