example

command
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2019 License: MIT Imports: 2 Imported by: 0

README

Example

main.go

package main

import (
	"log"

	"github.com/l-vitaly/goenv/example/config"
)

func main() {
	cfg, err := config.Parse()
	if err != nil {
		log.Fatalln(err)
	}

	log.Println(cfg.DBConn)
}

config/config.go

package config

import (
	"fmt"

	"github.com/l-vitaly/goenv"
)

const errPattern = "could not set %s"

// env name consts
const (
	DBConnEnvName = "DB_CONN"
)

// Config config.
type Config struct {
	DBConn string
}

// Parse env config vars.
func Parse() (*Config, error) {
	cfg := &Config{}

	goenv.StringVar(&cfg.DBConn, DBConnEnvName, "")
	goenv.Parse()

	if cfg.DBConn == "" {
		return nil, fmt.Errorf(errPattern, DBConnEnvName)
	}

	return cfg, nil
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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