Documentation
¶
Overview ¶
Package api is the atomic api helper library
Index ¶
- func Write(w http.ResponseWriter, status int, payload interface{}, headers ...http.Header) error
- func WriteJSON(w http.ResponseWriter, status int, payload interface{}, headers ...http.Header) error
- func WriteXML(w http.ResponseWriter, status int, payload interface{}, headers ...http.Header) error
- type Option
- func WithAddr(addr string) Option
- func WithAuthorizer(auth oauth.Authorizer) Option
- func WithBasepath(base string) Option
- func WithLogger(logger log.Interface) Option
- func WithName(name string) Option
- func WithRouter(router *mux.Router) Option
- func WithVersioning(version string, serverVersion ...string) Option
- type Parameters
- type Responder
- type Response
- type Server
- func (s *Server) AddRoute(path string, method string, params Parameters, handler interface{}, ...)
- func (s *Server) Handler() http.Handler
- func (s *Server) RequestVersion(r *http.Request) string
- func (s *Server) Router() *mux.Router
- func (s *Server) Serve() error
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) WriteError(w http.ResponseWriter, status int, err error)
- func (s *Server) WriteJSON(w http.ResponseWriter, status int, v interface{}, pretty ...bool)
- type WriterFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*Server)
Option provides the server options, these will override th defaults and any atomic instance values.
func WithAuthorizer ¶
func WithAuthorizer(auth oauth.Authorizer) Option
WithAuthorizer sets the authorizer for the server
func WithBasepath ¶
WithBasepath sets the router basepath for the api
func WithVersioning ¶
WithVersioning enables versioning that will enforce a versioned path and optionally set the Server header to the serverVersion
type Parameters ¶
Parameters interface handles binding requests
type Responder ¶
type Responder interface {
// Status returns the http status
Status() int
// Payload is the payload
Payload() interface{}
// Write writes ou the payload
Write(w http.ResponseWriter) error
}
Responder is an api response interface
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is the common response type
func NewResponse ¶
func NewResponse(payload ...interface{}) *Response
NewResponse returns a response with defaults
func (*Response) WithHeader ¶
WithHeader adds headers to the request
func (*Response) WithStatus ¶
WithStatus sets the status
func (*Response) WithWriter ¶ added in v1.0.0
func (r *Response) WithWriter(w WriterFunc) *Response
WithWriter sets the writer
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an http server that provides basic REST funtionality
func (*Server) AddRoute ¶
func (s *Server) AddRoute(path string, method string, params Parameters, handler interface{}, scope ...oauth.Permissions)
AddRoute adds a route in the clear
func (*Server) RequestVersion ¶
RequestVersion returns the request version or the server version is not found
func (*Server) WriteError ¶
func (s *Server) WriteError(w http.ResponseWriter, status int, err error)
WriteError writes an error object
type WriterFunc ¶ added in v1.0.0
type WriterFunc func(w http.ResponseWriter, status int, payload interface{}, headers ...http.Header) error
WriterFunc is a response writer