Last active
November 2, 2015 10:39
-
-
Save mix3/be58f102b64208de3fe6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
`) | |
} |
Author
mix3
commented
Nov 2, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment