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 ¶
- Variables
- func CalculateCloneDir(gitSparseCheckoutSet []string, revisionOrTag string) string
- type AppServer
- func (srv *AppServer) Config() *configuration.Registry
- func (srv *AppServer) DebugLog() *log.Logger
- func (srv *AppServer) ErrLog() *log.Logger
- func (srv *AppServer) GetRegisteredRoutes() (string, error)
- func (srv *AppServer) HTTPServer() *http.Server
- func (srv *AppServer) HandleArchive() http.HandlerFunc
- func (srv *AppServer) HandleStatus() http.HandlerFunc
- func (srv *AppServer) InfoLog() *log.Logger
- func (srv *AppServer) InitGitLocalMirror() chan error
- func (srv *AppServer) Router() *mux.Router
- func (srv *AppServer) Setup() error
- func (srv *AppServer) SetupArchivesCacheDir() error
- func (srv *AppServer) SetupGitLocalClonesDir() error
- func (srv *AppServer) SetupRoutes() error
- func (srv *AppServer) Stop()
- func (srv *AppServer) WarnLog() *log.Logger
- type ArchiveMethod
- type ConcurrentResult
- type TickerTool
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) GetRegisteredRoutes ¶
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 ¶
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) InitGitLocalMirror ¶
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) SetupArchivesCacheDir ¶
SetupArchivesCacheDir uses or creates the directory in which the server keeps cache files.
func (*AppServer) SetupGitLocalClonesDir ¶
SetupGitLocalClonesDir uses or creates the directory in which the server manages the partial git clones with sparse checkouts.
func (*AppServer) SetupRoutes ¶
SetupRoutes registers handlers for various URL paths. You can call this function more than once but only the first call will have an effect.
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 ¶
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"