summaryrefslogtreecommitdiff
path: root/sandpit
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2017-07-08 09:25:37 +0100
committerKatolaZ <katolaz@freaknet.org>2017-07-08 09:25:37 +0100
commitc63c8c8778cb497bba1b3d77e8810d2dd45d2e24 (patch)
tree677999d78ddc9db01a3d20a3e9652fae70130d61 /sandpit
parentc3f29e8540cc135286c8a9abc33aac8df8005389 (diff)
sandpit folder + experiments with YAML commands and configs
Diffstat (limited to 'sandpit')
-rw-r--r--sandpit/test_yaml.go102
1 files changed, 102 insertions, 0 deletions
diff --git a/sandpit/test_yaml.go b/sandpit/test_yaml.go
new file mode 100644
index 0000000..ebe8758
--- /dev/null
+++ b/sandpit/test_yaml.go
@@ -0,0 +1,102 @@
+package main
+
+import (
+ "fmt"
+ "github.com/go-yaml/yaml"
+ "log"
+)
+
+type STag struct {
+ S_tag string
+ S_args []string
+}
+
+type SCmd struct {
+ S_cmd string
+ S_hash string
+}
+
+type STagConfig struct {
+ S_tag string
+ S_commands []SCmd
+}
+
+type SCORSHmsg struct {
+ S_msg []STag
+}
+
+type SCORSHcfg struct {
+ S_cfg []STagConfig
+}
+
+var msg_str = `
+s_msg:
+ - s_tag: BUILD
+ s_args:
+ - suites/jessie
+ - suites/ascii
+ - s_tag: REMOVE
+ s_args:
+ - file1
+`
+
+var cfg_str = `
+s_cfg:
+ - s_tag: BUILD
+ s_commands:
+ - s_cmd: file:///bin/ls
+ s_hash: 12345
+ - s_cmd: file:///home/katolaz/script.sh
+ s_hash: abc123df
+ - s_cmd: http://myserver.org/build.php?name=\1
+ s_hash:
+ - s_tag: REMOVE
+ s_commands:
+ - s_cmd: file:///bin/rm
+`
+
+func main() {
+
+ var c SCORSHmsg
+
+ var conf SCORSHcfg
+
+ //log.Printf("%s\n", test_str)
+
+ err := yaml.Unmarshal([]byte(msg_str), &c)
+ if err != nil {
+ log.Fatal("error: ", err)
+ }
+
+ for _, item := range c.S_msg {
+ fmt.Printf("Record: \n")
+ fmt.Printf(" s_tag: %s\n", item.S_tag)
+ fmt.Printf(" s_args:\n")
+
+ for _, a := range item.S_args {
+ fmt.Printf(" %s\n", a)
+ }
+ }
+
+ fmt.Println("----------------------------")
+
+ err = yaml.Unmarshal([]byte(cfg_str), &conf)
+ if err != nil {
+ log.Fatal("error: ", err)
+ }
+
+ for _, cfg_item := range conf.S_cfg {
+ fmt.Printf("Config record:\n")
+ fmt.Printf(" s_tag: %s\n", cfg_item.S_tag)
+ fmt.Printf(" s_commands:\n")
+
+ for _, c := range cfg_item.S_commands {
+ fmt.Printf(" s_cmd: %s\n", c.S_cmd)
+ fmt.Printf(" s_hash: %s\n", c.S_hash)
+ fmt.Println(" ---")
+ }
+ fmt.Println("-+-+-")
+
+ }
+
+}