webserver

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: GPL-3.0 Imports: 22 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 func(http.ResponseWriter, *http.Request) error)

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 NewGzipHandler

func NewGzipHandler(handler http.Handler) 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 NewTerryHandler added in v1.0.1

func NewTerryHandler(handler http.Handler) http.Handler

NewTerryHandler returns a new TerryHandler, ready for use.

Types

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 BasicAuthHandler

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

BasicAuthHandler is a handler wrapper used for basic authenticate. Its only job is to do the authentication and then pass the work to the Handler it wraps around

func (BasicAuthHandler) ServeHTTP

func (hl BasicAuthHandler) 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 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

func NewServer(ctx context.Context, cfg config.Config, lib library.Library) *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 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