expvarplus

package module
v0.0.0-...-6251af2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: MIT Imports: 8 Imported by: 1

README

expvarplus

Build Status

This is not a replacement for expvar, nor is it an opinionated way of how to use expvar, but instead adds some extra stuff to the variables that are already exported (typically to /debug/vars), including:

  • env - a map of safelisted environment variables
  • uptime - some variables related to process uptime including:
    • start_time - time of roughly when the process started (UTC)
    • uptime - start time minus server time (UTC)
    • uptime_ms - uptime (above) in milliseconds
    • server_time - time according to the server process (UTC)

Usage

Because expvarplus plugs into the existing expvar goodness, it's probably best to start by looking at the expvar docs.

Check out one of the complete examples, or do like so:

// import the thing
import (
	"github.com/meatballhat/expvarplus"
)

// ... other code ...

	// register the handler func with your muxer, either at the
	// traditional location:
	mux.HandleFunc(`/debug/vars`, expvarplus.HandleExpvars)

	// or at a custom location:
	mux.HandleFunc(`/fancy/custom/obscure/xyz123`, expvarplus.HandleExpvars)

In order to expose environment variables in the env map, add them to thesimply safelist like so:

	// in one part of your app:
	expvarplus.AddToEnvSafelist("FOO", "USER", "BOOT_TIME", "LANG")

	// and maybe somewhere else:
	expvarplus.AddToEnvSafelist("WHATEVER_SECRET_SAUCE")

This will result in the env map containing keys for FOO, USER, BOOT_TIME, LANG, and WHATEVER_SECRET_SAUCE along with their corresponding values as fetched at request time with os.Getenv.

NOTE: Environment variables will not be exposed unless safelisted.

Documentation

Overview

This is not a replacement for expvar, but instead adds some extra stuff to the variables that are exported (typically to /debug/vars), including:

env: a map of safelisted environment variables

uptime: some variables related to process uptime including:
  start_time: time of roughly when the process started (UTC)
  uptime: start time minus server time (UTC)
  uptime_ms: uptime (above) in milliseconds
  server_time: time according to the server process (UTC)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToEnvSafelist

func AddToEnvSafelist(keys ...string)

func HandleExpvars

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

HandleExpvars does the same thing as the private expvar.expvarHandler, but exposed as public for pluggability into other web frameworks and generates json in a maybe slightly kinda more sane way (???).

func RemoveFromEnvSafelist

func RemoveFromEnvSafelist(keys ...string)

Types

This section is empty.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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