http

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2018 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STANDARD RequestType = iota
	MIRRORLIST
	FILESTATS
	MIRRORSTATS
	CHECKSUM

	UNDEFINED SecureOption = iota
	WITHTLS
	WITHOUTTLS
)

Variables

View Source
var (
	// ErrTemplatesNotFound is returned cannot be loaded
	ErrTemplatesNotFound = errors.New("please set a valid path to the templates directory")
)

Functions

func NewGzipHandler

func NewGzipHandler(fn http.HandlerFunc) http.HandlerFunc

NewGzipHandler is an HTTP handler used to compress responses if supported by the client

Types

type Context

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

Context represents the context of a request

func NewContext

func NewContext(w http.ResponseWriter, r *http.Request, t Templates) *Context

NewContext returns a new instance of Context

func (*Context) IsChecksum

func (c *Context) IsChecksum() bool

IsChecksum returns true if a checksum has been requested

func (*Context) IsFileStats

func (c *Context) IsFileStats() bool

IsFileStats returns true if the file stats has been requested

func (*Context) IsMirrorStats

func (c *Context) IsMirrorStats() bool

IsMirrorStats returns true if the mirror stats has been requested

func (*Context) IsMirrorlist

func (c *Context) IsMirrorlist() bool

IsMirrorlist returns true if the mirror list has been requested

func (*Context) IsPretty

func (c *Context) IsPretty() bool

IsPretty returns true if the pretty json has been requested

func (*Context) QueryParam

func (c *Context) QueryParam(key string) string

QueryParam returns the value associated with the given query parameter

func (*Context) Request

func (c *Context) Request() *http.Request

Request returns the underlying http.Request of the current request

func (*Context) ResponseWriter

func (c *Context) ResponseWriter() http.ResponseWriter

ResponseWriter returns the underlying http.ResponseWriter of the current request

func (*Context) SecureOption

func (c *Context) SecureOption() SecureOption

SecureOption returns the selected secure option

func (*Context) Templates

func (c *Context) Templates() Templates

Templates returns the instance of precompiled templates

func (*Context) Type

func (c *Context) Type() RequestType

Type returns the type of the current request

type DefaultEngine

type DefaultEngine struct{}

DefaultEngine is the default algorithm used for mirror selection

func (DefaultEngine) Selection

func (h DefaultEngine) Selection(ctx *Context, cache *mirrors.Cache, fileInfo *filesystem.FileInfo, clientInfo network.GeoIPRecord) (mlist mirrors.Mirrors, excluded mirrors.Mirrors, err error)

Selection returns an ordered list of selected mirror, a list of rejected mirrors and and an error code

type HTTP

type HTTP struct {
	Listener *net.Listener

	Restarting bool
	// contains filtered or unexported fields
}

HTTP represents an instance of the HTTP webserver

func HTTPServer

func HTTPServer(redis *database.Redis, cache *mirrors.Cache) *HTTP

HTTPServer is the constructor of the HTTP server

func (*HTTP) LoadTemplates

func (h *HTTP) LoadTemplates(name string) (t *template.Template, err error)

LoadTemplates pre-loads templates from the configured template directory

func (*HTTP) Reload

func (h *HTTP) Reload()

Reload the configuration

func (*HTTP) RunServer

func (h *HTTP) RunServer() (err error)

RunServer is the main function used to start the HTTP server

func (*HTTP) SetListener

func (h *HTTP) SetListener(l net.Listener)

SetListener can be used to set a different listener that should be used by the HTTP server. This is primarily used during seamless binary upgrade.

func (*HTTP) Stop

func (h *HTTP) Stop(timeout time.Duration)

Stop gracefully stops the HTTP server with a timeout to let the remaining connections finish

func (*HTTP) StopChan

func (h *HTTP) StopChan() <-chan struct{}

StopChan returns a channel that notifies when the server is stopped

func (*HTTP) Terminate

func (h *HTTP) Terminate()

Terminate terminates the current HTTP server gracefully

type JSONRenderer

type JSONRenderer struct{}

JSONRenderer is used to render JSON formatted details about the current request

func (*JSONRenderer) Type

func (w *JSONRenderer) Type() string

Type returns the type of renderer

func (*JSONRenderer) Write

func (w *JSONRenderer) Write(ctx *Context, results *mirrors.Results) (statusCode int, err error)

Write is used to write the result to the ResponseWriter

type MirrorListRenderer

type MirrorListRenderer struct{}

MirrorListRenderer is used to render the mirrorlist page using the HTML templates

func (*MirrorListRenderer) Type

func (w *MirrorListRenderer) Type() string

Type returns the type of renderer

func (*MirrorListRenderer) Write

func (w *MirrorListRenderer) Write(ctx *Context, results *mirrors.Results) (statusCode int, err error)

Write is used to write the result to the ResponseWriter

type MirrorStats

type MirrorStats struct {
	ID         int
	Name       string
	Downloads  int64
	Bytes      int64
	PercentD   float32
	PercentB   float32
	SyncOffset SyncOffset
}

MirrorStats contains the stats of a given mirror

type MirrorStatsPage

type MirrorStatsPage struct {
	List        []MirrorStats
	MirrorList  []mirrors.Mirror
	LocalJSPath string
}

MirrorStatsPage contains the values needed to generate the mirrorstats page

type RedirectRenderer

type RedirectRenderer struct{}

RedirectRenderer is a basic renderer that redirects the user to the first mirror in the list

func (*RedirectRenderer) Type

func (w *RedirectRenderer) Type() string

Type returns the type of renderer

func (*RedirectRenderer) Write

func (w *RedirectRenderer) Write(ctx *Context, results *mirrors.Results) (statusCode int, err error)

Write is used to write the result to the ResponseWriter

type RequestType

type RequestType int

RequestType defines the type of the request

type SecureOption

type SecureOption int

SecureOption is the type that defines TLS requirements

type Stats

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

Stats is the internal structure for the download stats

func NewStats

func NewStats(redis *database.Redis) *Stats

NewStats returns an instance of the stats counter

func (*Stats) CountDownload

func (s *Stats) CountDownload(m mirrors.Mirror, fileinfo filesystem.FileInfo) error

CountDownload is a lightweight method used to count a new download for a specific file and mirror

func (*Stats) Terminate

func (s *Stats) Terminate()

Terminate stops the stats handler and commit results to the database

type StatsFileNow

type StatsFileNow struct {
	Today int64
	Month int64
	Year  int64
	Total int64
}

StatsFileNow is the structure containing the latest stats of a file

type StatsFilePeriod

type StatsFilePeriod struct {
	Period    string
	Downloads int64
}

StatsFilePeriod is the structure containing the stats for the given period

type SyncOffset

type SyncOffset struct {
	Valid         bool
	Value         int // in hours
	HumanReadable string
}

SyncOffset contains the time offset between the mirror and the local repository

type Templates

type Templates struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

Templates is a struct embedding instances of the precompiled templates

Jump to

Keyboard shortcuts

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