Guest User

Untitled

a guest
Apr 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "log"
  5. "os"
  6.  
  7. "github.com/hashicorp/hcl"
  8. )
  9.  
  10. const (
  11. EXAMPLE_HCL = `config = "/etc/test.conf"`
  12. )
  13.  
  14. type HCLConfig struct {
  15. ConfigFile string `hcl:"config"`
  16. }
  17.  
  18. func main() {
  19. cfg := &HCLConfig{}
  20.  
  21. hclTree, err := hcl.Parse(EXAMPLE_HCL)
  22. if err != nil {
  23. os.Exit(1)
  24. }
  25.  
  26. // how to modify tree to override config field
  27.  
  28. if err := hcl.DecodeObject(&cfg, hclTree); err != nil {
  29. os.Exit(1)
  30. }
  31.  
  32. log.Printf("%+vn", cfg)
  33. }
Add Comment
Please, Sign In to add comment