推荐一个动态模板引擎库
🎉🎉🎉
魔改了 ejs 作为模板,用 otto 解释,这样可以在业务中实现非常动态灵活的输出,你可以把上下文作为一个 json 传到 ejs 中。
// default
e := otto.NewDefaultOttoEngine()
got, _ := e.Exec("hello, <%= name %>!", map[string]interface{}{"name": "goejs"}, &contract.Option{
Debug: true,
})
fmt.Println(got) // hello, goejs!
// config
e := otto.NewOttoEngine(ejs.NewJsScript(ejs.WithOpenDelimiter("{"), ejs.WithOpenDelimiter("}")))
got, _ := e.Exec("hello, {%= name %}!", map[string]interface{}{"name": "goejs"}, &contract.Option{
Debug: true,
})
fmt.Println(got) // hello, goejs!