Skip to content

structs with annotated fields

Latest
Compare
Choose a tag to compare
@Attumm Attumm released this 30 Nov 20:28
· 3 commits to main since this release
0a182da

Settingo now allows you to define and pass structs with annotated fields directly, making your configuration cleaner and simpler. With IDE integration from code completion

import (
	"fmt"
	"github.com/Attumm/settingo/settingo"
	"log"
)

type Config struct {
	Filename       string `settingo:"Path of the filename"`
	Storage        string `settingo:"Storage type"`
	Convert        bool   `settingo:"Convert mode, will convert data into Convert Storage type"`
	ConvertStorage string `settingo:"bytes"`
}

func main() {
	config := &Config{
		Filename:       "~/Downloads/archive/data",
		Storage:        "csv",
		Convert:        true,
		ConvertStorage: "bytes",
	}
	
	settingo.ParseTo(config)
	
	fmt.Println(config.Filename)
	fmt.Println(config.Storage)
	fmt.Println(config.Convert)
	fmt.Println(config.ConvertStorage)
}
./foobar --help
Usage of ./go_quote:
  -CONVERT string
        Convert mode, will convert data into Convert Storage type (default "true")
  -CONVERTSTORAGE string
        bytes (default "bytes")
  -FILENAME string
        Path of the filename (default "~/Downloads/archive/data.csv")
  -STORAGE string
        Storage type (default "csv")