admin

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 26 Imported by: 6

README

http-admin

Utility admin server for Go

Documentation

Overview

Package admin implements an HTTP server providing useful information & tools about this server.

Index

Constants

This section is empty.

Variables

View Source
var (
	ProcessInfoGroup = "Process Info"
	PerfProfileGroup = "Performance Profile"
	UtilitiesGroup   = "Utilities"
	MetricsGroup     = "Metrics"
)

Top level groups for the Sidebar nav

View Source
var (
	RootPath    = "/"
	AdminPath   = "/admin"
	ClientsPath = AdminPath + "/clients/"
	ServersPath = AdminPath + "/servers/"
	FilesPath   = AdminPath + "/files/"
)

Well known paths

View Source
var DefaultAdminHTTPServer = &HTTPServer{}

DefaultAdminHTTPServer is the global admin http server.

Gatherer is the thing we gather metrics from.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDigest

func AssetDigest(name string) ([sha256.Size]byte, error)

AssetDigest returns the digest of the file with the given name. It returns an error if the asset could not be found or the digest could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"}, AssetDir("data/img") would return []string{"a.png", "b.png"}, AssetDir("foo.txt") and AssetDir("notexist") would return an error, and AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func AssetString

func AssetString(name string) (string, error)

AssetString returns the asset contents as a string (instead of a []byte).

func Digests

func Digests() (map[string][sha256.Size]byte, error)

Digests returns a map of all known files and their checksums.

func LoggingHandler

func LoggingHandler(writer http.ResponseWriter, request *http.Request)

LoggingHandler returns the current state of all loggers that we know about.

func MetricQueryHandler

func MetricQueryHandler(w http.ResponseWriter, r *http.Request)

MetricQueryHandler either renders the list of all metrics and a graph, or returns the queried metrics' current values.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func MustAssetString

func MustAssetString(name string) string

MustAssetString is like AssetString but panics when Asset would return an error. It simplifies safe initialization of global variables.

func PingHandler

func PingHandler(w http.ResponseWriter, r *http.Request)

PingHandler serves a very simple response that can be used as a health check.

func RedirectHandler

func RedirectHandler(url string, code int) http.Handler

RedirectHandler avoids the default behaviour of writing random html into the response.

func ResourceHandler

func ResourceHandler(baseRequestPath, baseResourcePath string) http.Handler

ResourceHandler returns the asset, relative to the given paths.

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory.

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively.

func Serve

func Serve(opts Opts)

Serve starts the HTTPServer.

func ServeOnce

func ServeOnce(opts Opts)

ServeOnce starts the HTTPServer, but only once.

func SummaryHandler

func SummaryHandler(w http.ResponseWriter, r *http.Request)

SummaryHandler renders the front-page content.

func UpdateLoggingHandler

func UpdateLoggingHandler(writer http.ResponseWriter, request *http.Request)

UpdateLoggingHandler associates a new log level with a given module. There is no way of telling if the module has a custom level or if it is "falling back" to the root module, so this does nothing clever.

Types

type HTTPServer

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

HTTPServer is a holder for the router and server involved in serving the admin UI.

type Logger

type Logger interface {
	Debugf(msg string, args ...interface{})
	Infof(msg string, args ...interface{})
	Warningf(msg string, args ...interface{})
	Errorf(msg string, args ...interface{})
}

A Logger is the interface we log to.

type LoggerInfo

type LoggerInfo interface {
	// ModuleLevels returns a map of all known modules and their level
	ModuleLevels() map[string]logging.Level
	// SetLevel sets the level of a logging module.
	SetLevel(level logging.Level, module string)
}

LoggerInfo is the interface we need from something that can describe & update log levels.

type Opts

type Opts struct {
	Disabled bool       `long:"disabled" description:"If true, the admin server will never start." env:"ADMIN_DISABLE_HTTP"`
	Host     string     `long:"host" description:"The host to listen on."`
	Port     int        `long:"port" default:"9990" description:"The port to listen on."`
	Logger   Logger     `no-flag:"true"`
	LogInfo  LoggerInfo `no-flag:"true"`
}

Opts is all flags associated with the admin HTTP server.

type Route

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

Route represents a path and a handler, making it possible to display a menu of routes in the UI.

Directories

Path Synopsis
Package main implements a simple binary that
Package main implements a simple binary that

Jump to

Keyboard shortcuts

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