Documentation ¶
Index ¶
- Constants
- func AddCORS(next http.Handler) http.Handler
- func AddHTMLHeaders(next http.Handler) http.Handler
- func AddJSONHeaders(next http.Handler) http.Handler
- func AddSecureHeaders(next http.Handler) http.Handler
- func Getenv(k, v string) string
- func Parse1123(s string) time.Time
- func Preflight(w http.ResponseWriter, r *http.Request)
- func RealRFC1122Time(t time.Time) string
- type Server
- func (srv *Server) AddStartHook(h StartHook)
- func (srv *Server) AddStopHook(h StopHook)
- func (srv *Server) Init()
- func (srv *Server) InitMiddleware()
- func (srv *Server) InitRouter()
- func (srv *Server) Route(pattern string, fn func(r chi.Router)) chi.Router
- func (srv *Server) ServeFile(w http.ResponseWriter, r *http.Request, name string)
- func (srv *Server) Start() error
- func (srv *Server) Static(w http.ResponseWriter, r *http.Request)
- func (srv *Server) Stop()
- func (srv *Server) Use(middlewares ...func(http.Handler) http.Handler)
- func (srv *Server) WebGet(pattern string, handler http.HandlerFunc)
- func (srv *Server) WebGets(pattern string, fn func(r chi.Router))
- func (srv *Server) WebPost(pattern string, handler http.HandlerFunc)
- type StartHook
- type StopHook
Constants ¶
const ( // WEBHOST default WEBHOST = "127.0.0.1" // WEBPORT default WEBPORT = "80" // WEBSTATIC default WEBSTATIC = "static" )
Variables ¶
This section is empty.
Functions ¶
func AddHTMLHeaders ¶
AddHTMLHeaders for web pages.
func AddJSONHeaders ¶
AddJSONHeaders for JSON responses.
func AddSecureHeaders ¶
AddSecureHeaders for SSL/TLS requests.
func Getenv ¶
Getenv returns a value for key k, or value v if the environment variable is undefined.
func Preflight ¶
func Preflight(w http.ResponseWriter, r *http.Request)
Preflight returns options for REST calls.
func RealRFC1122Time ¶ added in v0.7.0
RealRFC1122Time makes a HTTP header-compatible date string from the supplied time.
Types ¶
type Server ¶
type Server struct { sync.RWMutex sync.WaitGroup http.Server // contains filtered or unexported fields }
Server structure.
func New ¶
func New() *Server
New server init. Reads settings from environment: WEBHOST - default 127.0.0.1 WEBPORT - default 15000 WEBSTATIC - default "./static/"
func (*Server) AddStartHook ¶ added in v0.8.0
AddStartHook takes a hook function to run before the server starts. You may also return an error, which makes the server fail launch. Hooks are executed in the order they were added.
func (*Server) AddStopHook ¶ added in v0.8.0
AddStopHook takes a hook function to run before the server stops. Hooks are executed in the order they were added.
func (*Server) InitMiddleware ¶
func (srv *Server) InitMiddleware()
InitMiddleware sets up basic middleware on the root web route. These are RealIP and RequestID from chi, a logger for visits and HTML headers.
func (*Server) InitRouter ¶
func (srv *Server) InitRouter()
InitRouter creates the default root router which loads files from the WEBSTATIC path.
func (*Server) ServeFile ¶
ServeFile serves a file from the WEBSTATIC path. NOTE: The server needs to be reloaded if the environment somehow changes.
func (*Server) Static ¶
func (srv *Server) Static(w http.ResponseWriter, r *http.Request)
Static page serving.
func (*Server) WebGet ¶
func (srv *Server) WebGet(pattern string, handler http.HandlerFunc)
WebGet adds a GET route matching the specified pattern.