
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
github.com/gookit/config
Golang application config manage tool library.
JSON
(default), INI
, YAML
, TOML
, HCL
JSON
content support comments. will auto clear commentsflags
)map.key
arr.2
envKey: ${SHELL}
-> envKey: /bin/zsh
Get
Int
String
Bool
Ints
IntMap
Strings
StringMap
...If you just want to use INI for simple config management, recommended use gookit/ini
Here using the yaml format as an example(testdata/yml_other.yml
):
name: app2
debug: false
baseKey: value2
shell: ${SHELL}
envKey1: ${NotExist|defValue}
map1:
key: val2
key2: val20
arr1:
- val1
- val21
examples code please see _examples/yaml.go:
package main
import (
"github.com/gookit/config"
"github.com/gookit/config/yaml"
)
// go run ./examples/yaml.go
func main() {
config.WithOptions(config.ParseEnv)
// add driver for support yaml content
config.AddDriver(yaml.Driver)
// config.SetDecoder(config.Yaml, yaml.Decoder)
err := config.LoadFiles("testdata/yml_base.yml")
if err != nil {
panic(err)
}
// fmt.Printf("config data: \n %#v\n", config.Data())
// load more files
err = config.LoadFiles("testdata/yml_other.yml")
// can also load multi at once
// err := config.LoadFiles("testdata/yml_base.yml", "testdata/yml_other.yml")
if err != nil {
panic(err)
}
}
age, ok := config.Int("age")
fmt.Print(ok, age) // true 100
val, ok := config.Bool("debug")
fmt.Print(ok, val) // true true
name, ok := config.String("name")
fmt.Print(ok, name) // true inhere
arr1, ok := config.Strings("arr1")
fmt.Printf("%v %#v", ok, arr1) // true []string{"val1", "val21"}
val, ok := config.StringMap("map1")
fmt.Printf("%v %#v",ok, val) // true map[string]string{"key":"val2", "key2":"val20"}
value, ok := config.String("shell")
fmt.Print(ok, value) // true /bin/zsh
// from array
value, ok := config.String("arr1.0")
fmt.Print(ok, value) // true "val1"
// from map
value, ok := config.String("map1.key")
fmt.Print(ok, value) // true "val2"
// set value
config.Set("name", "new name")
name, ok = config.String("name")
fmt.Print(ok, name) // true "new name"
LoadData(dataSource ...interface{}) (err error)
Load from struts or mapsLoadFlags(keys []string) (err error)
Load from cli flagsLoadExists(sourceFiles ...string) (err error)
LoadFiles(sourceFiles ...string) (err error)
LoadRemote(format, url string) (err error)
LoadSources(format string, src []byte, more ...[]byte) (err error)
LoadStrings(format string, str string, more ...string) (err error)
DefXXX
get value with default value
Bool(key string) (value bool, ok bool)
DefBool(key string, defVal ...bool) bool
Int(key string) (value int, ok bool)
DefInt(key string, defVal ...int) int
Int64(key string) (value int64, ok bool)
DefInt64(key string, defVal ...int64)
Ints(key string) (arr []int, ok bool)
IntMap(key string) (mp map[string]int, ok bool)
Float(key string) (value float64, ok bool)
DefFloat(key string, defVal ...float64) float64
String(key string) (value string, ok bool)
DefString(key string, defVal ...string) string
Strings(key string) (arr []string, ok bool)
StringMap(key string) (mp map[string]string, ok bool)
Get(key string, findByPath ...bool) (value interface{}, ok bool)
Set(key string, val interface{}, setByPath ...bool) (err error)
AddDriver(driver Driver)
Data() map[string]interface{}
DumpTo(out io.Writer, format string) (n int64, err error)
go test -cover
// contains all sub-folder
go test -cover ./...
MIT
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.