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 variablesuptime
- 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 millisecondsserver_time
- time according to the server process (UTC)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.
Version | Tag | Published |
---|---|---|
v0.0.0-20180410141646-6251af2cf85a | 2yrs ago |