Skip to content

Instantly share code, notes, and snippets.

@jippi
Created December 19, 2016 19:08
Show Gist options
  • Save jippi/b1634de7d439366b42e8afede48f8342 to your computer and use it in GitHub Desktop.
Save jippi/b1634de7d439366b42e8afede48f8342 to your computer and use it in GitHub Desktop.
scale "bump" {
name = "hello"
type = "rabbitmq"
}
scale "derp" {
name = "world"
type = "derp"
}
package main
import (
"io/ioutil"
log "github.com/Sirupsen/logrus"
"github.com/hashicorp/hcl"
)
// Scale struct
type Scale struct {
Name string
Type string
}
// Config struct
type Config struct {
Scales []Scale `hcl:"scale"`
}
func main() {
var out Config
config, err := ioutil.ReadFile("config.hcl")
if err != nil {
log.Errorf("Failed to read file: %s", err)
return
}
hclErr := hcl.Decode(&out, string(config))
if hclErr != nil {
log.Errorf("HCL Error: %s", hclErr)
return
}
log.Infof("Number of rules: %d", len(out.Scales))
for index, scale := range out.Scales {
log.Infof("[%d] name: %s ; type : %s ", index, scale.Name, scale.Type)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment