distributedio / configo Goto Github PK
View Code? Open in Web Editor NEWConfigo is a go library to parse toml configuration using struct tags
License: MIT License
Configo is a go library to parse toml configuration using struct tags
License: MIT License
As far as I can tell anyways.
Love the library though!!
Working with the library I found a bug: the call to Unmarshal just hangs forever.
The following code allows to reproduce the issue.
package main
import (
"github.com/shafreeck/configo"
"fmt"
)
type SimpleTest struct {
Test string
}
type ComlexeTest struct {
Test string
Test1 []SimpleTest
Test2 []SimpleTest
}
type Config struct {
Test ComlexeTest
}
var toml = `
[test]
test = "test"
[[test.test1]]
test = "test1"
[[test.test2]]
test = "test2"
`
func Test2() {
c := &Config{}
if err := configo.Unmarshal([]byte(toml), &c); err != nil {
panic(err)
}
fmt.Println(c)
}
My config struct is like this:
type Config struct {
Client struct {
ServerAddress string `cfg:"server_address, https://server.example.com, url, Server address"`
Identifier string `cfg:"identifier, required, ascii, Identifier"`
UpdateInterval time.Duration `cfg:"update_interval, 60, int, Update interval in seconds"`
LANInterface string `cfg:"lan_interface, auto, alphanumeric, Which LAN interface to use, will return the first LAN interface available"`
} `cfg:"client"`
}
And my config is like below:
[client]
server_address="https://server.example.com"
identifier="id"
update_interval=60
lan_interface="auto"
I have a global variable config
:
var config = &Config{}
And I have err := configo.Unmarshal(conf, &config)
in main()
, but I get this error when I run:
Error parsing config: line 5: field corresponding to `lan_interface' is not defined in `*struct { ServerAddress string "cfg:\"server_address, https://server.example.com, url, Server address\""; Identifier string "cfg:\"identifier, required, ascii, Identifier\""; UpdateInterval time.Duration "cfg:\"update_interval, 60, int, Update interval in seconds\""; LANInterface string "cfg:\"lan_interface, auto, alphanumeric, Which LAN interface to use, will return the first LAN interface available\"" }'
But in fact lan_interface
is defined. Any ideas?
When a configuration item is of type bool and the default value is false, setting true does not take effect
Or maybe more accurately, unless there is an initialized member in the slice. But when there is not I think it isn't supposed to print out the field tag?
Related would be specifying a default for a slice of structs, is that possible?
Export the applyDefault
function as ApplyDefault
.
It is useful to build an object with default configurations.
// now the default is an object initialized by empty values.
default := conf.ExampleConfig()
// fill the fields with default value
configo.ApplyDefault(&default)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.