api

package
v0.0.0-...-1f6f007 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogMiddleware

func LogMiddleware(logger log.Logger, inner http.Handler, name string) http.Handler

LogMiddleware is a wrapper for the http handler. It gets passed the handler and returns the same handler with added logging and timing functionalities.

func NewRouter

func NewRouter(logger log.Logger, routes Routes) *mux.Router

NewRouter creates a new router based on Gorilla's mux router It also wraps the handlers with logging functionality.

Types

type APIServer

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

APIServer is a structure that defines the API Server. This is defined in order for it to be easily created with a structure that defines the API Routes

func NewAPIServer

func NewAPIServer(wg *sync.WaitGroup, config Config) *APIServer

NewAPIServer creates and runs a new API Server

func (APIServer) BuildAndServeAPI

func (s APIServer) BuildAndServeAPI()

BuildAndServeAPI is the function used to serve the API endpoints

type Config

type Config struct {
	Port      string
	Protected bool
	Password  string
	LogLevel  log.Level
	Routes    []Route
}

Config holds the config necessary for the API Server

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route is a structure that defines the endpoints of the API.

type Routes

type Routes []Route

Routes is a type that encapsulates a list of Route elements

Jump to

Keyboard shortcuts

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