Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gogf/gf into feature/go-1.20-pola…
Browse files Browse the repository at this point in the history
…ris-config

* 'master' of github.com:gogf/gf: (23 commits)
  build(go.mod): upgrade minimum required go version from 1.18 to 1.20 (#3688)
  refactor(net/ghttp): enhance `ghttp.StartPProfServer` (#3555)
  refactor(encoding/gjson): change data parameter from type any to []byte (#3542)
  refactor(net/gudp): improve implements (#3491)
  fix(os/gcache): memory leak for LRU when adding operations more faster than deleting (#3823)
  fix(os/gcmd): argument index calculating error in multilevel command (#3807)
  fix(database/gdb): invalid order by statement generated when multiple order inputs (#3803)
  fix(cmd/gf): creating logic.go empty folder when there is no correct logic service (#3815)
  test(drivers/mysql): loose unit testing for transaction (#3819)
  fix(net/ghttp&gclient,contrib/rpc/grpcx): remove request and response contents in opentelemetry tracing attributes (#3810)
  feat: new version v2.7.4 (#3809)
  fix(util/gconv): unstable converting when there is an external attribute with the same name as the internal structure (#3799)
  feat(database/gdb): add year field type support for ORM operations (#3805)
  fix(cmd/gf): table and field names converted to its lower case before CamelCase converting in command `gen dao` (#3801)
  fix(net/gclient): panic when containing `@file:` parameter value in json post request (#3775)
  feat(contrib/registry/etcd/): add `DialTimeout` and `AutoSyncInterval` option (#3698)
  fix(database/gdb): support OrderRandom feature in different databases (#3794)
  fix(net/goai): change default value of RequestBody.Required from true to false, add required tag support for RequestBody (#3796)
  fix(util/gvalid): retrive empty slice parameter in custom validation rule function failed (#3795)
  fix(util/gconv): cached field indexes append issue caused incorrect field converting (#3790)
  ...

# Conflicts:
#	.github/workflows/ci-main.sh
#	.github/workflows/golangci-lint.yml
#	contrib/metric/otelmetric/go.mod
  • Loading branch information
houseme committed Sep 28, 2024
2 parents 2cd3d0c + ab3fbdd commit b1cf8ba
Show file tree
Hide file tree
Showing 178 changed files with 3,798 additions and 2,173 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/ci-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ for file in `find . -name go.mod`; do
dirpath=$(dirname $file)
echo $dirpath

# ignore mssql tests as its docker service failed
# TODO remove this ignoring codes after the mssql docker service OK
if [ "mssql" = $(basename $dirpath) ]; then
continue 1
fi

if [[ $file =~ "/testdata/" ]]; then
echo "ignore testdata path $file"
continue 1
fi

# package kuhecm needs golang >= v1.19
# package kuhecm was moved to sub ci procedure.
if [ "kubecm" = $(basename $dirpath) ]; then
continue 1
if ! go version|grep -qE "go1.[2-9][0-9]"; then
echo "ignore kubecm as go version: $(go version)"
continue 1
fi
fi

# package consul needs golang >= v1.19
if [ "consul" = $(basename $dirpath) ]; then
continue 1
if ! go version|grep -qE "go1.[2-9][0-9]"; then
echo "ignore consul as go version: $(go version)"
continue 1
Expand Down
39 changes: 23 additions & 16 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ jobs:
- 6379:6379

# MySQL backend server.
# docker run -d --name mysql \
# -p 3306:3306 \
# -e MYSQL_DATABASE=test \
# -e MYSQL_ROOT_PASSWORD=12345678 \
# loads/mysql:5.7
mysql:
image: loads/mysql:5.7
env:
Expand Down Expand Up @@ -108,22 +113,24 @@ jobs:
# -e MSSQL_USER=root \
# -e MSSQL_PASSWORD=LoremIpsum86 \
# loads/mssqldocker:14.0.3391.2
mssql:
image: loads/mssqldocker:14.0.3391.2
env:
ACCEPT_EULA: Y
SA_PASSWORD: LoremIpsum86
MSSQL_DB: test
MSSQL_USER: root
MSSQL_PASSWORD: LoremIpsum86
ports:
- 1433:1433
options: >-
--health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P LoremIpsum86 -l 30 -Q \"SELECT 1\" || exit 1"
--health-start-period 10s
--health-interval 10s
--health-timeout 5s
--health-retries 10

# TODO mssql docker failed, will be enabled later after it is OK in github action.
# mssql:
# image: loads/mssqldocker:14.0.3391.2
# env:
# ACCEPT_EULA: Y
# SA_PASSWORD: LoremIpsum86
# MSSQL_DB: test
# MSSQL_USER: root
# MSSQL_PASSWORD: LoremIpsum86
# ports:
# - 1433:1433
# options: >-
# --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P LoremIpsum86 -l 30 -Q \"SELECT 1\" || exit 1"
# --health-start-period 10s
# --health-interval 10s
# --health-timeout 5s
# --health-retries 10

# ClickHouse backend server.
# docker run -d --name clickhouse \
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: doc-build
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
- name: Set Up Golang Environment
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.22.5
cache: false
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Build website
run: npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
golangci:
strategy:
matrix:
go-version: [ '1.20','1.21.4','1.22', "1.23" ]
go-version: [ '1.20','1.21.4','1.22', '1.23' ]
name: golangci-lint
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bin/
cmd/gf/main
cmd/gf/gf
temp/
example/log
go.work
go.work.sum
!cmd/gf/go.work
Expand Down
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ linters-settings:
# Checks the number of lines in a function.
# If lower than 0, disable the check.
# Default: 60
lines: 330
lines: 340
# Checks the number of statements in a function.
# If lower than 0, disable the check.
# Default: 40
Expand Down Expand Up @@ -180,6 +180,9 @@ linters-settings:

# https://golangci-lint.run/usage/linters/#govet
govet:
# Report about shadowed variables.
# Default: false
# check-shadowing: true
# Settings per analyzer.
settings:
# Analyzer name, run `go tool vet help` to see all analyzers.
Expand Down
14 changes: 7 additions & 7 deletions cmd/gf/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module github.com/gogf/gf/cmd/gf/v2
go 1.18

require (
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.7.3
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.7.3
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.3
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.7.3
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.7.3
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.7.3
github.com/gogf/gf/v2 v2.7.3
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.7.4
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.7.4
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.4
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.7.4
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.7.4
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.7.4
github.com/gogf/gf/v2 v2.7.4
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f
github.com/olekukonko/tablewriter v0.0.5
golang.org/x/mod v0.17.0
Expand Down
14 changes: 14 additions & 0 deletions cmd/gf/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiU
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.7.4 h1:FC2/bxPLlEq2v/X7CmtLsnnQEu3qtVgzhhDV8cTCBAs=
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.7.4/go.mod h1:EflLqMm5SHvq+w+0CmCFPzlbIgpihMacxgA8Uao2NwE=
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.7.4 h1:tYPmYj7gUgS5UstZ0MRxx0xVlP8d3+T8Y2rjdVbx13M=
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.7.4/go.mod h1:f/TlOcTI2P5WoLjXeFTdT9bMgXjLe+s/x4YG87Wgxeg=
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.4 h1:Rhv48tVnl+o5qyd1hTLxKStWT7MEqP0zrEXKa/t4VLg=
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.4/go.mod h1:V6eAZVlFWv4AgDK7VzLbwMZiOygcu/374Rcyhv9hSEM=
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.7.4 h1:ZjmvcrSXzNQXXrTOxjrBjY2mPI2ODfg+Kc0rT+yMmQM=
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.7.4/go.mod h1:1weG4QVTWzr9Gv0H4eK8MnEKlxrq5n7uM27595IW/5U=
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.7.4 h1:6eaV81MUtE7NUqYR95wOLQcdZ+OlLxn2GEs+rN+wtrM=
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.7.4/go.mod h1:JjZO8Ic5UxnFVtEY4cDkpFQQ1tx7pX7ZAQnlJ8ux0Kc=
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.7.4 h1:5AQnCRADGyUogYHjzq618stY8Jdd23l2n/tL3jEuEBQ=
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.7.4/go.mod h1:aYE4mSx8x4hnOxiClDkQnwAXrTFOfaKF+tSCGDxSYaw=
github.com/gogf/gf/v2 v2.7.4 h1:cGHUBO5Jr8ty21GN5EO+S2rFYhprdcqnwS7PnWL7+t4=
github.com/gogf/gf/v2 v2.7.4/go.mod h1:EBXneAg/wes86rfeh68XC0a2JBNQylmT7Sp6/8Axk88=
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f h1:7xfXR/BhG3JDqO1s45n65Oyx9t4E/UqDOXep6jXdLCM=
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f/go.mod h1:HnYoio6S7VaFJdryKcD/r9HgX+4QzYfr00XiXUo/xz0=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand Down
2 changes: 1 addition & 1 deletion cmd/gf/internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
71 changes: 71 additions & 0 deletions cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,3 +691,74 @@ 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]))
}
})
}
43 changes: 43 additions & 0 deletions cmd/gf/internal/cmd/cmd_z_unit_gen_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,46 @@ 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")
apiFolder = gtest.DataPath("issue", "3328", "logic")
logicGoPath = apiFolder + filepath.FromSlash("/logic.go")
in = genservice.CGenServiceInput{
SrcFolder: apiFolder,
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(apiFolder, "*", true)
for _, file := range files {
if file == logicGoPath {
if gfile.IsDir(logicGoPath) {
t.Fatalf("%s should not is folder", logicGoPath)
}
}
}
})
}
8 changes: 5 additions & 3 deletions cmd/gf/internal/cmd/gendao/gendao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
8 changes: 4 additions & 4 deletions cmd/gf/internal/cmd/gendao/gendao_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -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),
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/gf/internal/cmd/gendao/gendao_do.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand All @@ -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)
Expand Down
Loading

0 comments on commit b1cf8ba

Please sign in to comment.