zap

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Afero = &afero.Afero{Fs: afero.NewOsFs()}

Afero is a filesystem wrapper providing util methods and easy test mocks.

Functions

func ExpandPath added in v1.4.0

func ExpandPath(c *gabs.Container, token *list.Element, res *bytes.Buffer)

ExpandPath takes a Config, list of tokens (parsed from request) and the results buffer At each level of recursion, it matches the token to the action described in the Config, and writes it to the result buffer. There is special care needed to handle slashes correctly, which makes this function quite nontrivial. Tests are crucial to ensure correctness.

func HealthHandler

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

HealthHandler responds to /healthz request.

func IndexHandler

func IndexHandler(ctx *Context, w http.ResponseWriter, r *http.Request) (int, error)

IndexHandler handles all the non status expansions.

func MakeReloadCallback

func MakeReloadCallback(c *Context, configName string) func()

MakeReloadCallback returns a func that that reads the config file and updates global state.

func ParseYaml

func ParseYaml(fname string) (*gabs.Container, error)

ParseYaml takes a file name and returns a gabs Config object.

func UpdateHosts

func UpdateHosts(c *Context)

TODO: add tests. simulate touching a file. UpdateHosts will attempt to write the zap list of shortcuts to /etc/hosts. It will gracefully fail if there are not enough permissions to do so.

func ValidateConfig

func ValidateConfig(c *gabs.Container) error

ValidateConfig verifies that there are no unexpected values in the Config file. at each level of the Config, we should either have a KV for expansions, or a leaf node with the values oneof "expand", "query", "ssl_off" that map to a string.

func VarsHandler

func VarsHandler(c *Context, w http.ResponseWriter, r *http.Request) (int, error)

VarsHandler responds to /varz request and prints Config.

func WatchConfigFileChanges

func WatchConfigFileChanges(watcher *fsnotify.Watcher, fname string, cb func())

WatchConfigFileChanges will attach an fsnotify watcher to the config file, and trigger the cb function when the file is updated.

Types

type Context

type Context struct {
	// Config is a Json container with path configs
	Config *gabs.Container

	// ConfigMtx Enables safe hot reloading of Config.
	ConfigMtx sync.Mutex

	// Advertise IP, used in /etc/hosts in case bind address differs.
	Advertise string
}

type CtxWrapper

type CtxWrapper struct {
	*Context
	H func(*Context, http.ResponseWriter, *http.Request) (int, error)
}

func (CtxWrapper) ServeHTTP

func (cw CtxWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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