Coder Social home page Coder Social logo

env's Introduction

env

GoDoc Build Status

Implements a simple way of handling environment values. Each environment field is simply reflected by a variable inside the Go program. Out of the box handlers for the types bool, []byte, time.Duration, int, []int, string, []string and map[string]string are provided. Other types can be added by using the RegisterField function.

Example

package main

import (
    "fmt"

    "github.com/simia-tech/env/v2"
)

var (
    name   = env.String("NAME", "joe")
    age    = env.Int("AGE", 24)
    shifts = env.StringMap("SHIFTS", map[string]string{"monday": "9am - 5pm"})
)

func main() {
    env.ParseFlags()

    fmt.Printf("%s is %d years old\nshifts are %v\n",
        name.GetOrDefault(), age.GetOrDefault(), shifts.GetOrDefault())
}

If the program is called with -print-env, all registered environment fields would be printed...

NAME="joe"
AGE="24"
SHIFTS="monday:\"9am - 5pm\""

By using -print-env -print-env-format long-bash, a description for each field is generated.

# String field. The default value is 'joe'. Defined at .../main.go:11.
NAME="joe"

# Int field. The default value is '24'. Defined at .../main.go:10.
AGE="24"

# StringMap fields. The default value is 'monday:\"9am - 5pm\"'. Defined at .../main.go:9.
SHIFTS="monday:\"9am - 5pm\""

License

The project is licensed under Apache 2.0.

env's People

Contributors

phifty avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.