Skip to content

Instantly share code, notes, and snippets.

@manuelarte
Created June 20, 2025 18:26
Show Gist options
  • Save manuelarte/8f5cafbb44fa736b9381d4fb9c625e34 to your computer and use it in GitHub Desktop.
Save manuelarte/8f5cafbb44fa736b9381d4fb9c625e34 to your computer and use it in GitHub Desktop.
`KeyValueExpr` parsing comments with dst
package main
import (
"github.com/dave/dst"
"github.com/dave/dst/decorator"
"os"
)
func main() {
code := `package a
func main(){
_ = Person{
// the birthdate is now
Birthdate: time.Now(),
// the surname is important
Surname: "Doe",
Name: "John",
}
}
`
f, err := decorator.Parse(code)
if err != nil {
panic(err)
}
dst.Fprint(os.Stdout, f, dst.NotNilFilter)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment