Created
December 19, 2016 19:08
-
-
Save jippi/b1634de7d439366b42e8afede48f8342 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
scale "bump" { | |
name = "hello" | |
type = "rabbitmq" | |
} | |
scale "derp" { | |
name = "world" | |
type = "derp" | |
} |
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 ( | |
"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