dreamfactory_cmd/cmd/v2/gen_test.go
2023-06-09 21:58:02 +08:00

43 lines
898 B
Go

package main_test
import (
"go_dreamfactory/cmd/v2/lib/common"
cfg "go_dreamfactory/sys/configure/structs"
"html/template"
"os"
"testing"
)
type TaskCond struct {
Data map[int32]*cfg.GameRdtaskCondiData
}
func TestTask(t *testing.T) {
commcfg := &common.Config{
Path: "F:\\projects\\workspace\\go_dreamfactory\\bin\\json",
}
if tb, err := cfg.NewTables(commcfg.Loader); err == nil {
data := tb.RdtaskCondi.GetDataMap()
tmpl := template.New("task")
tplTxt := `reqDataMap := map[int32]TaskCondi{
{{ range .Data }}
{{.Id}}:{ {{.Type}},[]int32{ {{.Data1}},{{.Data2}},{{.Data3}},{{.Data4}},{{.Data5}} },
{{ end}} }`
tpl, err := tmpl.Parse(tplTxt)
if err != nil {
t.Fatal(err)
}
//输出文件
file, err := os.OpenFile("./tpl.txt", os.O_CREATE|os.O_WRONLY, 0755)
if err != nil {
panic(err)
}
p := TaskCond{
Data: data,
}
tpl.Execute(file, p)
}
}