Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Default ¶
func Default() any
Default returns registered config nodes default value structure
Example ¶
package main
import (
"encoding/json"
"github.com/acrazing/go-conf"
)
func main() {
type ServerConfig struct {
Host string `json:"host"`
Port int `json:"port"`
}
// Register first
conf.Register[ServerConfig]("server")
d := conf.Default()
txt, _ := json.MarshalIndent(d, "", " ")
println(txt)
}
Output:
func Get ¶
Get a configuration node from registry
Example ¶
package main
import (
"github.com/acrazing/go-conf"
)
func main() {
type ServerConfig struct {
Host string `json:"host"`
Port int `json:"port"`
}
// Register first
conf.Register[ServerConfig]("server")
// Init registry
r, err := conf.Load("config.json")
if err != nil {
panic(err.Error())
}
// Get config from registry
serverConfig, err := conf.Get[ServerConfig](r)
if err != nil {
panic(err)
}
println(serverConfig.Host, serverConfig.Port)
}
Output:
Types ¶
Click to show internal directories.
Click to hide internal directories.