提交 65256b42 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

parse sample yaml file

上级 ca5f2b1c
package action
import logUtils "github.com/easysoft/zendata/src/utils/log"
import (
"github.com/easysoft/zendata/src/model"
logUtils "github.com/easysoft/zendata/src/utils/log"
"gopkg.in/yaml.v2"
"io/ioutil"
)
func Generate(file string, count int, fields string, out string, table string) {
logUtils.Screen(file)
definition := model.Definition{}
yamlContent, err := ioutil.ReadFile(file)
if err == nil {
logUtils.Screen(string(yamlContent))
err = yaml.Unmarshal(yamlContent, &definition)
if err == nil {
logUtils.Screen("===")
}
}
}
package model
type Definition struct {
Title string `yaml:"title"`
Desc string `yaml:"desc"`
Author string `yaml:"author"`
Version string`yaml:"version"`
Fields []Field `yaml:"fields,flow"`
}
type Field struct {
Name string `yaml:"name"`
Datatype string `yaml:"datatype"`
From string `yaml:"from"`
To string `yaml:"to"`
Prefix string `yaml:"prefix"`
Postfix string `yaml:"postfix"`
}
......@@ -48,11 +48,11 @@ func main() {
flagSet.BoolVar(&parse, "p", false, "")
flagSet.BoolVar(&parse, "parse", false, "")
flagSet.StringVar(&file, "o", "", "")
flagSet.StringVar(&file, "out", "", "")
flagSet.StringVar(&out, "o", "", "")
flagSet.StringVar(&out, "out", "", "")
flagSet.StringVar(&file, "t", "", "")
flagSet.StringVar(&file, "table", "", "")
flagSet.StringVar(&table, "t", "", "")
flagSet.StringVar(&table, "table", "", "")
flagSet.BoolVar(&help, "h", false, "")
flagSet.BoolVar(&help, "help", false, "")
......@@ -78,7 +78,6 @@ func main() {
} else {
logUtils.PrintUsage()
}
}
}
......
title: just a test
desc: this is the test file.
author: wwccss
version: 1.0
fields:
field1:
- name: field1
datatype: list
range: 10-20
from: 10
to: 20
prefix: int_
postfix: ' '
- name: field2
datatype: list
from: 10
to: 20
prefix: int_
postfix: ' '
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册