Documentation ¶
Index ¶
- Constants
- Variables
- func ErrFormat(message string) []byte
- func LoggerAndRecovery(h http.Handler) http.Handler
- func MsgFormat(key, value string) []byte
- func Trim(url string) string
- func TrimTrailingSlash(next http.Handler) http.Handler
- type Config
- type Middleware
- type Server
- func (s *Server) Attach(stuff ...interface{})
- func (s *Server) AttachController(controller controllers.Controller)
- func (s *Server) AttachControllers(controllers ...controllers.Controller)
- func (s *Server) AttachMiddleware(middleware Middleware)
- func (s *Server) AttachMiddlewares(middlewares ...Middleware)
- func (s *Server) Port() int
- func (s *Server) Run()
- func (s *Server) RunWithCancel() context.CancelFunc
- func (s *Server) Stop() error
- func (s *Server) Wait() <-chan error
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 ¶
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 ¶
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 ReadConfig ¶
func ReadEnvVarsConfig ¶
func ReadEnvVarsConfig() Config
type Middleware ¶
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 (*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) RunWithCancel ¶
func (s *Server) RunWithCancel() context.CancelFunc
Runs the server asynchronously, with a cancel function to shutdown the server
Click to show internal directories.
Click to hide internal directories.