Skip to content

Instantly share code, notes, and snippets.

@mix3 mix3/main.go
Last active Nov 2, 2015

Embed
What would you like to do?
package main
import (
"log"
"github.com/hashicorp/hcl"
"github.com/k0kubun/pp"
)
type Config struct {
Hoge Hoge `hcl:"hoge"`
}
type Hoge struct {
Fuga int `hcl:"fuga"`
Piyo string `hcl:"piyo"`
}
func parse(input string) {
var result Config
obj, err := hcl.Parse(input)
if err != nil {
log.Fatal(err)
}
if err := hcl.DecodeObject(&result, obj); err != nil {
log.Fatal(err)
}
pp.Println(result)
}
func main() {
parse(`
hoge {
fuga = 1
piyo = "baz"
}
`)
parse(`
hoge {
fuga = "bar" /* wrong */
piyo = "baz"
}
`)
}
@mix3

This comment has been minimized.

Copy link
Owner Author

mix3 commented Nov 2, 2015

$ go run main.go
main.Config{
  Hoge: main.Hoge{
    Fuga: 1,
    Piyo: "baz",
  },
}
2015/11/02 19:30:52 strconv.ParseInt: parsing "bar": invalid syntax
exit status 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.