Documentation ¶
Overview ¶
Package webserver contains the webserver which deals with processing requests from the user, presenting him with the interface of the application.
Index ¶
- func InternalErrorOnErrorHandler(writer http.ResponseWriter, req *http.Request, fnc HandlerFuncWithError)
- func NewCreateQRTokenHandler(needsAuth bool, auth config.Auth) http.Handler
- func NewGzipHandler(handler http.Handler) http.Handler
- func NewLoginHandler(auth config.Auth) http.Handler
- func NewLogoutHandler() http.Handler
- func NewTemplateHandler(tpl *template.Template, title string) http.Handler
- func NewTerryHandler(handler http.Handler) http.Handler
- func WithInternalError(fnc HandlerFuncWithError) http.HandlerFunc
- type AlbumArtworkHandler
- type AlbumHandler
- type AllTemplates
- type AuthHandler
- type BrowseHandler
- type FileHandler
- type GzipHandler
- type HandlerFuncWithError
- type PackrTemplates
- type SearchHandler
- type Server
- type Templates
- type TerryHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InternalErrorOnErrorHandler ¶
func InternalErrorOnErrorHandler(writer http.ResponseWriter, req *http.Request, fnc HandlerFuncWithError)
InternalErrorOnErrorHandler is used to wrap around handlers-like functions which just return error. This function actually writes the HTTP error and renders the error in the html.
func NewCreateQRTokenHandler ¶ added in v1.2.1
NewCreateQRTokenHandler returns a http.Handler which will generate an access token in a QR bar code and serve it as a png image as a response. In the bar code the server address from the query value "address" is included.
func NewGzipHandler ¶
NewGzipHandler returns GzipHandler which will gzip anything written in the supplied handler. Must be the main handler given to the net.Server
func NewLoginHandler ¶ added in v1.2.0
NewLoginHandler returns a new login handler which will use the information in auth for deciding when user has logged in correctly and also for generating tokens.
func NewLogoutHandler ¶ added in v1.2.0
NewLogoutHandler returns a handler which will logout the user form his HTTP session by unsetting his session cookie.
func NewTemplateHandler ¶ added in v1.2.1
NewTemplateHandler returns a handler which will execute the page template inside the layout template.
func NewTerryHandler ¶ added in v1.0.1
NewTerryHandler returns a new TerryHandler, ready for use.
func WithInternalError ¶ added in v1.2.0
func WithInternalError(fnc HandlerFuncWithError) http.HandlerFunc
WithInternalError converts HandlerFuncWithError to http.HandlerFunc by making sure all errors returned are flushed to the writer and Internal Server Error HTTP status is sent.
Types ¶
type AlbumArtworkHandler ¶ added in v1.2.0
type AlbumArtworkHandler struct {
// contains filtered or unexported fields
}
AlbumArtworkHandler is a http.Handler which will find and serve the artwork of a particular album.
func NewAlbumArtworkHandler ¶ added in v1.2.0
func NewAlbumArtworkHandler( am library.ArtworkManager, rootBox packr.Box, notFoundImagePath string, ) *AlbumArtworkHandler
NewAlbumArtworkHandler returns a new Album artwork handler. It needs an implementaion of the ArtworkManager.
func (AlbumArtworkHandler) ServeHTTP ¶ added in v1.2.0
func (aah AlbumArtworkHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
ServeHTTP is required by the http.Handler's interface
type AlbumHandler ¶
type AlbumHandler struct {
// contains filtered or unexported fields
}
AlbumHandler is a http.Handler which will find and serve a zip of the album by the album ID.
func NewAlbumHandler ¶
func NewAlbumHandler(lib library.Library) *AlbumHandler
NewAlbumHandler returns a new Album handler. It needs a library to search in
func (AlbumHandler) ServeHTTP ¶
func (fh AlbumHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
ServeHTTP is required by the http.Handler's interface
type AllTemplates ¶ added in v1.2.1
type AllTemplates struct {
// contains filtered or unexported fields
}
AllTemplates is a structure which contains all parsed templates for different pages. They are ready for usage in http handlers which return HTML.
type AuthHandler ¶ added in v1.2.0
type AuthHandler struct {
// contains filtered or unexported fields
}
AuthHandler is a handler wrapper used for authenticaation. Its only job is to do the authentication and then pass the work to the Handler it wraps around. Possible methods for authentication:
- Basic Auth with the username and password
- Authorization Bearer JWT token
- JWT token in a session cookie
- JWT token as a query string
Basic auth is preserved for backward compatibility. Needless to say, it so not a prefered method for authentication.
func (*AuthHandler) ServeHTTP ¶ added in v1.2.0
func (hl *AuthHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface and does the actual basic authenticate check for every request
type BrowseHandler ¶ added in v1.1.0
type BrowseHandler struct {
// contains filtered or unexported fields
}
BrowseHandler is a http.Handler which will allow you to browse through artists or albums with the help of pagination.
func NewBrowseHandler ¶ added in v1.1.0
func NewBrowseHandler(lib library.Library) *BrowseHandler
NewBrowseHandler returns a new Browse handler. It needs a library to browse through.
func (BrowseHandler) ServeHTTP ¶ added in v1.1.0
func (bh BrowseHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
ServeHTTP is required by the http.Handler's interface
type FileHandler ¶
type FileHandler struct {
// contains filtered or unexported fields
}
FileHandler will find and serve a media file by its ID
func NewFileHandler ¶
func NewFileHandler(lib library.Library) *FileHandler
NewFileHandler returns a new File handler will will be resposible for serving a file from the library identified from its ID.
func (FileHandler) ServeHTTP ¶
func (fh FileHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
ServeHTTP is required by the http.Handler's interface
type GzipHandler ¶
type GzipHandler struct {
// contains filtered or unexported fields
}
GzipHandler gzips our output using a custom Writer. It will check if gzip is among the accepted encodings and gzip if so. Otherwise it will do nothing.
func (GzipHandler) ServeHTTP ¶
func (gzh GzipHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
ServeHTTP satisfies the http.Handler interface
type HandlerFuncWithError ¶ added in v1.2.0
type HandlerFuncWithError func(http.ResponseWriter, *http.Request) error
HandlerFuncWithError is similar to http.HandlerFunc but returns an error when the handling of the request failed.
type PackrTemplates ¶ added in v1.2.0
type PackrTemplates struct {
// contains filtered or unexported fields
}
PackrTemplates is Templates implementation which uses packr.Box to extract template data.
func NewPackrTemplates ¶ added in v1.2.0
func NewPackrTemplates(box packr.Box) *PackrTemplates
NewPackrTemplates returns a new PackrTemplates which will use the argument box for finding and reading files.
func (*PackrTemplates) All ¶ added in v1.2.1
func (t *PackrTemplates) All() (*AllTemplates, error)
All implements the Templates interface.
type SearchHandler ¶
type SearchHandler struct {
// contains filtered or unexported fields
}
SearchHandler is a http.Handler responsible for search requests. It will use the Library to return a list of matched files to the interface.
func NewSearchHandler ¶
func NewSearchHandler(lib library.Library) *SearchHandler
NewSearchHandler returns a new SearchHandler for processing search queries. They will be run against the supplied library
func (SearchHandler) ServeHTTP ¶
func (sh SearchHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
ServeHTTP is required by the http.Handler's interface
type Server ¶
type Server struct { // Makes the server lockable. This lock should be used for accessing the // listener sync.Mutex // contains filtered or unexported fields }
Server represends our webserver. It will be controlled from here
func NewServer ¶
NewServer Returns a new Server using the supplied configuration cfg. The returned server is ready and calling its Serve method will start it.
type Templates ¶ added in v1.2.0
type Templates interface { // Get find and parses a template based on its file name. Get(path string) (*template.Template, error) // All returns a struct which contains all templates in // non-exported attributes. All() (*AllTemplates, error) }
Templates is a type which knows how to find and parse HTML templates by their name.
type TerryHandler ¶ added in v1.0.1
type TerryHandler struct {
// contains filtered or unexported fields
}
TerryHandler adds the X-Clacks-Overhead header. It wraps around the actual handler.
func (TerryHandler) ServeHTTP ¶ added in v1.0.1
func (th TerryHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
ServeHTTP satisfies the http.Handler interface.