Documentation
¶
Overview ¶
Package aserver implements a wrapper around gorilla/mux router and net/http server to create a production grade server and simply the creation of routes and handlers.
Index ¶
- func WithDebug(d bool) func(*AServer) error
- func WithDefaultHeaders(d bool) func(*AServer) error
- func WithDownFile(down string) func(*AServer) error
- func WithHTTPIdleTimeout(t int) func(*AServer) error
- func WithHTTPTimeout(t int) func(*AServer) error
- func WithHealthHandler(h bool) func(*AServer) error
- func WithListen(listen string) func(*AServer) error
- func WithLogFile(logfile string) func(*AServer) error
- func WithLogger(logger Logger) func(*AServer) error
- func WithMaxConcurrent(m int) func(*AServer) error
- func WithSEid(seid uint32) func(*AServer) error
- func WithStrictSlash(s bool) func(*AServer) error
- func WithTLS(t bool) func(*AServer) error
- func WithTLSCertFile(certfile string) func(*AServer) error
- func WithTLSKeyFile(keyfile string) func(*AServer) error
- func WithTLSStrongCiphers(c bool) func(*AServer) error
- func WithTestHandler(t bool) func(*AServer) error
- type AServer
- func (e *AServer) AddHeader(key, value string)
- func (e *AServer) AddRoute(route Route)
- func (e *AServer) AddRoutes(routes Routes)
- func (e *AServer) Handler401(r *http.Request) Response
- func (e *AServer) Handler404(r *http.Request) Response
- func (e *AServer) Handler405(r *http.Request) Response
- func (e *AServer) HandlerHealth(r *http.Request) Response
- func (e *AServer) HandlerTest(r *http.Request) Response
- func (e *AServer) Start() error
- func (e *AServer) Stop() error
- func (e *AServer) Wrapper(handlerName string, hFunc Handler) http.Handler
- type Handler
- type Header
- type Headers
- type Logger
- type LoggerFields
- type Response
- type Route
- type Routes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithDefaultHeaders ¶
func WithDownFile ¶
func WithHTTPIdleTimeout ¶
func WithHTTPTimeout ¶
func WithHealthHandler ¶
func WithListen ¶
func WithLogFile ¶
func WithLogger ¶
func WithMaxConcurrent ¶
func WithStrictSlash ¶
func WithTLSCertFile ¶
func WithTLSKeyFile ¶
func WithTLSStrongCiphers ¶
func WithTestHandler ¶
Types ¶
type AServer ¶
type AServer struct { Headers Headers Routes Routes Listen string HTTPTimeout int HTTPIdleTimeout int MaxConcurrent int LogFile string // Optional, defaults to stdout DownFile string HealthHandler bool TestHandler bool StrictSlash bool DefaultHeaders bool TLS bool TLSCertFile string TLSKeyFile string TLSStrongCiphers bool Debug bool Logger Logger // Our logger interface for compatibility SEid uint32 // Event ID for logging // contains filtered or unexported fields }
func (*AServer) HandlerHealth ¶
HandlerHealth implements a health check for load balancers, etc.
func (*AServer) HandlerTest ¶
HandlerTest accepts an optional 'id' variable and echos it back This is an example of a handler that can receive a variable in the URL or not Note that two routes are defined in routes.go, one with the variable and one without
type Logger ¶
type Logger interface { Debug(eid uint32, msg string, fields map[string]interface{}) Info(eid uint32, msg string, fields map[string]interface{}) Warning(eid uint32, msg string, fields map[string]interface{}) Error(eid uint32, msg string, fields map[string]interface{}) Fatal(eid uint32, msg string, fields map[string]interface{}) }
Logger is an interface that defines the logging methods and is compatible with log.Logger
type LoggerFields ¶
type LoggerFields map[string]interface{}
LoggerFields is a map of key/value pairs for logging
type Response ¶
type Response struct { Status string `json:"status"` // Text Status Code int `json:"code"` // HTTP status code Details string `json:"details,omitempty"` // optional response details Data any `json:"data,omitempty"` // any is the new interface{} }
Response provides a consistent format for API responses Data is used to hold an appropriate structure