appserver

package
v0.0.0-...-26c6371 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package appserver provides a Server structure that let's you package things you need all around your service (e.g. configuration, HTTP mgmt, logging, routing, etc.)

Package appserver provides a Server structure that let's you package things you need all around your service (e.g. configuration, HTTP mgmt, logging, routing, etc.)

Index

Constants

This section is empty.

Variables

View Source
var (
	// Commit current build commit set by build script
	Commit = "0"
	// BuildTime set by build script in ISO 8601 (UTC) format:
	// YYYY-MM-DDThh:mm:ssTZD (see https://www.w3.org/TR/NOTE-datetime for
	// details)
	BuildTime = "0"
	// StartTime in ISO 8601 (UTC) format
	StartTime = time.Now().UTC().Format("2006-01-02T15:04:05Z")
)

Functions

func CalculateCloneDir

func CalculateCloneDir(gitSparseCheckoutSet []string, revisionOrTag string) string

CalculateCloneDir TBD

Types

type AppServer

type AppServer struct {
	CacheCleaner     *TickerTool
	GitMirrorUpdater *TickerTool
	// contains filtered or unexported fields
}

AppServer is an HTTP server

func New

func New(config *configuration.Registry) (*AppServer, error)

New creates a new AppServer object

func NewDefaultOrPanic

func NewDefaultOrPanic() *AppServer

NewDefaultOrPanic returns a server with a default configuration or panics if there is an error

func (*AppServer) Config

func (srv *AppServer) Config() *configuration.Registry

Config returns the app server's config object

func (*AppServer) DebugLog

func (srv *AppServer) DebugLog() *log.Logger

Config returns the app server's debug logger

func (*AppServer) ErrLog

func (srv *AppServer) ErrLog() *log.Logger

Config returns the app server's error logger

func (*AppServer) GetRegisteredRoutes

func (srv *AppServer) GetRegisteredRoutes() (string, error)

GetRegisteredRoutes returns all registered routes formatted with their methods, paths, queries and names. It is a good idea to print this information on server start to give you an idea of what routes are available in the system.

func (*AppServer) HTTPServer

func (srv *AppServer) HTTPServer() *http.Server

HTTPServer returns the app server's HTTP server

func (*AppServer) HandleArchive

func (srv *AppServer) HandleArchive() http.HandlerFunc

HandleArchive does the heavy lifting on each request. TODO(kwk): document me TODO(kwk): Forward to github when s=/ or s=. ?

func (*AppServer) HandleStatus

func (srv *AppServer) HandleStatus() http.HandlerFunc

HandleStatus returns the handler function for the /status endpoint

func (*AppServer) InfoLog

func (srv *AppServer) InfoLog() *log.Logger

Config returns the app server's info logger

func (*AppServer) InitGitLocalMirror

func (srv *AppServer) InitGitLocalMirror() chan error

InitGitLocalMirror either clones a the remote git repository into the local diectory pointed to by GetGitLocalMirrorDir(); otherwise the already existing mirror directory is taken. The read/write mutex AppServer.GitMirrorMutex.RLock() will return true once the mirror is ready.

func (*AppServer) Router

func (srv *AppServer) Router() *mux.Router

Router returns the app server's HTTP router

func (*AppServer) Setup

func (srv *AppServer) Setup() error

Setup is a glue function to setup the server in the right way.

func (*AppServer) SetupArchivesCacheDir

func (srv *AppServer) SetupArchivesCacheDir() error

SetupArchivesCacheDir uses or creates the directory in which the server keeps cache files.

func (*AppServer) SetupGitLocalClonesDir

func (srv *AppServer) SetupGitLocalClonesDir() error

SetupGitLocalClonesDir uses or creates the directory in which the server manages the partial git clones with sparse checkouts.

func (*AppServer) SetupRoutes

func (srv *AppServer) SetupRoutes() error

SetupRoutes registers handlers for various URL paths. You can call this function more than once but only the first call will have an effect.

func (*AppServer) Stop

func (srv *AppServer) Stop()

Stop will stop the cache cleaning and git mirror updates

func (*AppServer) WarnLog

func (srv *AppServer) WarnLog() *log.Logger

Config returns the app server's warning logger

type ArchiveMethod

type ArchiveMethod string
const (
	TarXz ArchiveMethod = "tar.xz"
	Zip                 = "zip"
)

type ConcurrentResult

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

type TickerTool

type TickerTool struct {
	// Ticker is a regular ticker
	Ticker *time.Ticker

	// Once is used to prevent setting up the ticker more than once.
	Once sync.Once

	// Done is the channel on which we sent a value in order to exit the go
	// routine in the for-loop executed in ExecuteAtEachTick().
	Done chan bool

	// ErrorChan buffered (size 1) error channel on which the registered tick
	// function (see ExecuteAtEachTick) can report errors.
	ErrorChan chan error

	// If needed here's a mutex to lock the tool
	RWMutex sync.RWMutex
	// contains filtered or unexported fields
}

TickerTool contains everything we need to easily handle repetitive task with a one-time setup.

func NewTickerTool

func NewTickerTool(tickDuration time.Duration) *TickerTool

NewTickerTool returns a ticker tool that has setup the time when the ticker fires.

func (*TickerTool) ExecuteAtEachTick

func (tt *TickerTool) ExecuteAtEachTick(log *log.Logger, fn func(tick time.Time) error)

ExecuteAtEachTick must only be called once. It calls the given function "fn" at each time the ticker ticks.

func (*TickerTool) IsTickFunctionRegistered

func (tt *TickerTool) IsTickFunctionRegistered() bool

IsTickFunctionRegistered returns true if the ExecuteAtEachTick function was already called at least once.

func (*TickerTool) Stop

func (tt *TickerTool) Stop()

Stop stops the ticker update cycle and "aborts early"

Jump to

Keyboard shortcuts

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