Languages
Envlet for Go
envlet.Inject sets the process environment from one token. Then os.Getenv, like always.
Inject
package main
import (
"context"
"log"
"os"
"github.com/selcor/envlet-go"
)
func main() {
if err := envlet.Inject(context.Background()); err != nil {
log.Fatal(err)
}
stripe.Key = os.Getenv("STRIPE_KEY")
}Load
values, err := envlet.Load(context.Background())
if err != nil {
return err
}
db, err := sql.Open("postgres", values["DATABASE_URL"])Get
stripeKey, err := envlet.Get(context.Background(), "STRIPE_KEY")
if err != nil {
return err
}Install
go get github.com/selcor/envlet-go@v0.1.0Set up
- 01
Install
go get github.com/selcor/envlet-go@v0.1.0.
- 02
Set one secret
ENVLET_TOKEN in the environment of the binary.
- 03
Inject in main
Call envlet.Inject(ctx) first thing in main.
Questions
- Will my app start if Envlet is down?
- No, and that is the point. The SDK retries for a few seconds, then fails so you notice. It never starts your app with half an environment.
- What does the host need?
- One variable, ENVLET_TOKEN. Everything else arrives at boot.
- Can I still set some values on the Go host?
- Yes. A value the host already set wins. Pass override if you want Envlet to win instead.