修改自动生成模板

This commit is contained in:
ayflying
2025-02-10 14:42:02 +08:00
parent 167f90b250
commit 2b51cc5f7c
5 changed files with 38 additions and 11 deletions

View File

@@ -2,13 +2,18 @@ package cmd
import (
"context"
"embed"
"fmt"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"io/fs"
)
//go:embed make/*
var ConfigFiles embed.FS
var (
Make = gcmd.Command{
Name: "make",
@@ -19,8 +24,8 @@ var (
{Name: "id", Short: "i", Brief: "活动id"},
{Name: "name", Short: "n", Brief: "服务文件名"},
},
Examples: "make -m=act -id=1: 创建活动1的接口与服务文件 \n" +
"make -m=logic -n=test: 创建test的服务文件",
Examples: "make -m act -i 1: 创建活动1的接口与服务文件 \n" +
"make -m logic -n test: 创建test的服务文件",
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
//g.Dump(parser.GetOptAll(), parser.GetArgAll())
@@ -59,7 +64,9 @@ func (c *cMake) Act(id int) (err error) {
err = gfile.PutContents(filePath, "package v1\n")
filePath = fmt.Sprintf("internal/game/act/act%d/act%d.go", id, id)
fileStr := gfile.GetContents("internal/cmd/make/act")
//fileStr := gfile.GetContents(getFilePath)
get, err := fs.ReadFile(ConfigFiles, "make/act")
fileStr := string(get)
fileStr = gstr.Replace(fileStr, "{id}", gconv.String(id))
err = gfile.PutContents(filePath, fileStr)
@@ -68,7 +75,9 @@ func (c *cMake) Act(id int) (err error) {
func (c *cMake) Logic(name string) (err error) {
var filePath = fmt.Sprintf("internal/logic/%s/%s.go", name, name)
fileStr := gfile.GetContents("internal/cmd/make/logic")
//fileStr := gfile.GetContents("./make/logic")
get, err := fs.ReadFile(ConfigFiles, "make/act")
fileStr := string(get)
fileStr = gstr.Replace(fileStr, "{package}", name)
fileStr = gstr.Replace(fileStr, "{name}", gstr.CaseCamel(name))

View File

@@ -1,7 +1,6 @@
package act{id}
import (
v1 "game_server/api/act/v1"
"game_server/internal/service"
"github.com/gogf/gf/v2/os/gctx"
)
@@ -28,7 +27,7 @@ func init() {
func (s *sAct{id}) GetData(uid int64) (data *Data) {
get, _ := service.GameAct().Info(uid, ActId)
get.Scan(&data)
if get.IsEmpty() || data == nil {
if get.IsEmpty() || get.IsNil() || data == nil {
data = &Data{
}
}