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: 0

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