Documentation ¶
Index ¶
- Variables
- type FileStore
- type Logger
- type MemoryStore
- type Option
- type Response
- type Service
- func (s Service) HTMLHandler(h http.Handler) http.Handler
- func (s Service) JSONHandler(h http.Handler) http.Handler
- func (s Service) OffHandler(w http.ResponseWriter, r *http.Request)
- func (s Service) OnHandler(w http.ResponseWriter, r *http.Request)
- func (s Service) StatusHandler(w http.ResponseWriter, r *http.Request)
- func (s Service) TextHandler(h http.Handler) http.Handler
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( HTMLContentType = "text/html; charset=utf-8" TextContentType = "text/text; charset=utf-8" JSONContentType = "application/json; charset=utf-8" )
Values for HTTP Contet-Type header.
Functions ¶
This section is empty.
Types ¶
type FileStore ¶
type FileStore struct {
// contains filtered or unexported fields
}
FileStore implements Store that manages maintenance status by existence of a specific file. If file exists maintenance is enabled, otherwise is disabled. This store persists maintenance state and provides a simple way to set maintenance on local filesystem with external tools.
func NewFileStore ¶
NewFileStore creates a new instance of FileStore.
type Logger ¶
type Logger interface { Infof(format string, a ...interface{}) Errorf(format string, a ...interface{}) }
Logger defines methods required for logging.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore implements Store that keeps data in memory.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new instance of MemoryStore.
func (*MemoryStore) Off ¶
func (s *MemoryStore) Off() (changed bool, err error)
Off disables maintenance.
func (*MemoryStore) On ¶
func (s *MemoryStore) On() (changed bool, err error)
On enables maintenance.
func (*MemoryStore) Status ¶
func (s *MemoryStore) Status() (on bool, err error)
Status returns true if maintenance is enabled.
type Option ¶
type Option func(*Service)
Option is a function that sets optional parameters to the Handler.
func WithLogger ¶
WithLogger sets the function that will perform message logging. Default is log.Printf.
type Response ¶
type Response struct { // Body will be returned if Handler is nil. Body string Handler http.Handler }
Response holds configuration for HTTP response during maintenance mode.
type Service ¶
type Service struct { HTML Response JSON Response Text Response // contains filtered or unexported fields }
Service implements http.Service interface to write a custom HTTP response during maintenance mode. It also provides JSON API handlers that can be used to check, set and remove maintenance mode.
func New ¶
New creates a new instance of Handler. The first argument is the handler that will be executed when maintenance mode is off.
func (Service) HTMLHandler ¶
HTMLHandler is a HTTP middleware that should be used alongide HTML pages.
func (Service) JSONHandler ¶
JSONHandler is a HTTP middleware that should be used alongide JSON-encoded responses.
func (Service) OffHandler ¶
func (s Service) OffHandler(w http.ResponseWriter, r *http.Request)
OffHandler can be used in JSON-encoded HTTP API to disable maintenance.
func (Service) OnHandler ¶
func (s Service) OnHandler(w http.ResponseWriter, r *http.Request)
OnHandler can be used in JSON-encoded HTTP API to enable maintenance. It returns HTTP Status Created if the maintenance is enabled. If the maintenance is already enabled, it returns HTTP Status OK.
func (Service) StatusHandler ¶
func (s Service) StatusHandler(w http.ResponseWriter, r *http.Request)
StatusHandler can be used in JSON-encoded HTTP API to check the status of maintenance.
type Store ¶
type Store interface { // Return true if maintenance is enabled. Status() (on bool, err error) // Enable maintenance and returns true if the state has changed. On() (changed bool, err error) // Disables maintenance and returns true if the state has changed. Off() (changed bool, err error) }
Store defines methods that are reqired to check, set and remove information wheather the maintenance is on of off. Usually only one boolean value is needed to be stored