goprop

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

goprop

Tag Test

Golang util for bind environment to the struct and validate with validator.

Usage

Use default, read environmet which start with APP_

package main

import (
	"fmt"
	"os"
	"time"

	"github.com/tongium/goprop"
)

type Configuration struct {
	Name     string
	Number   int
	Digit    float64
	SomeWord string
	Duration time.Duration
    CustomName string `env:"CUS"` // specific environment name
}

func init() {
	os.Setenv("APP_NAME", "Gopher")
	os.Setenv("APP_DURATION", "1h")
	os.Setenv("APP_SOME_WORD", "Hello World!")
	os.Setenv("APP_DIGIT", "1.23")
	os.Setenv("APP_NUMBER", "1")
}

func main() {
	cfg := Configuration{}

	if err := goprop.Load(&cfg); err != nil {
		panic(err)
	}

	fmt.Printf("%+v\n", cfg)
}

result

{Name:Gopher Number:1 Digit:1.23 SomeWord:Hello World! Duration:1h0m0s}

see more example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(T interface{}) error

Support only exported field and type is string, bool, int, or float

func LoadWithConfig

func LoadWithConfig(T interface{}, cfg Config) error

func ToSnakeCase

func ToSnakeCase(str string) string

Types

type Config

type Config struct {
	Prefix string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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