yaml规则匹配

test.yaml

rule:
  author: osk 
  created: 2019-5-14
  description: information collection
  actions:
    1: cat /etc/passwd
    2: cat /etc/issue
os: Linux
name: Recon
uuid: 01dfdaa3-0e14-467d-9bc8-e0610b9e9f89

code

package main

import (
	"fmt"
	"log"

	"github.com/kylelemons/go-gypsy/yaml"
)

func nodeToMap(node yaml.Node) yaml.Map {
	m, ok := node.(yaml.Map)
	if !ok {
		panic(fmt.Sprintf("%v is not of type map", node))
	}
	return m
}

// func nodeToList(node yaml.Node) yaml.List {
// 	m, ok := node.(yaml.List)
// 	if !ok {
// 		panic(fmt.Sprintf("%v is not of type list", node))
// 	}
// 	return m
// }

func main() {
	config, err := yaml.ReadFile("./test.yaml")
	if err != nil {
		log.Fatalf("readfile(%q): %s", "test.yaml", err)
	}

	x := nodeToMap(config.Root)["rule"]
	fmt.Println(yaml.Child(x, "actions"))

}

你可能感兴趣的:(总结)