Replies: 3 comments 2 replies
-
Hey @gozes, there are some basic examples on the docs site. If these don't help or you have any questions, let me know and I can add more. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Will have a better look tomorrow but by just having a quick look now they
are quite basic. I was hoping for example on selecting and filtering deep
in a nested object :)
.
…On Fri, Jun 28, 2024, 16:25 Tom Wright ***@***.***> wrote:
Hey @gozes <https://github.com/gozes>, there are some basic examples on
the docs site
<https://daseldocs.tomwright.me/examples/using-dasel-as-a-go-package>.
If these don't help or you have any questions, let me know and I can add
more.
—
Reply to this email directly, view it on GitHub
<#411 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAE2QWRQ5S2MLEVMFUYMOUTZJV577AVCNFSM6AAAAABI6XWC4GVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TSMBWGM2DQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
2 replies
-
@gozes Does this example help you understand how to use this from go? package main
import (
"fmt"
"github.com/tomwright/dasel/v2"
)
type NestedValue struct {
Value any
}
type Root struct {
Foos []Foo
Value NestedValue
}
type Foo struct {
Bar Bar
}
type Bar struct {
Baz Baz
}
type Baz struct {
User User
}
type User struct {
FirstName string
LastName string
}
func main() {
x := Root{
Foos: []Foo{
{
Bar: Bar{
Baz: Baz{
User: User{
FirstName: "first name 1",
LastName: "last name 1",
},
},
},
},
{
Bar: Bar{
Baz: Baz{
User: User{
FirstName: "first name 2",
LastName: "last name 2",
},
},
},
},
},
Value: NestedValue{
Value: NestedValue{
Value: NestedValue{
Value: "Hello",
},
},
},
}
// Dig into a bunch of nested values
nestedValues, err := dasel.Select(&x, "Value.Value.Value.Value")
if err != nil {
panic(err)
}
// Take the final result and cast it to a string
fmt.Println(nestedValues.Interfaces()[0].(string)) // Hello
// Read through a slice containing nested values, and take the result as the actual go struct
users, err := dasel.Select(&x, "Foos.all().Bar.Baz.User")
if err != nil {
panic(err)
}
for _, u := range users.Interfaces() {
user := u.(User)
fmt.Printf("%T, %T, %s, %s\n", u, user, user.FirstName, user.LastName)
// main.User, main.User, first name 1, last name 1
// main.User, main.User, first name 2, last name 2
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
So after having a brief look at the golang docs for dasel as library I can import is not exactly clear to me what the correct/best way to use dasel as library. the repo dose not have an
example
folder so dose anyone knows or has any examples I can look at?Beta Was this translation helpful? Give feedback.
All reactions