httpsrv

package
v0.12.17 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: MIT Imports: 15 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AssetSet = make(map[string]AssetRoutes)
View Source
var IdentRouteSet = make(map[string]IdentRoutes)

IdentRouteSet is a set of lists of routes to handle

View Source
var MiddlewareSet = make(map[Event][]Middleware)

MiddlewareSet is a set of middlewares grouped by Event lifecycle

View Source
var RouteSet = make(map[string]HttpRoutes)

RouteSet is a set of routelists

View Source
var SignalShutdown = make(chan struct{})

SignalShutdown channel is closed when httpsrv shuts down

View Source
var SignalStartup = make(chan struct{})

SignalStartup channel is closed when httpsrv starts up

View Source
var WaitShutdown sync.WaitGroup

WaitShutdown registers services to wait for graceful shutdown

Functions

func AssetRegister

func AssetRegister(name string, routes AssetRoutes)

func Config

func Config()

Config reads settings from viper

func FsHtml5

func FsHtml5(fn http.FileSystem) http.FileSystem

This function will return the app for subdirectories of the application so it can remove the /#/ urls.

func HttpRegister

func HttpRegister(name string, routes HttpRoutes)

HttpRegister registers a routeset

func IdentRegister

func IdentRegister(name string, routes IdentRoutes)

IdentRegister adds an ident route to list

func NewRouter

func NewRouter() *mux.Router

NewRouter creates a router to handle requests

func RegisterModule

func RegisterModule(name string, fn ModuleHandler)

RegisterModule stores a module

func Run

func Run()

Run startup a new server

func Shutdown

func Shutdown()

Shutdown graceful shutdown of server

func WriteError

func WriteError(w http.ResponseWriter, code int, msg string)

WriteError write an error message

func WriteObject

func WriteObject(w http.ResponseWriter, code int, o interface{})

WriteObject write object as json

func WriteText

func WriteText(w http.ResponseWriter, code int, o string)

WriteText writes plain text

func WriteWindow

func WriteWindow(w http.ResponseWriter, code int, results, limit, offset uint64, o interface{})

WriteWindow writes a window object of items

Types

type AssetRoute

type AssetRoute struct {
	Name        string
	Path        string
	HandlerFunc http.FileSystem
}

type AssetRoutes

type AssetRoutes []AssetRoute

func (AssetRoutes) Len

func (a AssetRoutes) Len() int

func (AssetRoutes) Less

func (a AssetRoutes) Less(i, j int) bool

func (AssetRoutes) Swap

func (a AssetRoutes) Swap(i, j int)

type Event

type Event int

Event lifecycle state

const (
	EventPreAuth Event = iota
	EventPreHandle
	EventPostHandle
	EventComplete
	EventUnknown = 1<<63 - 1
)

Event lifecycle states

func (Event) String

func (e Event) String() string

type HandlerFunc

type HandlerFunc func(ResponseWriter, *http.Request, ident.Ident)

HandlerFunc is used by registered routes

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *http.Request, i ident.Ident)

ServeHTTP handles a request

type HttpRoute

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

HttpRoute is a route to handle

type HttpRoutes

type HttpRoutes []HttpRoute

HttpRoutes is a list of routes

type IdentRoute

type IdentRoute struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc HandlerFunc
}

IdentRoute is a single route to handle

type IdentRoutes

type IdentRoutes []IdentRoute

IdentRoutes is a list of routes to handle

type Middleware

type Middleware struct {
	Name        string
	Whitelist   map[string]bool
	Blacklist   map[string]bool
	ProcessHTTP MiddlewareFunc
}

Middleware defines when middleware should be executed in event lifecycle

func NewMiddleware

func NewMiddleware(name string, hdlr MiddlewareFunc) (m Middleware)

NewMiddleware defines a new middleware

func (Middleware) Register

func (m Middleware) Register(event Event)

Register inserts the middleware into the lifecycle map

func (Middleware) SetBlacklist

func (m Middleware) SetBlacklist(whitelist []string) Middleware

SetBlacklist sets the events to avoid

func (Middleware) SetWhitelist

func (m Middleware) SetWhitelist(whitelist []string) Middleware

SetWhitelist sets the events names to target

type MiddlewareFunc

type MiddlewareFunc func(name string, w ResponseWriter, r *http.Request, id ident.Ident) bool

MiddlewareFunc is a function that handles a request/response through request lifecycle

type MiddlewareList

type MiddlewareList []Middleware

MiddlewareList is a list of registered middlewares

type ModuleHandler

type ModuleHandler func(map[string]string)

ModuleHandler holds registered handlers for httpsrv

type ResponseWriter

type ResponseWriter struct {
	W http.ResponseWriter
	R *responseWriter
}

func WrapResponseWriter

func WrapResponseWriter(w http.ResponseWriter) (r ResponseWriter)

func (ResponseWriter) GetCode

func (w ResponseWriter) GetCode() int

func (ResponseWriter) Header

func (w ResponseWriter) Header() http.Header

func (ResponseWriter) Since

func (w ResponseWriter) Since() time.Duration

func (ResponseWriter) StopTime

func (w ResponseWriter) StopTime() time.Duration

func (ResponseWriter) Write

func (w ResponseWriter) Write(b []byte) (int, error)

func (ResponseWriter) WriteError

func (w ResponseWriter) WriteError(code int, msg string)

func (ResponseWriter) WriteHeader

func (w ResponseWriter) WriteHeader(c int)

func (ResponseWriter) WriteObject

func (w ResponseWriter) WriteObject(code int, o interface{})

func (ResponseWriter) WriteText

func (w ResponseWriter) WriteText(code int, str string)

func (ResponseWriter) WriteWindow

func (w ResponseWriter) WriteWindow(code int, results, limit, offset uint64, o interface{})

type ResultError

type ResultError struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

ResultError is a message error swagger:model ResultError

type ResultWindow

type ResultWindow struct {
	Code    int         `json:"code"`
	Msg     string      `json:"msg"`
	Results uint64      `json:"results"`
	Limit   uint64      `json:"limit"`
	Offset  uint64      `json:"offset"`
	Items   interface{} `json:"items"`
}

ResultWindow represents a windowed struct of items. swagger:model ResultWindow

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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