-
Notifications
You must be signed in to change notification settings - Fork 0
/
genenttx.go
35 lines (28 loc) · 967 Bytes
/
genenttx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package generator
import (
_ "embed"
"path/filepath"
"github.com/iancoleman/strcase"
conf "github.com/suyuan32/goctls/config"
"github.com/suyuan32/goctls/rpc/parser"
"github.com/suyuan32/goctls/util"
"github.com/suyuan32/goctls/util/format"
"github.com/suyuan32/goctls/util/pathx"
)
//go:embed enttx.tpl
var entTxTemplateText string
func (g *Generator) GenEntTx(ctx DirContext, _ parser.Proto, cfg *conf.Config, c *ZRpcContext) error {
filename, err := format.FileNamingFormat(cfg.NamingFormat, "ent_tx.go")
if err != nil {
return err
}
handlerFilename := filepath.Join(ctx.GetInternal().Filename, "utils/entx", filename)
if err := pathx.MkdirIfNotExist(filepath.Join(ctx.GetInternal().Filename, "utils/entx")); err != nil {
return err
}
err = util.With("entTx").Parse(entTxTemplateText).SaveTo(map[string]string{
"package": ctx.GetMain().Package,
"serviceName": strcase.ToCamel(c.RpcName),
}, handlerFilename, false)
return err
}