Skip to content

How to update dasel.New() usage for v2 API? #376

Answered by TomWright
beatcracker asked this question in Q&A
Discussion options

You must be logged in to vote

In dasel V2 you can completely skip the step of creating a node and directly use package level functions dasel.Select, dasel.Put and dasel.Delete.

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
}

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@beatcracker
Comment options

@TomWright
Comment options

@beatcracker
Comment options

@TomWright
Comment options

@beatcracker
Comment options

Answer selected by beatcracker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants