env

package
v0.0.0-...-c0adaf6 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// API_PREFIX used for all available routes.
	API_PREFIX string = "/api"

	// API_VERSION included in all available routes.
	API_VERSION string = "/v1"
)

Variables

This section is empty.

Functions

func Header(key, value string) func(http.Handler) http.Handler

Header creates HeaderHandler middleware.

func Log

func Log(t logger.Type) func(http.Handler) http.Handler

Log logs data to stdout with github.com/go-http-utils/logger.

Types

type APIError

type APIError string

APIError informs about possible failures in requests.

const (
	// RequestFailedError when service call fails.
	RequestFailedError APIError = "HTTP_REQUEST_FAILED"

	// ReadDataFailedError when response contains errors.
	ReadDataFailedError APIError = "READ_DATA_FAILED"

	// UnmarshalDataFailedError when unmarshal data from response fails.
	UnmarshalDataFailedError APIError = "UNMARSHAL_DATA_FAILED"
)

func (APIError) Error

func (e APIError) Error() string

Error returns error value as string.

func (APIError) String

func (e APIError) String() string

String returns string value.

type APIResponse

type APIResponse struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

APIResponse returned from endpoints in JSON form.

func NewAPIResponse

func NewAPIResponse(msg string, code int) APIResponse

APIResponse is a default constructor of APIResponse.

func (APIResponse) Send

func (a APIResponse) Send(resp http.ResponseWriter) error

Send marshaled APIError with given code.

type Environment

type Environment struct {
	Middleware alice.Chain
	Router     *Router
}

Environment stores all components that should be shared between packages in application.

func NewEnvironment

func NewEnvironment(logger logger.Type) *Environment

NewEnvironment is a default constructor for an Environment. It takes logger type as an argument.

type HeaderHandler

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

HeaderHandler acts as middleware adding headers.

func (HeaderHandler) ServeHTTP

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

ServeHTP serves HTML document.

type Middleware

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

Middleware holds different chains of middleware and merges them as needed.

func (*Middleware) API

API returns middleware chain containing common and api chain.

func (*Middleware) HTML

func (m *Middleware) HTML(h http.HandlerFunc) http.Handler

HTML returns middleware chain containing common and html chain.

type Router

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

Router enables defining API routes and assinging handlers.

func NewRouter

func NewRouter() *Router

NewRouter is a constructor for a Router.

func (*Router) Delete

func (r *Router) Delete(path string, f func(w http.ResponseWriter, r *http.Request))

Delete enables defining route and handler for DELETE method.

func (*Router) Get

func (r *Router) Get(path string, f func(w http.ResponseWriter, r *http.Request))

Get enables defining route and handler for GET method.

func (*Router) InternalRouter

func (r *Router) InternalRouter() *mux.Router

InternalRouter enables accessing router used in implementation.

func (*Router) Post

func (r *Router) Post(path string, f func(w http.ResponseWriter, r *http.Request))

Post enables defining route and handler for POST method.

func (*Router) Put

func (r *Router) Put(path string, f func(w http.ResponseWriter, r *http.Request))

Put enables defining route and handler for PUT method.

Jump to

Keyboard shortcuts

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