exp
github.com/meatballhat/expvarplus
go get github.com/meatballhat/expvarplus
exp

github.com/meatballhat/expvarplus

Extended expvar fun

go get github.com/meatballhat/expvarplus
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.

GitHub Stars

11

LAST COMMIT

4yrs ago

MAINTAINERS

0

CONTRIBUTORS

3

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v0.0.0-20180410141646-6251af2cf85a
2yrs ago
No alternatives found
No tutorials found
Add a tutorial