mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-14 05:03:49 +08:00
发布v2.15.11版本,更新内容请查看:https://github.com/bufanyun/hotgo/blob/v2.0/docs/guide-zh-CN/start-update-log.md
This commit is contained in:
@@ -7,5 +7,5 @@ package consts
|
||||
|
||||
// VersionApp HotGo版本
|
||||
const (
|
||||
VersionApp = "2.15.7"
|
||||
VersionApp = "2.15.11"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.15.1
|
||||
// @AutoGenerate Version 2.15.7
|
||||
package sys
|
||||
|
||||
import (
|
||||
@@ -76,4 +76,4 @@ func (c *cTestCategory) Delete(ctx context.Context, req *testcategory.DeleteReq)
|
||||
func (c *cTestCategory) Status(ctx context.Context, req *testcategory.StatusReq) (res *testcategory.StatusRes, err error) {
|
||||
err = service.SysTestCategory().Status(ctx, &req.TestCategoryStatusInp)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ export function updateConfig(params) {
|
||||
|
||||
webConfigSystem = `<template>
|
||||
<div>
|
||||
<n-grid cols="24 300:1 600:24" :x-gap="24">
|
||||
<n-grid cols="24 300:1 600:24" :x-gap="12">
|
||||
<n-grid-item span="6">
|
||||
<n-card :bordered="false" size="small" class="proCard">
|
||||
<n-thing
|
||||
|
||||
@@ -35,7 +35,9 @@ func GenLoggerByCtx(ctx context.Context) *glog.Logger {
|
||||
Logger().Panic(ctx, "获取定时任务序列号失败!")
|
||||
}
|
||||
|
||||
crons.RLock()
|
||||
logger, ok := crons.loggers[sn]
|
||||
crons.RUnlock()
|
||||
if ok {
|
||||
return logger
|
||||
}
|
||||
|
||||
@@ -136,6 +136,16 @@ func GenHashOption(key interface{}, label string, extra ...any) *model.Option {
|
||||
}
|
||||
}
|
||||
|
||||
// GetOption 通过key找到label
|
||||
func GetOption(ses []*model.Option, key interface{}) *model.Option {
|
||||
for _, v := range ses {
|
||||
if gconv.String(v.Key) == gconv.String(key) {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetOptionLabel 通过key找到label
|
||||
func GetOptionLabel(ses []*model.Option, key interface{}) string {
|
||||
for _, v := range ses {
|
||||
@@ -155,3 +165,16 @@ func HasOptionKey(ses []*model.Option, key interface{}) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// UniqueOption 去重选项
|
||||
func UniqueOption(src []*model.Option) (dst []*model.Option) {
|
||||
temp := map[string]struct{}{}
|
||||
for _, item := range src {
|
||||
key := gconv.String(item.Key)
|
||||
if _, ok := temp[key]; !ok {
|
||||
temp[key] = struct{}{}
|
||||
dst = append(dst, item)
|
||||
}
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func (c cGF) Index(ctx context.Context, in cGFInput) (out *cGFOutput, err error)
|
||||
answer := "n"
|
||||
// No argument or option, do installation checks.
|
||||
if data, isInstalled := service.Install.IsInstalled(); !isInstalled {
|
||||
mlog.Print("hi, it seams it's the first time you installing gf cli.")
|
||||
mlog.Print("hi, it seems it's the first time you installing gf cli.")
|
||||
answer = gcmd.Scanf("do you want to install gf(%s) binary to your system? [y/n]: ", gf.VERSION)
|
||||
} else if !data.IsSelf {
|
||||
mlog.Print("hi, you have installed gf cli.")
|
||||
|
||||
@@ -138,11 +138,6 @@ type cBuildInput struct {
|
||||
type cBuildOutput struct{}
|
||||
|
||||
func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, err error) {
|
||||
// print used go env
|
||||
if in.DumpENV {
|
||||
_, _ = Env.Index(ctx, cEnvInput{})
|
||||
}
|
||||
|
||||
mlog.SetHeaderPrint(true)
|
||||
|
||||
mlog.Debugf(`build command input: %+v`, in)
|
||||
@@ -217,7 +212,7 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
|
||||
if !gfile.Exists(in.PackDst) {
|
||||
// Remove the go file that is automatically packed resource.
|
||||
defer func() {
|
||||
_ = gfile.Remove(in.PackDst)
|
||||
_ = gfile.RemoveFile(in.PackDst)
|
||||
mlog.Printf(`remove the automatically generated resource go file: %s`, in.PackDst)
|
||||
}()
|
||||
}
|
||||
@@ -241,6 +236,10 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
|
||||
} else {
|
||||
genv.MustSet("CGO_ENABLED", "0")
|
||||
}
|
||||
// print used go env
|
||||
if in.DumpENV {
|
||||
_, _ = Env.Index(ctx, cEnvInput{})
|
||||
}
|
||||
for system, item := range platformMap {
|
||||
if len(customSystems) > 0 && customSystems[0] != "all" && !gstr.InArray(customSystems, system) {
|
||||
continue
|
||||
|
||||
@@ -8,6 +8,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -22,8 +23,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
GitName = "gf-site"
|
||||
BranchName = "gh-pages"
|
||||
|
||||
SiteFileName = GitName + "-" + BranchName
|
||||
// DocURL is the download address of the document
|
||||
DocURL = "https://github.com/gogf/gf/archive/refs/heads/gh-pages.zip"
|
||||
DocURL = "https://github.com/gogf/" + GitName + "/archive/refs/heads/" + BranchName + ".zip"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -70,12 +75,13 @@ func (c cDoc) Index(ctx context.Context, in cDocInput) (out *cDocOutput, err err
|
||||
mlog.Print("Failed to download document:", err)
|
||||
return
|
||||
}
|
||||
s := g.Server()
|
||||
s.SetServerRoot(docs.DocDir)
|
||||
s.SetPort(in.Port)
|
||||
s.SetDumpRouterMap(false)
|
||||
mlog.Printf("Access address http://127.0.0.1:%d", in.Port)
|
||||
s.Run()
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir(docs.DocDir)))
|
||||
mlog.Printf("Access address http://127.0.0.1:%d in %s", in.Port, docs.DocDir)
|
||||
err = http.ListenAndServe(fmt.Sprintf(":%d", in.Port), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -89,7 +95,7 @@ type DocSetting struct {
|
||||
|
||||
// NewDocSetting new DocSetting
|
||||
func NewDocSetting(ctx context.Context, in cDocInput) *DocSetting {
|
||||
fileName := "gf-doc-md.zip"
|
||||
fileName := SiteFileName + ".zip"
|
||||
tempDir := in.Path
|
||||
if tempDir == "" {
|
||||
tempDir = gfile.Temp("goframe/docs")
|
||||
@@ -99,17 +105,17 @@ func NewDocSetting(ctx context.Context, in cDocInput) *DocSetting {
|
||||
|
||||
return &DocSetting{
|
||||
TempDir: filepath.FromSlash(tempDir),
|
||||
DocDir: filepath.FromSlash(path.Join(tempDir, "gf-gh-pages")),
|
||||
DocDir: filepath.FromSlash(path.Join(tempDir, SiteFileName)),
|
||||
DocURL: in.Proxy + DocURL,
|
||||
DocZipFile: filepath.FromSlash(path.Join(tempDir, fileName)),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Clean clean the temporary directory
|
||||
// Clean cleans the temporary directory
|
||||
func (d *DocSetting) Clean() error {
|
||||
if _, err := os.Stat(d.TempDir); err == nil {
|
||||
err = gfile.Remove(d.TempDir)
|
||||
err = gfile.RemoveAll(d.TempDir)
|
||||
if err != nil {
|
||||
mlog.Print("Failed to delete temporary directory:", err)
|
||||
return err
|
||||
@@ -168,7 +174,7 @@ func (d *DocSetting) DownloadDoc() error {
|
||||
err := gcompress.UnZipFile(d.DocZipFile, d.TempDir)
|
||||
if err != nil {
|
||||
mlog.Print("Failed to unzip the file, please run again:", err)
|
||||
gfile.Remove(d.DocZipFile)
|
||||
_ = gfile.RemoveFile(d.DocZipFile)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -93,6 +93,12 @@ type (
|
||||
)
|
||||
|
||||
func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err error) {
|
||||
if !gfile.Exists(in.File) {
|
||||
mlog.Fatalf(`given file "%s" not found`, in.File)
|
||||
}
|
||||
if !gfile.IsFile(in.File) {
|
||||
mlog.Fatalf(`given "%s" is not a file`, in.File)
|
||||
}
|
||||
// Necessary check.
|
||||
if gproc.SearchBinary("go") == "" {
|
||||
mlog.Fatalf(`command "go" not found in your environment, please install golang first to proceed this command`)
|
||||
@@ -205,7 +211,7 @@ func (app *cRunApp) End(ctx context.Context, sig os.Signal, outputPath string) {
|
||||
mlog.Debugf("kill process error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
if err := gfile.Remove(outputPath); err != nil {
|
||||
if err := gfile.RemoveFile(outputPath); err != nil {
|
||||
mlog.Printf("delete binary file error: %s", err.Error())
|
||||
} else {
|
||||
mlog.Printf("deleted binary file: %s", outputPath)
|
||||
|
||||
@@ -192,7 +192,7 @@ func (c cUp) doUpgradeCLI(ctx context.Context) (err error) {
|
||||
defer func() {
|
||||
mlog.Printf(`new version cli binary is successfully installed to "%s"`, gfile.SelfPath())
|
||||
mlog.Printf(`remove temporary buffer file "%s"`, localSaveFilePath)
|
||||
_ = gfile.Remove(localSaveFilePath)
|
||||
_ = gfile.RemoveFile(localSaveFilePath)
|
||||
}()
|
||||
|
||||
// It fails if file not exist or its size is less than 1MB.
|
||||
|
||||
@@ -691,3 +691,151 @@ func Test_Gen_Dao_Issue3459(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3749
|
||||
func Test_Gen_Dao_Issue3749(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
db = testDB
|
||||
table = "table_user"
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`issue`, `3749`, `user.tpl.sql`),
|
||||
table,
|
||||
)
|
||||
)
|
||||
dropTableWithDb(db, table)
|
||||
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||
for _, v := range array {
|
||||
if _, err = db.Exec(ctx, v); err != nil {
|
||||
t.AssertNil(err)
|
||||
}
|
||||
}
|
||||
defer dropTableWithDb(db, table)
|
||||
|
||||
var (
|
||||
path = gfile.Temp(guid.S())
|
||||
group = "test"
|
||||
in = gendao.CGenDaoInput{
|
||||
Path: path,
|
||||
Link: link,
|
||||
Group: group,
|
||||
}
|
||||
)
|
||||
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
|
||||
// for go mod import path auto retrieve.
|
||||
err = gfile.Copy(
|
||||
gtest.DataPath("gendao", "go.mod.txt"),
|
||||
gfile.Join(path, "go.mod"),
|
||||
)
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
// files
|
||||
files, err := gfile.ScanDir(path, "*.go", true)
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
filepath.FromSlash(path + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(path + "/dao/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/entity/table_user.go"),
|
||||
})
|
||||
// content
|
||||
testPath := gtest.DataPath(`issue`, `3749`)
|
||||
expectFiles := []string{
|
||||
filepath.FromSlash(testPath + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/dao/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||
}
|
||||
for i, _ := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Gen_Dao_Sqlite3(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
table = "table_user"
|
||||
path = gfile.Temp(guid.S())
|
||||
linkSqlite3 = fmt.Sprintf("sqlite::@file(%s/db.sqlite3)", path)
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`gendao`, `sqlite3`, `user.sqlite3.sql`),
|
||||
table,
|
||||
)
|
||||
)
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
dbSqlite3, err := gdb.New(gdb.ConfigNode{
|
||||
Link: linkSqlite3,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
|
||||
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||
for _, v := range array {
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
if _, err = dbSqlite3.Exec(ctx, v); err != nil {
|
||||
t.AssertNil(err)
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
group = "test"
|
||||
in = gendao.CGenDaoInput{
|
||||
Path: path,
|
||||
Link: linkSqlite3,
|
||||
Group: group,
|
||||
Tables: table,
|
||||
}
|
||||
)
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
// for go mod import path auto retrieve.
|
||||
err = gfile.Copy(
|
||||
gtest.DataPath("gendao", "go.mod.txt"),
|
||||
gfile.Join(path, "go.mod"),
|
||||
)
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
// files
|
||||
files, err := gfile.ScanDir(path, "*.go", true)
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
filepath.FromSlash(path + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(path + "/dao/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/entity/table_user.go"),
|
||||
})
|
||||
// content
|
||||
testPath := gtest.DataPath("gendao", "generated_user_sqlite3")
|
||||
expectFiles := []string{
|
||||
filepath.FromSlash(testPath + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/dao/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||
}
|
||||
for i, _ := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"hotgo/internal/library/hggen/internal/cmd/genpb"
|
||||
)
|
||||
|
||||
func TestGenPbIssue3882(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
outputPath = gfile.Temp(guid.S())
|
||||
outputApiPath = filepath.Join(outputPath, "api")
|
||||
outputCtrlPath = filepath.Join(outputPath, "controller")
|
||||
|
||||
protobufFolder = gtest.DataPath("issue", "3882")
|
||||
in = genpb.CGenPbInput{
|
||||
Path: protobufFolder,
|
||||
OutputApi: outputApiPath,
|
||||
OutputCtrl: outputCtrlPath,
|
||||
}
|
||||
err error
|
||||
)
|
||||
err = gfile.Mkdir(outputApiPath)
|
||||
t.AssertNil(err)
|
||||
err = gfile.Mkdir(outputCtrlPath)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(outputPath)
|
||||
|
||||
_, err = genpb.CGenPb{}.Pb(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
var (
|
||||
genContent = gfile.GetContents(filepath.Join(outputApiPath, "issue3882.pb.go"))
|
||||
exceptText = `dc:"Some comment on field with 'one' 'two' 'three' in the comment."`
|
||||
)
|
||||
t.Assert(gstr.Contains(genContent, exceptText), true)
|
||||
})
|
||||
}
|
||||
@@ -22,9 +22,9 @@ func Test_Gen_Service_Default(t *testing.T) {
|
||||
var (
|
||||
path = gfile.Temp(guid.S())
|
||||
dstFolder = path + filepath.FromSlash("/service")
|
||||
apiFolder = gtest.DataPath("genservice", "logic")
|
||||
srvFolder = gtest.DataPath("genservice", "logic")
|
||||
in = genservice.CGenServiceInput{
|
||||
SrcFolder: apiFolder,
|
||||
SrcFolder: srvFolder,
|
||||
DstFolder: dstFolder,
|
||||
DstFileNameCase: "Snake",
|
||||
WatchFile: "",
|
||||
@@ -46,11 +46,11 @@ func Test_Gen_Service_Default(t *testing.T) {
|
||||
|
||||
// logic file
|
||||
var (
|
||||
genApi = apiFolder + filepath.FromSlash("/logic.go")
|
||||
genApiExpect = apiFolder + filepath.FromSlash("/logic_expect.go")
|
||||
genSrv = srvFolder + filepath.FromSlash("/logic.go")
|
||||
genSrvExpect = srvFolder + filepath.FromSlash("/logic_expect.go")
|
||||
)
|
||||
defer gfile.Remove(genApi)
|
||||
t.Assert(gfile.GetContents(genApi), gfile.GetContents(genApiExpect))
|
||||
defer gfile.Remove(genSrv)
|
||||
t.Assert(gfile.GetContents(genSrv), gfile.GetContents(genSrvExpect))
|
||||
|
||||
// files
|
||||
files, err := gfile.ScanDir(dstFolder, "*.go", true)
|
||||
@@ -73,3 +73,83 @@ func Test_Gen_Service_Default(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3328
|
||||
func Test_Issue3328(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
path = gfile.Temp(guid.S())
|
||||
dstFolder = path + filepath.FromSlash("/service")
|
||||
srvFolder = gtest.DataPath("issue", "3328", "logic")
|
||||
logicGoPath = srvFolder + filepath.FromSlash("/logic.go")
|
||||
in = genservice.CGenServiceInput{
|
||||
SrcFolder: srvFolder,
|
||||
DstFolder: dstFolder,
|
||||
DstFileNameCase: "Snake",
|
||||
WatchFile: "",
|
||||
StPattern: "",
|
||||
Packages: nil,
|
||||
ImportPrefix: "",
|
||||
Clear: false,
|
||||
}
|
||||
)
|
||||
gfile.Remove(logicGoPath)
|
||||
defer gfile.Remove(logicGoPath)
|
||||
|
||||
err := gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
_, err = genservice.CGenService{}.Service(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
files, err := gfile.ScanDir(srvFolder, "*", true)
|
||||
for _, file := range files {
|
||||
if file == logicGoPath {
|
||||
if gfile.IsDir(logicGoPath) {
|
||||
t.Fatalf("%s should not is folder", logicGoPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3835
|
||||
func Test_Issue3835(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
path = gfile.Temp(guid.S())
|
||||
dstFolder = path + filepath.FromSlash("/service")
|
||||
srvFolder = gtest.DataPath("issue", "3835", "logic")
|
||||
in = genservice.CGenServiceInput{
|
||||
SrcFolder: srvFolder,
|
||||
DstFolder: dstFolder,
|
||||
DstFileNameCase: "Snake",
|
||||
WatchFile: "",
|
||||
StPattern: "",
|
||||
Packages: nil,
|
||||
ImportPrefix: "",
|
||||
Clear: false,
|
||||
}
|
||||
)
|
||||
err := gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
_, err = genservice.CGenService{}.Service(ctx, in)
|
||||
t.AssertNil(err)
|
||||
|
||||
// contents
|
||||
var (
|
||||
genFile = dstFolder + filepath.FromSlash("/issue_3835.go")
|
||||
expectFile = gtest.DataPath("issue", "3835", "service", "issue_3835.go")
|
||||
)
|
||||
t.Assert(gfile.GetContents(genFile), gfile.GetContents(expectFile))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func (c CGenCtrl) generateByWatchFile(watchFile, sdkPath string, sdkStdVersion,
|
||||
return
|
||||
}
|
||||
}
|
||||
defer gfile.Remove(flockFilePath)
|
||||
defer gfile.RemoveFile(flockFilePath)
|
||||
_ = gfile.PutContents(flockFilePath, gtime.TimestampStr())
|
||||
|
||||
// check this updated file is an api file.
|
||||
|
||||
@@ -89,7 +89,7 @@ func (c *controllerGenerator) doGenerateCtrlNewByModuleAndVersion(
|
||||
if err = gfile.PutContents(moduleFilePath, gstr.TrimLeft(content)); err != nil {
|
||||
return err
|
||||
}
|
||||
mlog.Printf(`generated: %s`, moduleFilePath)
|
||||
mlog.Printf(`generated: %s`, gfile.RealPath(moduleFilePath))
|
||||
}
|
||||
if !gfile.Exists(moduleFilePathNew) {
|
||||
content := gstr.ReplaceByMap(consts.TemplateGenCtrlControllerNewEmpty, g.MapStrStr{
|
||||
@@ -99,7 +99,7 @@ func (c *controllerGenerator) doGenerateCtrlNewByModuleAndVersion(
|
||||
if err = gfile.PutContents(moduleFilePathNew, gstr.TrimLeft(content)); err != nil {
|
||||
return err
|
||||
}
|
||||
mlog.Printf(`generated: %s`, moduleFilePathNew)
|
||||
mlog.Printf(`generated: %s`, gfile.RealPath(moduleFilePathNew))
|
||||
}
|
||||
filePaths, err := gfile.ScanDir(dstModuleFolderPath, "*.go", false)
|
||||
if err != nil {
|
||||
@@ -161,7 +161,7 @@ func (c *controllerGenerator) doGenerateCtrlItem(dstModuleFolderPath string, ite
|
||||
return err
|
||||
}
|
||||
}
|
||||
mlog.Printf(`generated: %s`, methodFilePath)
|
||||
mlog.Printf(`generated: %s`, gfile.RealPath(methodFilePath))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func (c *controllerGenerator) doGenerateCtrlMergeItem(dstModuleFolderPath string
|
||||
if err = gfile.PutContentsAppend(ctrlFilePath, ctrlFileItem.controllers.String()); err != nil {
|
||||
return err
|
||||
}
|
||||
mlog.Printf(`generated: %s`, ctrlFilePath)
|
||||
mlog.Printf(`generated: %s`, gfile.RealPath(ctrlFilePath))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func (c *controllerClearer) doClear(dstModuleFolderPath string, item apiItem) (e
|
||||
`remove unimplemented and of no api definitions controller file: %s`,
|
||||
methodFilePath,
|
||||
)
|
||||
err = gfile.Remove(methodFilePath)
|
||||
err = gfile.RemoveFile(methodFilePath)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@@ -94,7 +94,7 @@ func (c *apiInterfaceGenerator) doGenerate(apiModuleFolderPath string, module st
|
||||
"{Interfaces}": gstr.TrimRightStr(interfaceDefinition, "\n", 2),
|
||||
}))
|
||||
err = gfile.PutContents(moduleFilePath, interfaceContent)
|
||||
mlog.Printf(`generated: %s`, moduleFilePath)
|
||||
mlog.Printf(`generated: %s`, gfile.RealPath(moduleFilePath))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ func (c *apiSdkGenerator) doGenerateSdkPkgFile(sdkFolderPath string) (err error)
|
||||
"{PkgName}": pkgName,
|
||||
}))
|
||||
err = gfile.PutContents(pkgFilePath, fileContent)
|
||||
mlog.Printf(`generated: %s`, pkgFilePath)
|
||||
mlog.Printf(`generated: %s`, gfile.RealPath(pkgFilePath))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -130,9 +130,9 @@ func (c *apiSdkGenerator) doGenerateSdkIClient(
|
||||
if isDirty {
|
||||
err = gfile.PutContents(iClientFilePath, fileContent)
|
||||
if isExist {
|
||||
mlog.Printf(`updated: %s`, iClientFilePath)
|
||||
mlog.Printf(`updated: %s`, gfile.RealPath(iClientFilePath))
|
||||
} else {
|
||||
mlog.Printf(`generated: %s`, iClientFilePath)
|
||||
mlog.Printf(`generated: %s`, gfile.RealPath(iClientFilePath))
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -183,7 +183,7 @@ func (c *apiSdkGenerator) doGenerateSdkImplementer(
|
||||
implementerFileContent += "\n"
|
||||
}
|
||||
err = gfile.PutContents(implementerFilePath, implementerFileContent)
|
||||
mlog.Printf(`generated: %s`, implementerFilePath)
|
||||
mlog.Printf(`generated: %s`, gfile.RealPath(implementerFilePath))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -208,9 +208,11 @@ type (
|
||||
NoModelComment bool `name:"noModelComment" short:"m" brief:"{CGenDaoBriefNoModelComment}" orphan:"true"`
|
||||
Clear bool `name:"clear" short:"a" brief:"{CGenDaoBriefClear}" orphan:"true"`
|
||||
|
||||
TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenDaoBriefTypeMapping}" orphan:"true"`
|
||||
FieldMapping map[DBTableFieldName]CustomAttributeType `name:"fieldMapping" short:"fm" brief:"{CGenDaoBriefFieldMapping}" orphan:"true"`
|
||||
genItems *CGenDaoInternalGenItems
|
||||
TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenDaoBriefTypeMapping}" orphan:"true"`
|
||||
FieldMapping map[DBTableFieldName]CustomAttributeType `name:"fieldMapping" short:"fm" brief:"{CGenDaoBriefFieldMapping}" orphan:"true"`
|
||||
|
||||
// internal usage purpose.
|
||||
genItems *CGenDaoInternalGenItems
|
||||
}
|
||||
CGenDaoOutput struct{}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ func doClearItem(item CGenDaoInternalGenItem, allGeneratedFilePaths []string) {
|
||||
}
|
||||
for _, filePath := range generatedFilePaths {
|
||||
if !gstr.InArray(allGeneratedFilePaths, filePath) {
|
||||
if err := gfile.Remove(filePath); err != nil {
|
||||
if err := gfile.RemoveFile(filePath); err != nil {
|
||||
mlog.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ func generateDaoSingle(ctx context.Context, in generateDaoSingleInput) {
|
||||
mlog.Fatalf(`fetching tables fields failed for table "%s": %+v`, in.TableName, err)
|
||||
}
|
||||
var (
|
||||
tableNameCamelCase = gstr.CaseCamel(strings.ToLower(in.NewTableName))
|
||||
tableNameCamelLowerCase = gstr.CaseCamelLower(strings.ToLower(in.NewTableName))
|
||||
tableNameCamelCase = formatFieldName(in.NewTableName, FieldNameCaseCamel)
|
||||
tableNameCamelLowerCase = formatFieldName(in.NewTableName, FieldNameCaseCamelLower)
|
||||
tableNameSnakeCase = gstr.CaseSnake(in.NewTableName)
|
||||
importPrefix = in.ImportPrefix
|
||||
)
|
||||
@@ -123,7 +123,7 @@ func generateDaoIndex(in generateDaoIndexInput) {
|
||||
mlog.Fatalf("writing content to '%s' failed: %v", path, err)
|
||||
} else {
|
||||
utils.GoFmt(path)
|
||||
mlog.Print("generated:", path)
|
||||
mlog.Print("generated:", gfile.RealPath(path))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ func generateDaoInternal(in generateDaoInternalInput) {
|
||||
mlog.Fatalf("writing content to '%s' failed: %v", path, err)
|
||||
} else {
|
||||
utils.GoFmt(path)
|
||||
mlog.Print("generated:", path)
|
||||
mlog.Print("generated:", gfile.RealPath(path))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ func generateColumnNamesForDao(fieldMap map[string]*gdb.TableField, removeFieldP
|
||||
}
|
||||
|
||||
array[index] = []string{
|
||||
" #" + gstr.CaseCamel(strings.ToLower(newFiledName)) + ":",
|
||||
" #" + formatFieldName(newFiledName, FieldNameCaseCamel) + ":",
|
||||
fmt.Sprintf(` #"%s",`, field.Name),
|
||||
}
|
||||
}
|
||||
@@ -219,7 +219,7 @@ func generateColumnDefinitionForDao(fieldMap map[string]*gdb.TableField, removeF
|
||||
newFiledName = gstr.TrimLeftStr(newFiledName, v, 1)
|
||||
}
|
||||
array[index] = []string{
|
||||
" #" + gstr.CaseCamel(strings.ToLower(newFiledName)),
|
||||
" #" + formatFieldName(newFiledName, FieldNameCaseCamel),
|
||||
" # " + "string",
|
||||
" #" + fmt.Sprintf(`// %s`, comment),
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
|
||||
structDefinition, _ = generateStructDefinition(ctx, generateStructDefinitionInput{
|
||||
CGenDaoInternalInput: in,
|
||||
TableName: tableName,
|
||||
StructName: gstr.CaseCamel(strings.ToLower(newTableName)),
|
||||
StructName: formatFieldName(newTableName, FieldNameCaseCamel),
|
||||
FieldMap: fieldMap,
|
||||
IsDo: true,
|
||||
})
|
||||
@@ -61,7 +61,7 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
|
||||
ctx,
|
||||
in,
|
||||
tableName,
|
||||
gstr.CaseCamel(strings.ToLower(newTableName)),
|
||||
formatFieldName(newTableName, FieldNameCaseCamel),
|
||||
structDefinition,
|
||||
)
|
||||
in.genItems.AppendGeneratedFilePath(doFilePath)
|
||||
@@ -70,7 +70,7 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
|
||||
mlog.Fatalf(`writing content to "%s" failed: %v`, doFilePath, err)
|
||||
} else {
|
||||
utils.GoFmt(doFilePath)
|
||||
mlog.Print("generated:", doFilePath)
|
||||
mlog.Print("generated:", gfile.RealPath(doFilePath))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func generateEntity(ctx context.Context, in CGenDaoInternalInput) {
|
||||
structDefinition, appendImports = generateStructDefinition(ctx, generateStructDefinitionInput{
|
||||
CGenDaoInternalInput: in,
|
||||
TableName: tableName,
|
||||
StructName: gstr.CaseCamel(strings.ToLower(newTableName)),
|
||||
StructName: formatFieldName(newTableName, FieldNameCaseCamel),
|
||||
FieldMap: fieldMap,
|
||||
IsDo: false,
|
||||
})
|
||||
@@ -44,7 +44,7 @@ func generateEntity(ctx context.Context, in CGenDaoInternalInput) {
|
||||
ctx,
|
||||
in,
|
||||
newTableName,
|
||||
gstr.CaseCamel(strings.ToLower(newTableName)),
|
||||
formatFieldName(newTableName, FieldNameCaseCamel),
|
||||
structDefinition,
|
||||
appendImports,
|
||||
)
|
||||
@@ -55,7 +55,7 @@ func generateEntity(ctx context.Context, in CGenDaoInternalInput) {
|
||||
mlog.Fatalf("writing content to '%s' failed: %v", entityFilePath, err)
|
||||
} else {
|
||||
utils.GoFmt(entityFilePath)
|
||||
mlog.Print("generated:", entityFilePath)
|
||||
mlog.Print("generated:", gfile.RealPath(entityFilePath))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ func generateStructFieldDefinition(
|
||||
}
|
||||
localTypeNameStr = string(localTypeName)
|
||||
switch localTypeName {
|
||||
case gdb.LocalTypeDate, gdb.LocalTypeDatetime:
|
||||
case gdb.LocalTypeDate, gdb.LocalTypeTime, gdb.LocalTypeDatetime:
|
||||
if in.StdTime {
|
||||
localTypeNameStr = "time.Time"
|
||||
} else {
|
||||
@@ -140,7 +140,7 @@ func generateStructFieldDefinition(
|
||||
}
|
||||
|
||||
attrLines = []string{
|
||||
" #" + gstr.CaseCamel(strings.ToLower(newFiledName)),
|
||||
" #" + formatFieldName(newFiledName, FieldNameCaseCamel),
|
||||
" #" + localTypeNameStr,
|
||||
}
|
||||
attrLines = append(attrLines, fmt.Sprintf(` #%sjson:"%s"`, tagKey, jsonTag))
|
||||
@@ -167,6 +167,43 @@ func generateStructFieldDefinition(
|
||||
return attrLines, appendImport
|
||||
}
|
||||
|
||||
type FieldNameCase string
|
||||
|
||||
const (
|
||||
FieldNameCaseCamel FieldNameCase = "CaseCamel"
|
||||
FieldNameCaseCamelLower FieldNameCase = "CaseCamelLower"
|
||||
)
|
||||
|
||||
// formatFieldName formats and returns a new field name that is used for golang codes generating.
|
||||
func formatFieldName(fieldName string, nameCase FieldNameCase) string {
|
||||
// For normal databases like mysql, pgsql, sqlite,
|
||||
// field/table names of that are in normal case.
|
||||
var newFieldName = fieldName
|
||||
if isAllUpper(fieldName) {
|
||||
// For special databases like dm, oracle,
|
||||
// field/table names of that are in upper case.
|
||||
newFieldName = strings.ToLower(fieldName)
|
||||
}
|
||||
switch nameCase {
|
||||
case FieldNameCaseCamel:
|
||||
return gstr.CaseCamel(newFieldName)
|
||||
case FieldNameCaseCamelLower:
|
||||
return gstr.CaseCamelLower(newFieldName)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// isAllUpper checks and returns whether given `fieldName` all letters are upper case.
|
||||
func isAllUpper(fieldName string) bool {
|
||||
for _, b := range fieldName {
|
||||
if b >= 'a' && b <= 'z' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// formatComment formats the comment string to fit the golang code without any lines.
|
||||
func formatComment(comment string) string {
|
||||
comment = gstr.ReplaceByArray(comment, g.SliceStr{
|
||||
|
||||
@@ -94,6 +94,9 @@ func (c CGenPb) Pb(ctx context.Context, in CGenPbInput) (out *CGenPbOutput, err
|
||||
mlog.Fatalf(`no proto files found in folder "%s"`, in.Path)
|
||||
}
|
||||
|
||||
var originPwd = gfile.Pwd()
|
||||
defer gfile.Chdir(originPwd)
|
||||
|
||||
if err = gfile.Chdir(protoPath); err != nil {
|
||||
mlog.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
@@ -90,8 +91,12 @@ func (c CGenPb) tagCommentIntoListMap(comment string, lineTagMap *gmap.ListMap)
|
||||
lineTagMap.Set(tagName, lineTagMap.GetVar(tagName).String()+tagContent)
|
||||
} else {
|
||||
var (
|
||||
tagName = "dc"
|
||||
tagContent = comment
|
||||
tagName = "dc"
|
||||
// Convert backticks and double quotes to single quotes.
|
||||
tagContent = gstr.ReplaceByMap(comment, g.MapStrStr{
|
||||
"`": `'`,
|
||||
`"`: `'`,
|
||||
})
|
||||
)
|
||||
lineTagMap.Set(tagName, lineTagMap.GetVar(tagName).String()+tagContent)
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ func generatePbEntityContentFile(ctx context.Context, in CGenPbEntityInternalInp
|
||||
if err := gfile.PutContents(path, strings.TrimSpace(entityContent)); err != nil {
|
||||
mlog.Fatalf("writing content to '%s' failed: %v", path, err)
|
||||
} else {
|
||||
mlog.Print("generated:", path)
|
||||
mlog.Print("generated:", gfile.RealPath(path))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ func (c CGenService) Service(ctx context.Context, in CGenServiceInput) (out *CGe
|
||||
return
|
||||
}
|
||||
}
|
||||
defer gfile.Remove(flockFilePath)
|
||||
defer gfile.RemoveFile(flockFilePath)
|
||||
_ = gfile.PutContents(flockFilePath, gtime.TimestampStr())
|
||||
|
||||
// It works only if given WatchFile is in SrcFolder.
|
||||
@@ -253,7 +253,7 @@ func (c CGenService) Service(ctx context.Context, in CGenServiceInput) (out *CGe
|
||||
utils.IsFileDoNotEdit(relativeFilePath) {
|
||||
|
||||
mlog.Printf(`remove no longer used service file: %s`, relativeFilePath)
|
||||
if err = gfile.Remove(file); err != nil {
|
||||
if err = gfile.RemoveFile(file); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -289,7 +289,7 @@ func (c CGenService) checkAndUpdateMain(srcFolder string) (err error) {
|
||||
var (
|
||||
logicPackageName = gstr.ToLower(gfile.Basename(srcFolder))
|
||||
logicFilePath = gfile.Join(srcFolder, logicPackageName+".go")
|
||||
importPath = utils.GetImportPath(logicFilePath)
|
||||
importPath = utils.GetImportPath(srcFolder)
|
||||
importStr = fmt.Sprintf(`_ "%s"`, importPath)
|
||||
mainFilePath = gfile.Join(gfile.Dir(gfile.Dir(gfile.Dir(logicFilePath))), "main.go")
|
||||
mainFileContent = gfile.GetContents(mainFilePath)
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"go/token"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
type pkgItem struct {
|
||||
@@ -78,12 +79,19 @@ func (c CGenService) parseImportPackages(node *ast.ImportSpec) (packages pkgItem
|
||||
path = node.Path.Value
|
||||
rawImport string
|
||||
)
|
||||
|
||||
if node.Name != nil {
|
||||
alias = node.Name.Name
|
||||
rawImport = alias + " " + path
|
||||
rawImport = node.Name.Name + " " + path
|
||||
} else {
|
||||
rawImport = path
|
||||
}
|
||||
|
||||
// if the alias is empty, it will further retrieve the real alias.
|
||||
if alias == "" {
|
||||
alias = c.getRealAlias(path)
|
||||
}
|
||||
|
||||
return pkgItem{
|
||||
Alias: alias,
|
||||
Path: path,
|
||||
@@ -91,6 +99,33 @@ func (c CGenService) parseImportPackages(node *ast.ImportSpec) (packages pkgItem
|
||||
}
|
||||
}
|
||||
|
||||
// getRealAlias retrieves the real alias of the package.
|
||||
// If package is "github.com/gogf/gf", the alias is "gf".
|
||||
// If package is "github.com/gogf/gf/v2", the alias is "gf" instead of "v2".
|
||||
func (c CGenService) getRealAlias(importPath string) (pkgName string) {
|
||||
importPath = gstr.Trim(importPath, `"`)
|
||||
parts := gstr.Split(importPath, "/")
|
||||
if len(parts) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
pkgName = parts[len(parts)-1]
|
||||
|
||||
if !gstr.HasPrefix(pkgName, "v") {
|
||||
return pkgName
|
||||
}
|
||||
|
||||
if len(parts) < 2 {
|
||||
return pkgName
|
||||
}
|
||||
|
||||
if gstr.IsNumeric(gstr.SubStr(pkgName, 1)) {
|
||||
pkgName = parts[len(parts)-2]
|
||||
}
|
||||
|
||||
return pkgName
|
||||
}
|
||||
|
||||
// parseFuncReceiverTypeName retrieves the receiver type of the function.
|
||||
// For example:
|
||||
//
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -75,28 +75,24 @@ func ReplaceGeneratedContentGFV2(folderPath string) (err error) {
|
||||
}, folderPath, "*.go", true)
|
||||
}
|
||||
|
||||
// GetImportPath calculates and returns the golang import path for given `filePath`.
|
||||
// GetImportPath calculates and returns the golang import path for given `dirPath`.
|
||||
// Note that it needs a `go.mod` in current working directory or parent directories to detect the path.
|
||||
func GetImportPath(filePath string) string {
|
||||
func GetImportPath(dirPath string) string {
|
||||
// If `filePath` does not exist, create it firstly to find the import path.
|
||||
var realPath = gfile.RealPath(filePath)
|
||||
var realPath = gfile.RealPath(dirPath)
|
||||
if realPath == "" {
|
||||
_ = gfile.Mkdir(filePath)
|
||||
realPath = gfile.RealPath(filePath)
|
||||
_ = gfile.Mkdir(dirPath)
|
||||
realPath = gfile.RealPath(dirPath)
|
||||
}
|
||||
|
||||
var (
|
||||
newDir = gfile.Dir(realPath)
|
||||
oldDir string
|
||||
suffix string
|
||||
suffix = gfile.Basename(dirPath)
|
||||
goModName = "go.mod"
|
||||
goModPath string
|
||||
importPath string
|
||||
)
|
||||
|
||||
if gfile.IsDir(filePath) {
|
||||
suffix = gfile.Basename(filePath)
|
||||
}
|
||||
for {
|
||||
goModPath = gfile.Join(newDir, goModName)
|
||||
if gfile.Exists(goModPath) {
|
||||
|
||||
@@ -796,7 +796,7 @@ func (s *sAdminMember) VerifySuperId(ctx context.Context, verifyId int64) bool {
|
||||
|
||||
// LoadSuperAdmin 加载超管数据
|
||||
func (s *sAdminMember) LoadSuperAdmin(ctx context.Context) {
|
||||
value, err := dao.AdminRole.Ctx(ctx).Where(dao.AdminRole.Columns().Key, consts.SuperRoleKey).Value()
|
||||
value, err := dao.AdminRole.Ctx(ctx).Fields("id").Where(dao.AdminRole.Columns().Key, consts.SuperRoleKey).Value()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "LoadSuperAdmin AdminRole err:%+v", err)
|
||||
return
|
||||
|
||||
@@ -130,7 +130,8 @@ func (s *sSysOptionTreeDemo) Delete(ctx context.Context, in *sysin.OptionTreeDem
|
||||
if count > 0 {
|
||||
return gerror.New("请先删除该选项树表下的所有下级!")
|
||||
}
|
||||
if _, err = s.Model(ctx).WherePri(in.Id).Delete(); err != nil {
|
||||
|
||||
if _, err = s.Model(ctx).WherePri(in.Id).Unscoped().Delete(); err != nil {
|
||||
err = gerror.Wrap(err, "删除选项树表失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.15.1
|
||||
// @AutoGenerate Version 2.15.7
|
||||
package sys
|
||||
|
||||
import (
|
||||
@@ -108,7 +108,7 @@ func (s *sSysTestCategory) Edit(ctx context.Context, in *sysin.TestCategoryEditI
|
||||
// Delete 删除测试分类
|
||||
func (s *sSysTestCategory) Delete(ctx context.Context, in *sysin.TestCategoryDeleteInp) (err error) {
|
||||
|
||||
if _, err = s.Model(ctx).WherePri(in.Id).Delete(); err != nil {
|
||||
if _, err = s.Model(ctx).WherePri(in.Id).Unscoped().Delete(); err != nil {
|
||||
err = gerror.Wrap(err, "删除测试分类失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
@@ -164,4 +164,4 @@ func (s *sSysTestCategory) Option(ctx context.Context) (opts []*model.Option, er
|
||||
opts[k] = dict.GenHashOption(v.Id, gconv.String(v.Name))
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.15.1
|
||||
// @AutoGenerate Version 2.15.7
|
||||
package sysin
|
||||
|
||||
import (
|
||||
@@ -140,4 +140,4 @@ func (in *TestCategoryStatusInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type TestCategoryStatusModel struct{}
|
||||
type TestCategoryStatusModel struct{}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
// @Copyright Copyright (c) 2024 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.15.1
|
||||
// @AutoGenerate Version 2.15.7
|
||||
package genrouter
|
||||
|
||||
import "hotgo/internal/controller/admin/sys"
|
||||
|
||||
func init() {
|
||||
LoginRequiredRouter = append(LoginRequiredRouter, sys.TestCategory) // 测试分类
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user