webserver

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 25, 2021 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package webserver contains the webserver which deals with processing requests from the user, presenting him with the interface of the application.

Index

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

func NewCreateQRTokenHandler(needsAuth bool, auth config.Auth) http.Handler

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

func NewGzipHandler(handler http.Handler, exceptions []string) http.Handler

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

func NewLoginHandler(auth config.Auth) http.Handler

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 NewLoginTokenHandler added in v1.3.0

func NewLoginTokenHandler(auth config.Auth) http.Handler

NewLoginTokenHandler returns a new login handler which will use the information in auth for deciding when device or program was logged in correctly by entering username and password.

func NewLogoutHandler added in v1.2.0

func NewLogoutHandler() http.Handler

NewLogoutHandler returns a handler which will logout the user form his HTTP session by unsetting his session cookie.

func NewRigisterTokenHandler added in v1.3.0

func NewRigisterTokenHandler() http.Handler

NewRigisterTokenHandler returns a handler resposible for checking and eventually registering registering in the database token generated to a device. !TODO: actually store the device token in the database once it has a unique ID

func NewTemplateHandler added in v1.2.1

func NewTemplateHandler(tpl *template.Template, title string) http.Handler

NewTemplateHandler returns a handler which will execute the page template inside the layout template.

func NewTerryHandler added in v1.0.1

func NewTerryHandler(handler http.Handler) http.Handler

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,
	httpRootFS fs.FS,
	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 ArtstImageHandler added in v1.4.0

type ArtstImageHandler struct {
	// contains filtered or unexported fields
}

ArtstImageHandler is a http.Handler which provides CRUD operations for artist images.

func NewArtistImagesHandler added in v1.4.0

func NewArtistImagesHandler(
	am library.ArtistImageManager,
) *ArtstImageHandler

NewArtistImagesHandler returns a new Artist image handler. It needs an implementation of the ArtistImageManager.

func (ArtstImageHandler) ServeHTTP added in v1.4.0

func (aih ArtstImageHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request)

ServeHTTP is required by the http.Handler's interface

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 FSTemplates added in v1.4.0

type FSTemplates struct {
	// contains filtered or unexported fields
}

FSTemplates is Templates implementation which uses fs.FS to extract template data.

func NewFSTemplates added in v1.4.0

func NewFSTemplates(fs fs.FS) *FSTemplates

NewFSTemplates returns a new FSTemplates which will use the argument fs.FS for finding and reading files.

func (*FSTemplates) All added in v1.4.0

func (t *FSTemplates) All() (*AllTemplates, error)

All implements the Templates interface.

func (*FSTemplates) Get added in v1.4.0

func (t *FSTemplates) Get(path string) (*template.Template, error)

Get implements Templates for the box in FSTemplates.

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 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 represents our web server. It will be controlled from here

func NewServer

func NewServer(
	ctx context.Context,
	cfg config.Config,
	lib *library.LocalLibrary,
	httpRootFS fs.FS,
	htmlTemplatesFS fs.FS,
) *Server

NewServer Returns a new Server using the supplied configuration cfg. The returned server is ready and calling its Serve method will start it.

func (*Server) Serve

func (srv *Server) Serve()

Serve actually starts the webserver. It attaches all the handlers and starts the webserver while consulting the ServerConfig supplied. Trying to call this method more than once for the same server will result in panic.

func (*Server) Stop

func (srv *Server) Stop()

Stop stops the webserver

func (*Server) Wait

func (srv *Server) Wait()

Wait syncs whoever called this with the server's stop

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.

Jump to

Keyboard shortcuts

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