app

package
v0.0.0-...-a2c9c92 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const CONFIG_FILENAME = "config.yml"
View Source
const (
	HEALTHCHECK_MESSAGE = "All good in the hood"
)

Variables

View Source
var (
	ErrServerNotStarted = fmt.Errorf("server not started")
)

Functions

func ErrFormat

func ErrFormat(message string) []byte

func LoggerAndRecovery

func LoggerAndRecovery(h http.Handler) http.Handler

func MsgFormat

func MsgFormat(key, value string) []byte

func Trim

func Trim(url string) string

func TrimTrailingSlash

func TrimTrailingSlash(next http.Handler) http.Handler

Returns a middleware that trims trailing slashes. If `allSlashes` is `true`, the middlware trims all trailing slashes, otherwise the middleware trims only a single trailing slash

Types

type Config

type Config struct {
	Port           int       `json:"Port"`
	ReadTimeout    int       `json:"ReadTimeout"`
	WriteTimeout   int       `json:"WriteTimeout"`
	MaxHeaderBytes int       `json:"MaxHeaderBytes"`
	Name           *string   `json:"Name"`
	CORS           *[]string `json:"CORS"`
}

func GetConfig

func GetConfig() (Config, error)

Reads parameters from `config.yml` and from env vars. The first time this function is called, the Config struct is cached and subsequent calls will returned the cached copy. There are 3 sources of config info and they are prioritized as follows:

1. (high priority) config from env vars 2. (medium) config from `config.yml` 3. (low) default config, hardcoded into this file

func MergeConfigs

func MergeConfigs(cfg1 Config, cfg2 Config) Config

func ReadConfig

func ReadConfig(filename string) (Config, error)

func ReadEnvVarsConfig

func ReadEnvVarsConfig() Config

type Middleware

type Middleware func(http.Handler) http.Handler

func CORS

func CORS(origins ...string) Middleware

`origins` are some extra origins to add to the OPTIONS response

type Server

type Server struct {
	Name       string
	Router     *mux.Router
	Config     Config
	Middleware []Middleware
	// contains filtered or unexported fields
}

func New

func New(config Config) *Server

func NewNoHandlers

func NewNoHandlers(router *mux.Router, config Config) *Server

func (*Server) Attach

func (s *Server) Attach(stuff ...interface{})

`stuff` is of type `controllers.Controller` or `Middleware` or a slice of either

func (*Server) AttachController

func (s *Server) AttachController(controller controllers.Controller)

func (*Server) AttachControllers

func (s *Server) AttachControllers(controllers ...controllers.Controller)

func (*Server) AttachMiddleware

func (s *Server) AttachMiddleware(middleware Middleware)

func (*Server) AttachMiddlewares

func (s *Server) AttachMiddlewares(middlewares ...Middleware)

func (*Server) Port

func (s *Server) Port() int

Returns the port that this server has been configured to run on

func (*Server) Run

func (s *Server) Run()

Runs the server asychronously

func (*Server) RunWithCancel

func (s *Server) RunWithCancel() context.CancelFunc

Runs the server asynchronously, with a cancel function to shutdown the server

func (*Server) Stop

func (s *Server) Stop() error

func (*Server) Wait

func (s *Server) Wait() <-chan error

Jump to

Keyboard shortcuts

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