How to update dasel.New() usage for v2 API? #376
-
Previously there was a Use as a go package documentation page which also helped me to hack-in INI file support in my code using zieckey/goini. This relied on using Examplepackage foo
import (
"github.com/tomwright/dasel"
"github.com/zieckey/goini"
)
func modifyINI(path string, selector string, value string) (err error) {
ini := goini.New()
err = ini.ParseFile(path)
if err != nil {
return
}
kv := ini.GetAll()
// This worked in V1
node := dasel.New(kv)
if err != nil {
return
}
if value == nil {
err = node.Delete(selector)
} else {
err = node.Put(selector, value)
}
if err != nil {
return
}
// Write file...
return
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
In dasel V2 you can completely skip the step of creating a node and directly use package level functions I have updated the docs: https://daseldocs.tomwright.me/examples/using-dasel-as-a-go-package E.g. func modifyINI(path string, selector string, value string) (err error) {
ini := goini.New()
err = ini.ParseFile(path)
if err != nil {
return
}
kv := ini.GetAll()
var result dasel.Value
if value == nil {
result, err = dasel.Delete(kv, selector)
} else {
result, err = dasel.Put(kv, selector, value)
}
if err != nil {
return
}
resultValue := result.Interface()
// Write file...
return
} |
Beta Was this translation helpful? Give feedback.
In dasel V2 you can completely skip the step of creating a node and directly use package level functions
dasel.Select
,dasel.Put
anddasel.Delete
.I have updated the docs: https://daseldocs.tomwright.me/examples/using-dasel-as-a-go-package
E.g.