diff --git a/.gitignore b/.gitignore
index f07ed0208..5af57e523 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,4 +15,5 @@ cbuild
**/.DS_Store
.vscode/
.test/
-main
\ No newline at end of file
+main
+gf
\ No newline at end of file
diff --git a/cmd/gf/go.mod b/cmd/gf/go.mod
index 55dfbae17..430fb4783 100644
--- a/cmd/gf/go.mod
+++ b/cmd/gf/go.mod
@@ -3,9 +3,9 @@ module github.com/gogf/gf/cmd/gf/v2
go 1.15
require (
- github.com/gogf/gf/contrib/drivers/mssql/v2 v2.0.0-rc
- github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.0.0-rc
- github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.0.0-rc
+ github.com/gogf/gf/contrib/drivers/mssql/v2 v2.0.0-rc2
+ github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.0.0-rc2
+ github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.0.0-rc2
github.com/gogf/gf/v2 v2.0.0-rc
github.com/olekukonko/tablewriter v0.0.5
)
diff --git a/cmd/gf/internal/cmd/cmd_gen_dao.go b/cmd/gf/internal/cmd/cmd_gen_dao.go
index 8267e8556..4528da444 100644
--- a/cmd/gf/internal/cmd/cmd_gen_dao.go
+++ b/cmd/gf/internal/cmd/cmd_gen_dao.go
@@ -43,7 +43,7 @@ gf gen dao -r user_
CONFIGURATION SUPPORT
Options are also supported by configuration file.
It's suggested using configuration file instead of command line arguments making producing.
- The configuration node name is "gf.gen.dao", which also supports multiple databases, for example(config.yaml):
+ The configuration node name is "gfcli.gen.dao", which also supports multiple databases, for example(config.yaml):
gfcli:
gen:
dao:
@@ -63,6 +63,7 @@ CONFIGURATION SUPPORT
cGenDaoBriefPrefix = `add prefix for all table of specified link/database tables`
cGenDaoBriefRemovePrefix = `remove specified prefix of the table, multiple prefix separated with ','`
cGenDaoBriefStdTime = `use time.Time from stdlib instead of gtime.Time for generated time/date fields of tables`
+ cGenDaoBriefWithTime = `add created time for auto produced go files`
cGenDaoBriefGJsonSupport = `use gJsonSupport to use *gjson.Json instead of string for generated json fields of tables`
cGenDaoBriefImportPrefix = `custom import prefix for generated go files`
cGenDaoBriefOverwriteDao = `overwrite all dao files both inside/outside internal folder`
@@ -97,7 +98,7 @@ generated json tag case for model struct, cases are as follows:
tplVarColumnDefine = `{TplColumnDefine}`
tplVarColumnNames = `{TplColumnNames}`
tplVarGroupName = `{TplGroupName}`
- tplVarDatetime = `{TplDatetime}`
+ tplVarDatetimeStr = `{TplDatetimeStr}`
)
var (
@@ -118,6 +119,7 @@ func init() {
`cGenDaoBriefPrefix`: cGenDaoBriefPrefix,
`cGenDaoBriefRemovePrefix`: cGenDaoBriefRemovePrefix,
`cGenDaoBriefStdTime`: cGenDaoBriefStdTime,
+ `cGenDaoBriefWithTime`: cGenDaoBriefWithTime,
`cGenDaoBriefGJsonSupport`: cGenDaoBriefGJsonSupport,
`cGenDaoBriefImportPrefix`: cGenDaoBriefImportPrefix,
`cGenDaoBriefOverwriteDao`: cGenDaoBriefOverwriteDao,
@@ -144,6 +146,7 @@ type (
JsonCase string `name:"jsonCase" short:"j" brief:"{cGenDaoBriefJsonCase}" d:"CamelLower"`
ImportPrefix string `name:"importPrefix" short:"i" brief:"{cGenDaoBriefImportPrefix}"`
StdTime bool `name:"stdTime" short:"s" brief:"{cGenDaoBriefStdTime}" orphan:"true"`
+ WithTime bool `name:"withTime" short:"c" brief:"{cGenDaoBriefWithTime}" orphan:"true"`
GJsonSupport bool `name:"gJsonSupport" short:"n" brief:"{cGenDaoBriefGJsonSupport}" orphan:"true"`
OverwriteDao bool `name:"overwriteDao" short:"o" brief:"{cGenDaoBriefOverwriteDao}" orphan:"true"`
DescriptionTag bool `name:"descriptionTag" short:"d" brief:"{cGenDaoBriefDescriptionTag}" orphan:"true"`
@@ -319,10 +322,10 @@ func generateDao(ctx context.Context, db gdb.DB, in cGenDaoInternalInput) {
}
// dao - index
- generateDaoIndex(tableNameCamelCase, tableNameCamelLowerCase, importPrefix, dirPathDao, fileName, in)
+ generateDaoIndex(in, tableNameCamelCase, tableNameCamelLowerCase, importPrefix, dirPathDao, fileName)
// dao - internal
- generateDaoInternal(tableNameCamelCase, tableNameCamelLowerCase, importPrefix, dirPathDao, fileName, fieldMap, in)
+ generateDaoInternal(in, tableNameCamelCase, tableNameCamelLowerCase, importPrefix, dirPathDao, fileName, fieldMap)
}
func generateDo(ctx context.Context, db gdb.DB, tableNames, newTableNames []string, in cGenDaoInternalInput) {
@@ -362,6 +365,7 @@ func generateDo(ctx context.Context, db gdb.DB, tableNames, newTableNames []stri
},
)
modelContent := generateDoContent(
+ in,
tableName,
gstr.CaseCamel(newTableName),
structDefinition,
@@ -391,6 +395,7 @@ func generateEntity(ctx context.Context, db gdb.DB, tableNames, newTableNames []
newTableName = newTableNames[i]
entityFilePath = gfile.Join(entityDirPath, gstr.CaseSnake(newTableName)+".go")
entityContent = generateEntityContent(
+ in,
newTableName,
gstr.CaseCamel(newTableName),
generateStructDefinition(generateStructDefinitionInput{
@@ -440,29 +445,29 @@ func getImportPartContent(source string, isDo bool) string {
return packageImportsStr
}
-func generateEntityContent(tableName, tableNameCamelCase, structDefine string) string {
+func generateEntityContent(in cGenDaoInternalInput, tableName, tableNameCamelCase, structDefine string) string {
entityContent := gstr.ReplaceByMap(consts.TemplateGenDaoEntityContent, g.MapStrStr{
tplVarTableName: tableName,
tplVarPackageImports: getImportPartContent(structDefine, false),
tplVarTableNameCamelCase: tableNameCamelCase,
tplVarStructDefine: structDefine,
})
- entityContent = replaceDefaultVar(entityContent)
+ entityContent = replaceDefaultVar(in, entityContent)
return entityContent
}
-func generateDoContent(tableName, tableNameCamelCase, structDefine string) string {
+func generateDoContent(in cGenDaoInternalInput, tableName, tableNameCamelCase, structDefine string) string {
doContent := gstr.ReplaceByMap(consts.TemplateGenDaoDoContent, g.MapStrStr{
tplVarTableName: tableName,
tplVarPackageImports: getImportPartContent(structDefine, true),
tplVarTableNameCamelCase: tableNameCamelCase,
tplVarStructDefine: structDefine,
})
- doContent = replaceDefaultVar(doContent)
+ doContent = replaceDefaultVar(in, doContent)
return doContent
}
-func generateDaoIndex(tableNameCamelCase, tableNameCamelLowerCase, importPrefix, dirPathDao, fileName string, in cGenDaoInternalInput) {
+func generateDaoIndex(in cGenDaoInternalInput, tableNameCamelCase, tableNameCamelLowerCase, importPrefix, dirPathDao, fileName string) {
path := gfile.Join(dirPathDao, fileName+".go")
if in.OverwriteDao || !gfile.Exists(path) {
indexContent := gstr.ReplaceByMap(getTplDaoIndexContent(""), g.MapStrStr{
@@ -471,7 +476,7 @@ func generateDaoIndex(tableNameCamelCase, tableNameCamelLowerCase, importPrefix,
tplVarTableNameCamelCase: tableNameCamelCase,
tplVarTableNameCamelLowerCase: tableNameCamelLowerCase,
})
- indexContent = replaceDefaultVar(indexContent)
+ indexContent = replaceDefaultVar(in, indexContent)
if err := gfile.PutContents(path, strings.TrimSpace(indexContent)); err != nil {
mlog.Fatalf("writing content to '%s' failed: %v", path, err)
} else {
@@ -482,10 +487,10 @@ func generateDaoIndex(tableNameCamelCase, tableNameCamelLowerCase, importPrefix,
}
func generateDaoInternal(
+ in cGenDaoInternalInput,
tableNameCamelCase, tableNameCamelLowerCase, importPrefix string,
dirPathDao, fileName string,
fieldMap map[string]*gdb.TableField,
- in cGenDaoInternalInput,
) {
path := gfile.Join(dirPathDao, "internal", fileName+".go")
modelContent := gstr.ReplaceByMap(getTplDaoInternalContent(""), g.MapStrStr{
@@ -497,7 +502,7 @@ func generateDaoInternal(
tplVarColumnDefine: gstr.Trim(generateColumnDefinitionForDao(fieldMap)),
tplVarColumnNames: gstr.Trim(generateColumnNamesForDao(fieldMap)),
})
- modelContent = replaceDefaultVar(modelContent)
+ modelContent = replaceDefaultVar(in, modelContent)
if err := gfile.PutContents(path, strings.TrimSpace(modelContent)); err != nil {
mlog.Fatalf("writing content to '%s' failed: %v", path, err)
} else {
@@ -506,9 +511,13 @@ func generateDaoInternal(
}
}
-func replaceDefaultVar(origin string) string {
+func replaceDefaultVar(in cGenDaoInternalInput, origin string) string {
+ var tplDatetimeStr string
+ if in.WithTime {
+ tplDatetimeStr = fmt.Sprintf(`Created at %s`, createdAt.String())
+ }
return gstr.ReplaceByMap(origin, g.MapStrStr{
- tplVarDatetime: createdAt.String(),
+ tplVarDatetimeStr: tplDatetimeStr,
})
}
diff --git a/cmd/gf/internal/consts/consts_gen_dao_template_dao.go b/cmd/gf/internal/consts/consts_gen_dao_template_dao.go
index c287cd759..f07fd1d55 100644
--- a/cmd/gf/internal/consts/consts_gen_dao_template_dao.go
+++ b/cmd/gf/internal/consts/consts_gen_dao_template_dao.go
@@ -30,7 +30,7 @@ var (
const TemplateDaoDaoInternalContent = `
// ==========================================================================
-// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at {TplDatetime}
+// Code generated by GoFrame CLI tool. DO NOT EDIT. {TplDatetimeStr}
// ==========================================================================
package internal
diff --git a/cmd/gf/internal/consts/consts_gen_dao_template_do.go b/cmd/gf/internal/consts/consts_gen_dao_template_do.go
index 9b63433af..b50eb1459 100644
--- a/cmd/gf/internal/consts/consts_gen_dao_template_do.go
+++ b/cmd/gf/internal/consts/consts_gen_dao_template_do.go
@@ -2,7 +2,7 @@ package consts
const TemplateGenDaoDoContent = `
// =================================================================================
-// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at {TplDatetime}
+// Code generated by GoFrame CLI tool. DO NOT EDIT. {TplDatetimeStr}
// =================================================================================
package do
diff --git a/cmd/gf/internal/consts/consts_gen_dao_template_entity.go b/cmd/gf/internal/consts/consts_gen_dao_template_entity.go
index 6232b7d74..597f2a9a1 100644
--- a/cmd/gf/internal/consts/consts_gen_dao_template_entity.go
+++ b/cmd/gf/internal/consts/consts_gen_dao_template_entity.go
@@ -2,7 +2,7 @@ package consts
const TemplateGenDaoEntityContent = `
// =================================================================================
-// Code generated by GoFrame CLI tool. DO NOT EDIT. Created at {TplDatetime}
+// Code generated by GoFrame CLI tool. DO NOT EDIT. {TplDatetimeStr}
// =================================================================================
package entity
diff --git a/cmd/gf/main.go b/cmd/gf/main.go
index be90cfd8b..0746b50b8 100644
--- a/cmd/gf/main.go
+++ b/cmd/gf/main.go
@@ -2,6 +2,8 @@ package main
import (
_ "github.com/gogf/gf/cmd/gf/v2/internal/packed"
+ "github.com/gogf/gf/v2/frame/g"
+ "github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/cmd/gf/v2/internal/cmd"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
@@ -12,6 +14,10 @@ import (
"github.com/gogf/gf/v2/text/gstr"
)
+const (
+ cliFolderName = `hack`
+)
+
func main() {
defer func() {
if exception := recover(); exception != nil {
@@ -23,6 +29,15 @@ func main() {
}
}()
+ // CLI configuration.
+ if path, _ := gfile.Search(cliFolderName); path != "" {
+ if adapter, ok := g.Cfg().GetAdapter().(*gcfg.AdapterFile); ok {
+ if err := adapter.SetPath(path); err != nil {
+ mlog.Fatal(err)
+ }
+ }
+ }
+
// zsh alias "git fetch" conflicts checks.
handleZshAlias()
diff --git a/contrib/drivers/mssql/go.sum b/contrib/drivers/mssql/go.sum
index f7ea0d13f..215d60c18 100644
--- a/contrib/drivers/mssql/go.sum
+++ b/contrib/drivers/mssql/go.sum
@@ -1,32 +1,9 @@
-cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
-cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
-github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
-github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
-github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
-github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
-github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
-github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
-github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
-github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
-github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
-github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
-github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
-github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E=
github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
-github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
-github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
-github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
-github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI=
-github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
-github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
-github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
-github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
-github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -34,94 +11,40 @@ github.com/denisenkom/go-mssqldb v0.11.0 h1:9rHa233rhdOyrz2GcP9NM+gi2psgJZ4GWDpL
github.com/denisenkom/go-mssqldb v0.11.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
-github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
-github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
-github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
-github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
-github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
-github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
-github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
-github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
-github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
-github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
-github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
-github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
-github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
-github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
-github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
-github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
-github.com/go-logr/logr v1.2.1 h1:DX7uPQ4WgAWfoh+NGGlbJQswnYIVvz0SRlLS3rPZQDA=
-github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
-github.com/go-logr/stdr v1.2.0 h1:j4LrlVXgrbIWO83mmQUnK0Hi+YnbD+vzrE1z/EphbFE=
-github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI=
github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg=
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
-github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
-github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
-github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
-github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
-github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
-github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
-github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
-github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
-github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
-github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
-github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
-github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
-github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
-github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
-github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
-github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
-github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
-github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
-github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
-github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
-github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
-github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
-github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
-github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
-github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
-github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
-github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
-github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
-github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
-github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
-github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
@@ -129,13 +52,6 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
-github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
-github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
-github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
-github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
-github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
-github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
-github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
@@ -149,201 +65,91 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.16.0 h1:6gjqkI8iiRHMvdccRJM8rVKjCWk6ZIm6FTm3ddIe4/c=
github.com/onsi/gomega v1.16.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
-github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
-github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
-github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
-github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
-github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
-github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
-github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
-github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
-github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
-github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
-github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
-github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
-github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
-github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
-github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
-github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
-github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
-github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
-github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
-github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
-github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
-github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
-github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
-github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
-go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
-go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
-go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q=
-go.opentelemetry.io/otel v1.3.0 h1:APxLf0eiBwLl+SOXiJJCVYzA1OOJNyAoV8C5RNRyy7Y=
-go.opentelemetry.io/otel v1.3.0/go.mod h1:PWIKzi6JCp7sM0k9yZ43VX+T345uNbAkDKwHVjb2PTs=
-go.opentelemetry.io/otel/sdk v1.3.0 h1:3278edCoH89MEJ0Ky8WQXVmDQv3FX4ZJ3Pp+9fJreAI=
-go.opentelemetry.io/otel/sdk v1.3.0/go.mod h1:rIo4suHNhQwBIPg9axF8V9CA72Wz2mKF1teNrup8yzs=
-go.opentelemetry.io/otel/trace v1.3.0 h1:doy8Hzb1RJ+I3yFhtDmwNc7tIyw1tNMOIsyPzp1NOGY=
-go.opentelemetry.io/otel/trace v1.3.0/go.mod h1:c/VDhno8888bvQYmbYLqe41/Ldmr/KKunbvWM4/fEjk=
-go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
-go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
-go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
-go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
-golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
+go.opentelemetry.io/otel v1.0.0 h1:qTTn6x71GVBvoafHK/yaRUmFzI4LcONZD0/kXxl5PHI=
+go.opentelemetry.io/otel v1.0.0/go.mod h1:AjRVh9A5/5DE7S+mZtTR6t8vpKKryam+0lREnfmS4cg=
+go.opentelemetry.io/otel/sdk v1.0.0 h1:BNPMYUONPNbLneMttKSjQhOTlFLOD9U22HNG1KrIN2Y=
+go.opentelemetry.io/otel/sdk v1.0.0/go.mod h1:PCrDHlSy5x1kjezSdL37PhbFUMjrsLRshJ2zCzeXwbM=
+go.opentelemetry.io/otel/trace v1.0.0 h1:TSBr8GTEtKevYMG/2d21M989r5WJYVimhTHBKVEZuh4=
+go.opentelemetry.io/otel/trace v1.0.0/go.mod h1:PXTWqayeFUlJV1YDNhsJYB184+IvAH814St6o6ajzIs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
-golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
-golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
-golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
-golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
-golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
-golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
-golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
-golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
-golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
-golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
-golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y=
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
-golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
-golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
-golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
-golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
-golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
-golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
-golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
-google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
-google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
-google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
-google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
-google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
-google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
-google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
-google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
-google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
-google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
-google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
-google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
-google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
-google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
-google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
-google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
-google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
-gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
-gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
-gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
-honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
-sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go
index 3db918764..d054033f0 100644
--- a/database/gdb/gdb.go
+++ b/database/gdb/gdb.go
@@ -408,11 +408,9 @@ func doNewByNode(node ConfigNode, group string) (db DB, err error) {
}
return c.db, nil
}
- return nil, gerror.NewCodef(
- gcode.CodeInvalidConfiguration,
- `cannot find database driver for specified database type "%s", did you misspell type name "%s" or forget importing the database driver?`,
- node.Type, node.Type,
- )
+ errorMsg := `cannot find database driver for specified database type "%s"`
+ errorMsg += `, did you misspell type name "%s" or forget importing the database driver?`
+ return nil, gerror.NewCodef(gcode.CodeInvalidConfiguration, errorMsg, node.Type, node.Type)
}
// Instance returns an instance for DB operations.
diff --git a/encoding/gjson/gjson_z_unit_test.go b/encoding/gjson/gjson_z_unit_test.go
index c477d95f8..cc07a1d49 100644
--- a/encoding/gjson/gjson_z_unit_test.go
+++ b/encoding/gjson/gjson_z_unit_test.go
@@ -552,3 +552,27 @@ func TestJson_Options(t *testing.T) {
t.Assert(fmt.Sprintf(`%v`, m["Id"]), `53687091200`)
})
}
+
+// https://github.com/gogf/gf/issues/1617
+func Test_Issue1617(t *testing.T) {
+ gtest.C(t, func(t *gtest.T) {
+ type MyJsonName struct {
+ F中文 int64 `json:"F中文"`
+ F英文 int64 `json:"F英文"`
+ F法文 int64 `json:"F法文"`
+ F西班牙语 int64 `json:"F西班牙语"`
+ }
+ jso := `{"F中文":1,"F英文":2,"F法文":3,"F西班牙语":4}`
+ var a MyJsonName
+ json, err := gjson.DecodeToJson(jso)
+ t.AssertNil(err)
+ err = json.Scan(&a)
+ t.AssertNil(err)
+ t.Assert(a, MyJsonName{
+ F中文: 1,
+ F英文: 2,
+ F法文: 3,
+ F西班牙语: 4,
+ })
+ })
+}
diff --git a/internal/utils/utils_str.go b/internal/utils/utils_str.go
index 960a12920..358d7d685 100644
--- a/internal/utils/utils_str.go
+++ b/internal/utils/utils_str.go
@@ -101,10 +101,12 @@ func ReplaceByMap(origin string, replaces map[string]string) string {
// RemoveSymbols removes all symbols from string and lefts only numbers and letters.
func RemoveSymbols(s string) string {
- var b []byte
+ var b = make([]rune, 0, len(s))
for _, c := range s {
- if (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') {
- b = append(b, byte(c))
+ if c > 127 {
+ b = append(b, c)
+ } else if (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') {
+ b = append(b, c)
}
}
return string(b)
diff --git a/internal/utils/utils_z_unit_test.go b/internal/utils/utils_z_unit_test.go
index 5201e80e1..91d8c8de0 100644
--- a/internal/utils/utils_z_unit_test.go
+++ b/internal/utils/utils_z_unit_test.go
@@ -69,6 +69,7 @@ func Test_ReadCloser(t *testing.T) {
func Test_RemoveSymbols(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
t.Assert(utils.RemoveSymbols(`-a-b._a c1!@#$%^&*()_+:";'.,'01`), `abac101`)
+ t.Assert(utils.RemoveSymbols(`-a-b我._a c1!@#$%^&*是()_+:帅";'.,哥'01`), `ab我ac1是帅哥01`)
})
}
diff --git a/net/gclient/gclient.go b/net/gclient/gclient.go
index 93dcdd0c7..9219fa3b0 100644
--- a/net/gclient/gclient.go
+++ b/net/gclient/gclient.go
@@ -36,15 +36,6 @@ type Client struct {
}
const (
- httpMethodGet = `GET`
- httpMethodPut = `PUT`
- httpMethodPost = `POST`
- httpMethodDelete = `DELETE`
- httpMethodHead = `HEAD`
- httpMethodPatch = `PATCH`
- httpMethodConnect = `CONNECT`
- httpMethodOptions = `OPTIONS`
- httpMethodTrace = `TRACE`
httpProtocolName = `http`
httpParamFileHolder = `@file:`
httpRegexParamJson = `^[\w\[\]]+=.+`
diff --git a/net/gclient/gclient_bytes.go b/net/gclient/gclient_bytes.go
index 1cabe39fd..bfdc85e41 100644
--- a/net/gclient/gclient_bytes.go
+++ b/net/gclient/gclient_bytes.go
@@ -8,53 +8,54 @@ package gclient
import (
"context"
+ "net/http"
"github.com/gogf/gf/v2/internal/intlog"
)
// GetBytes sends a GET request, retrieves and returns the result content as bytes.
func (c *Client) GetBytes(ctx context.Context, url string, data ...interface{}) []byte {
- return c.RequestBytes(ctx, httpMethodGet, url, data...)
+ return c.RequestBytes(ctx, http.MethodGet, url, data...)
}
// PutBytes sends a PUT request, retrieves and returns the result content as bytes.
func (c *Client) PutBytes(ctx context.Context, url string, data ...interface{}) []byte {
- return c.RequestBytes(ctx, httpMethodPut, url, data...)
+ return c.RequestBytes(ctx, http.MethodPut, url, data...)
}
// PostBytes sends a POST request, retrieves and returns the result content as bytes.
func (c *Client) PostBytes(ctx context.Context, url string, data ...interface{}) []byte {
- return c.RequestBytes(ctx, httpMethodPost, url, data...)
+ return c.RequestBytes(ctx, http.MethodPost, url, data...)
}
// DeleteBytes sends a DELETE request, retrieves and returns the result content as bytes.
func (c *Client) DeleteBytes(ctx context.Context, url string, data ...interface{}) []byte {
- return c.RequestBytes(ctx, httpMethodDelete, url, data...)
+ return c.RequestBytes(ctx, http.MethodDelete, url, data...)
}
// HeadBytes sends a HEAD request, retrieves and returns the result content as bytes.
func (c *Client) HeadBytes(ctx context.Context, url string, data ...interface{}) []byte {
- return c.RequestBytes(ctx, httpMethodHead, url, data...)
+ return c.RequestBytes(ctx, http.MethodHead, url, data...)
}
// PatchBytes sends a PATCH request, retrieves and returns the result content as bytes.
func (c *Client) PatchBytes(ctx context.Context, url string, data ...interface{}) []byte {
- return c.RequestBytes(ctx, httpMethodPatch, url, data...)
+ return c.RequestBytes(ctx, http.MethodPatch, url, data...)
}
// ConnectBytes sends a CONNECT request, retrieves and returns the result content as bytes.
func (c *Client) ConnectBytes(ctx context.Context, url string, data ...interface{}) []byte {
- return c.RequestBytes(ctx, httpMethodConnect, url, data...)
+ return c.RequestBytes(ctx, http.MethodConnect, url, data...)
}
// OptionsBytes sends a OPTIONS request, retrieves and returns the result content as bytes.
func (c *Client) OptionsBytes(ctx context.Context, url string, data ...interface{}) []byte {
- return c.RequestBytes(ctx, httpMethodOptions, url, data...)
+ return c.RequestBytes(ctx, http.MethodOptions, url, data...)
}
// TraceBytes sends a TRACE request, retrieves and returns the result content as bytes.
func (c *Client) TraceBytes(ctx context.Context, url string, data ...interface{}) []byte {
- return c.RequestBytes(ctx, httpMethodTrace, url, data...)
+ return c.RequestBytes(ctx, http.MethodTrace, url, data...)
}
// RequestBytes sends request using given HTTP method and data, retrieves returns the result
diff --git a/net/gclient/gclient_content.go b/net/gclient/gclient_content.go
index ca37eb4c8..1a39c97a5 100644
--- a/net/gclient/gclient_content.go
+++ b/net/gclient/gclient_content.go
@@ -6,60 +6,63 @@
package gclient
-import "context"
+import (
+ "context"
+ "net/http"
+)
// GetContent is a convenience method for sending GET request, which retrieves and returns
// the result content and automatically closes response object.
func (c *Client) GetContent(ctx context.Context, url string, data ...interface{}) string {
- return string(c.RequestBytes(ctx, httpMethodGet, url, data...))
+ return string(c.RequestBytes(ctx, http.MethodGet, url, data...))
}
// PutContent is a convenience method for sending PUT request, which retrieves and returns
// the result content and automatically closes response object.
func (c *Client) PutContent(ctx context.Context, url string, data ...interface{}) string {
- return string(c.RequestBytes(ctx, httpMethodPut, url, data...))
+ return string(c.RequestBytes(ctx, http.MethodPut, url, data...))
}
// PostContent is a convenience method for sending POST request, which retrieves and returns
// the result content and automatically closes response object.
func (c *Client) PostContent(ctx context.Context, url string, data ...interface{}) string {
- return string(c.RequestBytes(ctx, httpMethodPost, url, data...))
+ return string(c.RequestBytes(ctx, http.MethodPost, url, data...))
}
// DeleteContent is a convenience method for sending DELETE request, which retrieves and returns
// the result content and automatically closes response object.
func (c *Client) DeleteContent(ctx context.Context, url string, data ...interface{}) string {
- return string(c.RequestBytes(ctx, httpMethodDelete, url, data...))
+ return string(c.RequestBytes(ctx, http.MethodDelete, url, data...))
}
// HeadContent is a convenience method for sending HEAD request, which retrieves and returns
// the result content and automatically closes response object.
func (c *Client) HeadContent(ctx context.Context, url string, data ...interface{}) string {
- return string(c.RequestBytes(ctx, httpMethodHead, url, data...))
+ return string(c.RequestBytes(ctx, http.MethodHead, url, data...))
}
// PatchContent is a convenience method for sending PATCH request, which retrieves and returns
// the result content and automatically closes response object.
func (c *Client) PatchContent(ctx context.Context, url string, data ...interface{}) string {
- return string(c.RequestBytes(ctx, httpMethodPatch, url, data...))
+ return string(c.RequestBytes(ctx, http.MethodPatch, url, data...))
}
// ConnectContent is a convenience method for sending CONNECT request, which retrieves and returns
// the result content and automatically closes response object.
func (c *Client) ConnectContent(ctx context.Context, url string, data ...interface{}) string {
- return string(c.RequestBytes(ctx, httpMethodConnect, url, data...))
+ return string(c.RequestBytes(ctx, http.MethodConnect, url, data...))
}
// OptionsContent is a convenience method for sending OPTIONS request, which retrieves and returns
// the result content and automatically closes response object.
func (c *Client) OptionsContent(ctx context.Context, url string, data ...interface{}) string {
- return string(c.RequestBytes(ctx, httpMethodOptions, url, data...))
+ return string(c.RequestBytes(ctx, http.MethodOptions, url, data...))
}
// TraceContent is a convenience method for sending TRACE request, which retrieves and returns
// the result content and automatically closes response object.
func (c *Client) TraceContent(ctx context.Context, url string, data ...interface{}) string {
- return string(c.RequestBytes(ctx, httpMethodTrace, url, data...))
+ return string(c.RequestBytes(ctx, http.MethodTrace, url, data...))
}
// RequestContent is a convenience method for sending custom http method request, which
diff --git a/net/gclient/gclient_request.go b/net/gclient/gclient_request.go
index 50915db34..2dbb26d10 100644
--- a/net/gclient/gclient_request.go
+++ b/net/gclient/gclient_request.go
@@ -33,55 +33,55 @@ import (
// Get send GET request and returns the response object.
// Note that the response object MUST be closed if it'll never be used.
func (c *Client) Get(ctx context.Context, url string, data ...interface{}) (*Response, error) {
- return c.DoRequest(ctx, httpMethodGet, url, data...)
+ return c.DoRequest(ctx, http.MethodGet, url, data...)
}
// Put send PUT request and returns the response object.
// Note that the response object MUST be closed if it'll never be used.
func (c *Client) Put(ctx context.Context, url string, data ...interface{}) (*Response, error) {
- return c.DoRequest(ctx, httpMethodPut, url, data...)
+ return c.DoRequest(ctx, http.MethodPut, url, data...)
}
// Post sends request using HTTP method POST and returns the response object.
// Note that the response object MUST be closed if it'll never be used.
func (c *Client) Post(ctx context.Context, url string, data ...interface{}) (*Response, error) {
- return c.DoRequest(ctx, httpMethodPost, url, data...)
+ return c.DoRequest(ctx, http.MethodPost, url, data...)
}
// Delete send DELETE request and returns the response object.
// Note that the response object MUST be closed if it'll never be used.
func (c *Client) Delete(ctx context.Context, url string, data ...interface{}) (*Response, error) {
- return c.DoRequest(ctx, httpMethodDelete, url, data...)
+ return c.DoRequest(ctx, http.MethodDelete, url, data...)
}
// Head send HEAD request and returns the response object.
// Note that the response object MUST be closed if it'll never be used.
func (c *Client) Head(ctx context.Context, url string, data ...interface{}) (*Response, error) {
- return c.DoRequest(ctx, httpMethodHead, url, data...)
+ return c.DoRequest(ctx, http.MethodHead, url, data...)
}
// Patch send PATCH request and returns the response object.
// Note that the response object MUST be closed if it'll never be used.
func (c *Client) Patch(ctx context.Context, url string, data ...interface{}) (*Response, error) {
- return c.DoRequest(ctx, httpMethodPatch, url, data...)
+ return c.DoRequest(ctx, http.MethodPatch, url, data...)
}
// Connect send CONNECT request and returns the response object.
// Note that the response object MUST be closed if it'll never be used.
func (c *Client) Connect(ctx context.Context, url string, data ...interface{}) (*Response, error) {
- return c.DoRequest(ctx, httpMethodConnect, url, data...)
+ return c.DoRequest(ctx, http.MethodConnect, url, data...)
}
// Options send OPTIONS request and returns the response object.
// Note that the response object MUST be closed if it'll never be used.
func (c *Client) Options(ctx context.Context, url string, data ...interface{}) (*Response, error) {
- return c.DoRequest(ctx, httpMethodOptions, url, data...)
+ return c.DoRequest(ctx, http.MethodOptions, url, data...)
}
// Trace send TRACE request and returns the response object.
// Note that the response object MUST be closed if it'll never be used.
func (c *Client) Trace(ctx context.Context, url string, data ...interface{}) (*Response, error) {
- return c.DoRequest(ctx, httpMethodTrace, url, data...)
+ return c.DoRequest(ctx, http.MethodTrace, url, data...)
}
// PostForm issues a POST to the specified URL,
@@ -178,7 +178,7 @@ func (c *Client) prepareRequest(ctx context.Context, method, url string, data ..
params = httputil.BuildParams(data[0])
}
}
- if method == httpMethodGet {
+ if method == http.MethodGet {
var bodyBuffer *bytes.Buffer
if params != "" {
switch c.header[httpHeaderContentType] {
diff --git a/net/gclient/gclient_var.go b/net/gclient/gclient_var.go
index d867ad1a7..950f96ac0 100644
--- a/net/gclient/gclient_var.go
+++ b/net/gclient/gclient_var.go
@@ -8,6 +8,7 @@ package gclient
import (
"context"
+ "net/http"
"github.com/gogf/gf/v2/container/gvar"
)
@@ -15,55 +16,55 @@ import (
// GetVar sends a GET request, retrieves and converts the result content to specified pointer.
// The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (c *Client) GetVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
- return c.RequestVar(ctx, httpMethodGet, url, data...)
+ return c.RequestVar(ctx, http.MethodGet, url, data...)
}
// PutVar sends a PUT request, retrieves and converts the result content to specified pointer.
// The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (c *Client) PutVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
- return c.RequestVar(ctx, httpMethodPut, url, data...)
+ return c.RequestVar(ctx, http.MethodPut, url, data...)
}
// PostVar sends a POST request, retrieves and converts the result content to specified pointer.
// The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (c *Client) PostVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
- return c.RequestVar(ctx, httpMethodPost, url, data...)
+ return c.RequestVar(ctx, http.MethodPost, url, data...)
}
// DeleteVar sends a DELETE request, retrieves and converts the result content to specified pointer.
// The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (c *Client) DeleteVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
- return c.RequestVar(ctx, httpMethodDelete, url, data...)
+ return c.RequestVar(ctx, http.MethodDelete, url, data...)
}
// HeadVar sends a HEAD request, retrieves and converts the result content to specified pointer.
// The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (c *Client) HeadVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
- return c.RequestVar(ctx, httpMethodHead, url, data...)
+ return c.RequestVar(ctx, http.MethodHead, url, data...)
}
// PatchVar sends a PATCH request, retrieves and converts the result content to specified pointer.
// The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (c *Client) PatchVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
- return c.RequestVar(ctx, httpMethodPatch, url, data...)
+ return c.RequestVar(ctx, http.MethodPatch, url, data...)
}
// ConnectVar sends a CONNECT request, retrieves and converts the result content to specified pointer.
// The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (c *Client) ConnectVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
- return c.RequestVar(ctx, httpMethodConnect, url, data...)
+ return c.RequestVar(ctx, http.MethodConnect, url, data...)
}
// OptionsVar sends a OPTIONS request, retrieves and converts the result content to specified pointer.
// The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (c *Client) OptionsVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
- return c.RequestVar(ctx, httpMethodOptions, url, data...)
+ return c.RequestVar(ctx, http.MethodOptions, url, data...)
}
// TraceVar sends a TRACE request, retrieves and converts the result content to specified pointer.
// The parameter `pointer` can be type of: struct/*struct/**struct/[]struct/[]*struct/*[]struct, etc.
func (c *Client) TraceVar(ctx context.Context, url string, data ...interface{}) *gvar.Var {
- return c.RequestVar(ctx, httpMethodTrace, url, data...)
+ return c.RequestVar(ctx, http.MethodTrace, url, data...)
}
// RequestVar sends request using given HTTP method and data, retrieves converts the result
diff --git a/net/ghttp/ghttp.go b/net/ghttp/ghttp.go
index c4e21cca2..4783fe6d7 100644
--- a/net/ghttp/ghttp.go
+++ b/net/ghttp/ghttp.go
@@ -107,10 +107,11 @@ type (
)
const (
- HookBeforeServe = "HOOK_BEFORE_SERVE"
- HookAfterServe = "HOOK_AFTER_SERVE"
- HookBeforeOutput = "HOOK_BEFORE_OUTPUT"
- HookAfterOutput = "HOOK_AFTER_OUTPUT"
+ HeaderXUrlPath = "x-url-path" // Used for custom route handler, which does not change URL.Path.
+ HookBeforeServe = "HOOK_BEFORE_SERVE" // Hook handler before route handler/file serving.
+ HookAfterServe = "HOOK_AFTER_SERVE" // Hook handler after route handler/file serving.
+ HookBeforeOutput = "HOOK_BEFORE_OUTPUT" // Hook handler before response output.
+ HookAfterOutput = "HOOK_AFTER_OUTPUT" // Hook handler after response output.
ServerStatusStopped = 0
ServerStatusRunning = 1
DefaultServerName = "default"
diff --git a/net/ghttp/ghttp_middleware_cors.go b/net/ghttp/ghttp_middleware_cors.go
new file mode 100644
index 000000000..bcfe9b874
--- /dev/null
+++ b/net/ghttp/ghttp_middleware_cors.go
@@ -0,0 +1,13 @@
+// Copyright GoFrame 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 ghttp
+
+// MiddlewareCORS is a middleware handler for CORS with default options.
+func MiddlewareCORS(r *Request) {
+ r.Response.CORSDefault()
+ r.Middleware.Next()
+}
diff --git a/net/ghttp/ghttp_request.go b/net/ghttp/ghttp_request.go
index da33d83d7..cbdf12fef 100644
--- a/net/ghttp/ghttp_request.go
+++ b/net/ghttp/ghttp_request.go
@@ -184,30 +184,31 @@ func (r *Request) IsAjaxRequest() bool {
// GetClientIp returns the client ip of this request without port.
// Note that this ip address might be modified by client header.
func (r *Request) GetClientIp() string {
- if len(r.clientIp) == 0 {
- realIps := r.Header.Get("X-Forwarded-For")
- if realIps != "" && len(realIps) != 0 && !strings.EqualFold("unknown", realIps) {
- ipArray := strings.Split(realIps, ",")
- r.clientIp = ipArray[0]
- }
- if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
- r.clientIp = r.Header.Get("Proxy-Client-IP")
- }
- if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
- r.clientIp = r.Header.Get("WL-Proxy-Client-IP")
- }
- if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
- r.clientIp = r.Header.Get("HTTP_CLIENT_IP")
- }
- if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
- r.clientIp = r.Header.Get("HTTP_X_FORWARDED_FOR")
- }
- if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
- r.clientIp = r.Header.Get("X-Real-IP")
- }
- if r.clientIp == "" || strings.EqualFold("unknown", realIps) {
- r.clientIp = r.GetRemoteIp()
- }
+ if r.clientIp == "" {
+ return r.clientIp
+ }
+ realIps := r.Header.Get("X-Forwarded-For")
+ if realIps != "" && len(realIps) != 0 && !strings.EqualFold("unknown", realIps) {
+ ipArray := strings.Split(realIps, ",")
+ r.clientIp = ipArray[0]
+ }
+ if r.clientIp == "" {
+ r.clientIp = r.Header.Get("Proxy-Client-IP")
+ }
+ if r.clientIp == "" {
+ r.clientIp = r.Header.Get("WL-Proxy-Client-IP")
+ }
+ if r.clientIp == "" {
+ r.clientIp = r.Header.Get("HTTP_CLIENT_IP")
+ }
+ if r.clientIp == "" {
+ r.clientIp = r.Header.Get("HTTP_X_FORWARDED_FOR")
+ }
+ if r.clientIp == "" {
+ r.clientIp = r.Header.Get("X-Real-IP")
+ }
+ if r.clientIp == "" {
+ r.clientIp = r.GetRemoteIp()
}
return r.clientIp
}
diff --git a/net/ghttp/ghttp_server.go b/net/ghttp/ghttp_server.go
index ce4b6c2b4..f036c121d 100644
--- a/net/ghttp/ghttp_server.go
+++ b/net/ghttp/ghttp_server.go
@@ -201,7 +201,7 @@ func (s *Server) Start() error {
// Default HTTP handler.
if s.config.Handler == nil {
- s.config.Handler = s
+ s.config.Handler = s.ServeHTTP
}
// Install external plugins.
@@ -601,3 +601,21 @@ func (s *Server) getListenerFdMap() map[string]string {
}
return m
}
+
+// GetListenedPort retrieves and returns one port which is listened by current server.
+func (s *Server) GetListenedPort() int {
+ ports := s.GetListenedPorts()
+ if len(ports) > 0 {
+ return ports[0]
+ }
+ return 0
+}
+
+// GetListenedPorts retrieves and returns the ports which are listened by current server.
+func (s *Server) GetListenedPorts() []int {
+ ports := make([]int, 0)
+ for _, server := range s.servers {
+ ports = append(ports, server.GetListenedPort())
+ }
+ return ports
+}
diff --git a/net/ghttp/ghttp_server_config.go b/net/ghttp/ghttp_server_config.go
index e623f6ec1..099358983 100644
--- a/net/ghttp/ghttp_server_config.go
+++ b/net/ghttp/ghttp_server_config.go
@@ -66,7 +66,7 @@ type ServerConfig struct {
TLSConfig *tls.Config `json:"tlsConfig"`
// Handler the handler for HTTP request.
- Handler http.Handler `json:"-"`
+ Handler func(w http.ResponseWriter, r *http.Request) `json:"-"`
// ReadTimeout is the maximum duration for reading the entire
// request, including the body.
@@ -240,7 +240,7 @@ type ServerConfig struct {
func NewConfig() ServerConfig {
return ServerConfig{
Name: DefaultServerName,
- Address: "",
+ Address: ":0",
HTTPSAddr: "",
Handler: nil,
ReadTimeout: 60 * time.Second,
@@ -481,10 +481,15 @@ func (s *Server) SetName(name string) {
s.config.Name = name
}
-// Handler returns the request handler of the server.
-func (s *Server) Handler() http.Handler {
+// SetHandler sets the request handler for server.
+func (s *Server) SetHandler(h func(w http.ResponseWriter, r *http.Request)) {
+ s.config.Handler = h
+}
+
+// GetHandler returns the request handler of the server.
+func (s *Server) GetHandler() func(w http.ResponseWriter, r *http.Request) {
if s.config.Handler == nil {
- return s
+ return s.ServeHTTP
}
return s.config.Handler
}
diff --git a/net/ghttp/ghttp_server_graceful.go b/net/ghttp/ghttp_server_graceful.go
index 133a38ccf..1eaad5321 100644
--- a/net/ghttp/ghttp_server_graceful.go
+++ b/net/ghttp/ghttp_server_graceful.go
@@ -13,6 +13,7 @@ import (
"net"
"net/http"
"os"
+ "sync"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/os/gproc"
@@ -27,6 +28,7 @@ type gracefulServer struct {
address string // Listening address like:":80", ":8080".
httpServer *http.Server // Underlying http.Server.
rawListener net.Listener // Underlying net.Listener.
+ rawLnMu sync.RWMutex // Concurrent safety mutex for `rawListener`.
listener net.Listener // Wrapped net.Listener.
isHttps bool // Is HTTPS.
status int // Status of current server.
@@ -50,11 +52,11 @@ func (s *Server) newGracefulServer(address string, fd ...int) *gracefulServer {
return gs
}
-// newGracefulServer creates and returns a underlying http.Server with given address.
+// newGracefulServer creates and returns an underlying http.Server with given address.
func (s *Server) newHttpServer(address string) *http.Server {
server := &http.Server{
Addr: address,
- Handler: s.config.Handler,
+ Handler: http.HandlerFunc(s.config.Handler),
ReadTimeout: s.config.ReadTimeout,
WriteTimeout: s.config.WriteTimeout,
IdleTimeout: s.config.IdleTimeout,
@@ -72,15 +74,15 @@ func (s *gracefulServer) ListenAndServe() error {
return err
}
s.listener = ln
- s.rawListener = ln
+ s.setRawListener(ln)
return s.doServe(context.TODO())
}
// Fd retrieves and returns the file descriptor of current server.
-// It is available ony in *nix like operation systems like: linux, unix, darwin.
+// It is available ony in *nix like operating systems like: linux, unix, darwin.
func (s *gracefulServer) Fd() uintptr {
- if s.rawListener != nil {
- file, err := s.rawListener.(*net.TCPListener).File()
+ if ln := s.getRawListener(); ln != nil {
+ file, err := ln.(*net.TCPListener).File()
if err == nil {
return file.Fd()
}
@@ -111,7 +113,7 @@ func (s *gracefulServer) ListenAndServeTLS(certFile, keyFile string, tlsConfig .
if config.NextProtos == nil {
config.NextProtos = []string{"http/1.1"}
}
- err := error(nil)
+ var err error
if len(config.Certificates) == 0 {
config.Certificates = make([]tls.Certificate, 1)
if gres.Contains(certFile) {
@@ -133,10 +135,18 @@ func (s *gracefulServer) ListenAndServeTLS(certFile, keyFile string, tlsConfig .
}
s.listener = tls.NewListener(ln, config)
- s.rawListener = ln
+ s.setRawListener(ln)
return s.doServe(ctx)
}
+// GetListenedPort retrieves and returns one port which is listened by current server.
+func (s *gracefulServer) GetListenedPort() int {
+ if ln := s.getRawListener(); ln != nil {
+ return ln.Addr().(*net.TCPAddr).Port
+ }
+ return 0
+}
+
// getProto retrieves and returns the proto string of current server.
func (s *gracefulServer) getProto() string {
proto := "http"
@@ -199,6 +209,20 @@ func (s *gracefulServer) shutdown(ctx context.Context) {
}
}
+// setRawListener sets `rawListener` with given net.Listener.
+func (s *gracefulServer) setRawListener(ln net.Listener) {
+ s.rawLnMu.Lock()
+ defer s.rawLnMu.Unlock()
+ s.rawListener = ln
+}
+
+// setRawListener returns the `rawListener` of current server.
+func (s *gracefulServer) getRawListener() net.Listener {
+ s.rawLnMu.RLock()
+ defer s.rawLnMu.RUnlock()
+ return s.rawListener
+}
+
// close shuts down the server forcibly.
func (s *gracefulServer) close(ctx context.Context) {
if s.status == ServerStatusStopped {
diff --git a/net/ghttp/ghttp_server_router_hook.go b/net/ghttp/ghttp_server_router_hook.go
index 467319a53..6c53b05d0 100644
--- a/net/ghttp/ghttp_server_router_hook.go
+++ b/net/ghttp/ghttp_server_router_hook.go
@@ -61,6 +61,9 @@ func (s *Server) BindHookHandlerByMap(pattern string, hookMap map[string]Handler
// callHookHandler calls the hook handler by their registered sequences.
func (s *Server) callHookHandler(hook string, r *Request) {
+ if !r.hasHookHandler {
+ return
+ }
hookItems := r.getHookHandlers(hook)
if len(hookItems) > 0 {
// Backup the old router variable map.
@@ -91,9 +94,6 @@ func (s *Server) callHookHandler(hook string, r *Request) {
// getHookHandlers retrieves and returns the hook handlers of specified hook.
func (r *Request) getHookHandlers(hook string) []*handlerParsedItem {
- if !r.hasHookHandler {
- return nil
- }
parsedItems := make([]*handlerParsedItem, 0, 4)
for _, v := range r.handlers {
if v.Handler.HookName != hook {
diff --git a/net/ghttp/ghttp_server_router_serve.go b/net/ghttp/ghttp_server_router_serve.go
index 3b2221cf6..58318341c 100644
--- a/net/ghttp/ghttp_server_router_serve.go
+++ b/net/ghttp/ghttp_server_router_serve.go
@@ -9,6 +9,7 @@ package ghttp
import (
"context"
"fmt"
+ "net/http"
"strings"
"github.com/gogf/gf/v2/container/glist"
@@ -41,26 +42,28 @@ func (s *Server) getHandlersWithCache(r *Request) (parsedItems []*handlerParsedI
var (
ctx = r.Context()
method = r.Method
+ path = r.URL.Path
+ host = r.GetHost()
)
// Special http method OPTIONS handling.
// It searches the handler with the request method instead of OPTIONS method.
- if method == "OPTIONS" {
+ if method == http.MethodOptions {
if v := r.Request.Header.Get("Access-Control-Request-Method"); v != "" {
method = v
}
}
// Search and cache the router handlers.
- value, err := s.serveCache.GetOrSetFunc(
- ctx,
- s.serveHandlerKey(method, r.URL.Path, r.GetHost()),
- func(ctx context.Context) (interface{}, error) {
- parsedItems, hasHook, hasServe = s.searchHandlers(method, r.URL.Path, r.GetHost())
- if parsedItems != nil {
- return &handlerCacheItem{parsedItems, hasHook, hasServe}, nil
- }
- return nil, nil
- }, routeCacheDuration,
- )
+ if xUrlPath := r.Header.Get(HeaderXUrlPath); xUrlPath != "" {
+ path = xUrlPath
+ }
+ var handlerKey = s.serveHandlerKey(method, path, host)
+ value, err := s.serveCache.GetOrSetFunc(ctx, handlerKey, func(ctx context.Context) (interface{}, error) {
+ parsedItems, hasHook, hasServe = s.searchHandlers(method, path, host)
+ if parsedItems != nil {
+ return &handlerCacheItem{parsedItems, hasHook, hasServe}, nil
+ }
+ return nil, nil
+ }, routeCacheDuration)
if err != nil {
intlog.Errorf(ctx, `%+v`, err)
}
diff --git a/net/ghttp/ghttp_z_unit_feature_config_test.go b/net/ghttp/ghttp_z_unit_feature_config_test.go
index b6986c5e9..0995f2abf 100644
--- a/net/ghttp/ghttp_z_unit_feature_config_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_config_test.go
@@ -13,12 +13,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_ConfigFromMap(t *testing.T) {
@@ -63,19 +63,16 @@ func Test_SetConfigWithMap(t *testing.T) {
}
func Test_ClientMaxBodySize(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.POST("/", func(r *ghttp.Request) {
r.Response.Write(r.GetBodyString())
})
})
m := g.Map{
- "Address": p,
"ClientMaxBodySize": "1k",
}
gtest.Assert(s.SetConfigWithMap(m), nil)
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -84,7 +81,7 @@ func Test_ClientMaxBodySize(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
data := make([]byte, 1056)
for i := 0; i < 1056; i++ {
@@ -98,8 +95,7 @@ func Test_ClientMaxBodySize(t *testing.T) {
}
func Test_ClientMaxBodySize_File(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.POST("/", func(r *ghttp.Request) {
r.GetUploadFile("file")
@@ -107,12 +103,10 @@ func Test_ClientMaxBodySize_File(t *testing.T) {
})
})
m := g.Map{
- "Address": p,
"ErrorLogEnabled": false,
"ClientMaxBodySize": "1k",
}
gtest.Assert(s.SetConfigWithMap(m), nil)
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -122,7 +116,7 @@ func Test_ClientMaxBodySize_File(t *testing.T) {
// ok
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
path := gfile.Temp(gtime.TimestampNanoStr())
data := make([]byte, 512)
@@ -140,7 +134,7 @@ func Test_ClientMaxBodySize_File(t *testing.T) {
// too large
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
path := gfile.Temp(gtime.TimestampNanoStr())
data := make([]byte, 1056)
diff --git a/net/ghttp/ghttp_z_unit_feature_context_test.go b/net/ghttp/ghttp_z_unit_feature_context_test.go
index 23dd70cc4..73e8ae218 100644
--- a/net/ghttp/ghttp_z_unit_feature_context_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_context_test.go
@@ -13,13 +13,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Context(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.SetCtxVar("traceid", 123)
@@ -29,7 +28,6 @@ func Test_Context(t *testing.T) {
r.Response.Write(r.GetCtxVar("traceid"))
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -37,7 +35,7 @@ func Test_Context(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), `123`)
})
diff --git a/net/ghttp/ghttp_z_unit_feature_cookie_test.go b/net/ghttp/ghttp_z_unit_feature_cookie_test.go
index f184c7ec2..d190baa2a 100644
--- a/net/ghttp/ghttp_z_unit_feature_cookie_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_cookie_test.go
@@ -14,13 +14,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Cookie(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/set", func(r *ghttp.Request) {
r.Cookie.Set(r.Get("k").String(), r.Get("v").String())
})
@@ -30,7 +29,6 @@ func Test_Cookie(t *testing.T) {
s.BindHandler("/remove", func(r *ghttp.Request) {
r.Cookie.Remove(r.Get("k").String())
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -39,7 +37,7 @@ func Test_Cookie(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
client.SetBrowserMode(true)
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
r1, e1 := client.Get(ctx, "/set?k=key1&v=100")
if r1 != nil {
defer r1.Close()
@@ -62,8 +60,7 @@ func Test_Cookie(t *testing.T) {
}
func Test_SetHttpCookie(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/set", func(r *ghttp.Request) {
r.Cookie.SetHttpCookie(&http.Cookie{
Name: r.Get("k").String(),
@@ -76,7 +73,6 @@ func Test_SetHttpCookie(t *testing.T) {
s.BindHandler("/remove", func(r *ghttp.Request) {
r.Cookie.Remove(r.Get("k").String())
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -85,7 +81,7 @@ func Test_SetHttpCookie(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
client.SetBrowserMode(true)
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
r1, e1 := client.Get(ctx, "/set?k=key1&v=100")
if r1 != nil {
defer r1.Close()
diff --git a/net/ghttp/ghttp_z_unit_feature_error_code_test.go b/net/ghttp/ghttp_z_unit_feature_error_code_test.go
index 34464dde1..fbf625fd0 100644
--- a/net/ghttp/ghttp_z_unit_feature_error_code_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_error_code_test.go
@@ -17,14 +17,13 @@ import (
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Error_Code(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.Middleware.Next()
@@ -35,12 +34,12 @@ func Test_Error_Code(t *testing.T) {
panic(gerror.NewCode(gcode.New(10000, "", nil), "test error"))
})
})
- s.SetPort(p)
+ s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/"), "10000")
})
diff --git a/net/ghttp/ghttp_z_unit_feature_https_test.go b/net/ghttp/ghttp_z_unit_feature_https_test.go
index 6ceb6b5c6..f99db9b5d 100644
--- a/net/ghttp/ghttp_z_unit_feature_https_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_https_test.go
@@ -20,11 +20,11 @@ import (
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gstr"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_HTTPS_Basic(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.GET("/test", func(r *ghttp.Request) {
r.Response.Write("test")
@@ -34,7 +34,6 @@ func Test_HTTPS_Basic(t *testing.T) {
gdebug.TestDataPath("https", "files", "server.crt"),
gdebug.TestDataPath("https", "files", "server.key"),
)
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -44,22 +43,21 @@ func Test_HTTPS_Basic(t *testing.T) {
// HTTP
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.AssertIN(gstr.Trim(c.GetContent(ctx, "/")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
t.AssertIN(gstr.Trim(c.GetContent(ctx, "/test")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
})
// HTTPS
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("https://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("https://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/"), "Not Found")
t.Assert(c.GetContent(ctx, "/test"), "test")
})
}
func Test_HTTPS_Resource(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.GET("/test", func(r *ghttp.Request) {
r.Response.Write("test")
@@ -69,7 +67,6 @@ func Test_HTTPS_Resource(t *testing.T) {
gfile.Join("files", "server.crt"),
gfile.Join("files", "server.key"),
)
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -79,14 +76,14 @@ func Test_HTTPS_Resource(t *testing.T) {
// HTTP
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.AssertIN(gstr.Trim(c.GetContent(ctx, "/")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
t.AssertIN(gstr.Trim(c.GetContent(ctx, "/test")), g.Slice{"", "Client sent an HTTP request to an HTTPS server."})
})
// HTTPS
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("https://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("https://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/"), "Not Found")
t.Assert(c.GetContent(ctx, "/test"), "test")
})
diff --git a/net/ghttp/ghttp_z_unit_feature_ip_test.go b/net/ghttp/ghttp_z_unit_feature_ip_test.go
index d985162b8..e5b5b7d6c 100644
--- a/net/ghttp/ghttp_z_unit_feature_ip_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_ip_test.go
@@ -15,32 +15,29 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func TestRequest_GetRemoteIp(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write(r.GetRemoteIp())
})
s.SetDumpRouterMap(false)
- s.SetPort(p)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
clientV4 := g.Client()
- clientV4.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ clientV4.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
clientV6 := g.Client()
- clientV6.SetPrefix(fmt.Sprintf("http://[::1]:%d", p))
+ clientV6.SetPrefix(fmt.Sprintf("http://[::1]:%d", s.GetListenedPort()))
t.Assert(clientV4.GetContent(ctx, "/"), "127.0.0.1")
t.Assert(clientV6.GetContent(ctx, "/"), "::1")
})
-
}
diff --git a/net/ghttp/ghttp_z_unit_feature_log_test.go b/net/ghttp/ghttp_z_unit_feature_log_test.go
index 4b57c9ba8..6e74e2765 100644
--- a/net/ghttp/ghttp_z_unit_feature_log_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_log_test.go
@@ -15,18 +15,17 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gstr"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Log(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
logDir := gfile.Temp(gtime.TimestampNanoStr())
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/hello", func(r *ghttp.Request) {
r.Response.Write("hello")
})
@@ -37,13 +36,12 @@ func Test_Log(t *testing.T) {
s.SetAccessLogEnabled(true)
s.SetErrorLogEnabled(true)
s.SetLogStdout(false)
- s.SetPort(p)
s.Start()
defer s.Shutdown()
defer gfile.Remove(logDir)
time.Sleep(100 * time.Millisecond)
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/hello"), "hello")
t.Assert(client.GetContent(ctx, "/error"), "exception recovered: custom error")
diff --git a/net/ghttp/ghttp_z_unit_feature_middleware_basic_test.go b/net/ghttp/ghttp_z_unit_feature_middleware_basic_test.go
index 956ce2687..bc473fa4a 100644
--- a/net/ghttp/ghttp_z_unit_feature_middleware_basic_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_middleware_basic_test.go
@@ -16,13 +16,12 @@ import (
"github.com/gogf/gf/v2/debug/gdebug"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_BindMiddleware_Basic1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -44,7 +43,6 @@ func Test_BindMiddleware_Basic1(t *testing.T) {
r.Middleware.Next()
r.Response.Write("8")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -52,7 +50,7 @@ func Test_BindMiddleware_Basic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/test"), "1342")
@@ -61,8 +59,7 @@ func Test_BindMiddleware_Basic1(t *testing.T) {
}
func Test_BindMiddleware_Basic2(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -71,7 +68,6 @@ func Test_BindMiddleware_Basic2(t *testing.T) {
r.Middleware.Next()
r.Response.Write("2")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -79,7 +75,7 @@ func Test_BindMiddleware_Basic2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "12")
t.Assert(client.GetContent(ctx, "/test"), "12")
@@ -88,8 +84,7 @@ func Test_BindMiddleware_Basic2(t *testing.T) {
}
func Test_BindMiddleware_Basic3(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -111,7 +106,6 @@ func Test_BindMiddleware_Basic3(t *testing.T) {
r.Middleware.Next()
r.Response.Write("8")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -119,7 +113,7 @@ func Test_BindMiddleware_Basic3(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/test"), "Not Found")
@@ -132,8 +126,7 @@ func Test_BindMiddleware_Basic3(t *testing.T) {
}
func Test_BindMiddleware_Basic4(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.Response.Write("1")
@@ -147,7 +140,6 @@ func Test_BindMiddleware_Basic4(t *testing.T) {
r.Response.Write("test")
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -155,7 +147,7 @@ func Test_BindMiddleware_Basic4(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/test"), "1test2")
@@ -164,8 +156,7 @@ func Test_BindMiddleware_Basic4(t *testing.T) {
}
func Test_Middleware_With_Static(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.Response.Write("1")
@@ -176,7 +167,6 @@ func Test_Middleware_With_Static(t *testing.T) {
r.Response.Write("list")
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.SetServerRoot(gdebug.TestDataPath("static1"))
s.Start()
@@ -184,7 +174,7 @@ func Test_Middleware_With_Static(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "index")
t.Assert(client.GetContent(ctx, "/test.html"), "test")
@@ -194,8 +184,7 @@ func Test_Middleware_With_Static(t *testing.T) {
}
func Test_Middleware_Status(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.Middleware.Next()
@@ -205,14 +194,13 @@ func Test_Middleware_Status(t *testing.T) {
r.Response.Write("list")
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/user/list"), "200")
@@ -225,8 +213,7 @@ func Test_Middleware_Status(t *testing.T) {
}
func Test_Middleware_Hook_With_Static(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
a := garray.New(true)
s.Group("/", func(group *ghttp.RouterGroup) {
group.Hook("/*", ghttp.HookBeforeServe, func(r *ghttp.Request) {
@@ -248,7 +235,6 @@ func Test_Middleware_Hook_With_Static(t *testing.T) {
r.Response.Write("list")
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.SetServerRoot(gdebug.TestDataPath("static1"))
s.Start()
@@ -256,7 +242,7 @@ func Test_Middleware_Hook_With_Static(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
// The length assert sometimes fails, so I added time.Sleep here for debug purpose.
@@ -279,15 +265,13 @@ func Test_Middleware_Hook_With_Static(t *testing.T) {
}
func Test_BindMiddleware_Status(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
s.BindMiddleware("/test/*any", func(r *ghttp.Request) {
r.Middleware.Next()
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -295,7 +279,7 @@ func Test_BindMiddleware_Status(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/test"), "Not Found")
@@ -305,8 +289,7 @@ func Test_BindMiddleware_Status(t *testing.T) {
}
func Test_BindMiddlewareDefault_Basic1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -320,7 +303,6 @@ func Test_BindMiddlewareDefault_Basic1(t *testing.T) {
r.Middleware.Next()
r.Response.Write("4")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -328,7 +310,7 @@ func Test_BindMiddlewareDefault_Basic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "1342")
t.Assert(client.GetContent(ctx, "/test/test"), "13test42")
@@ -336,8 +318,7 @@ func Test_BindMiddlewareDefault_Basic1(t *testing.T) {
}
func Test_BindMiddlewareDefault_Basic2(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("PUT:/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -351,7 +332,6 @@ func Test_BindMiddlewareDefault_Basic2(t *testing.T) {
r.Middleware.Next()
r.Response.Write("4")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -359,7 +339,7 @@ func Test_BindMiddlewareDefault_Basic2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "1342")
t.Assert(client.PutContent(ctx, "/"), "1342")
@@ -369,8 +349,7 @@ func Test_BindMiddlewareDefault_Basic2(t *testing.T) {
}
func Test_BindMiddlewareDefault_Basic3(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -382,7 +361,6 @@ func Test_BindMiddlewareDefault_Basic3(t *testing.T) {
r.Middleware.Next()
r.Response.Write("2")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -390,7 +368,7 @@ func Test_BindMiddlewareDefault_Basic3(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "12")
t.Assert(client.GetContent(ctx, "/test/test"), "1test2")
@@ -398,8 +376,7 @@ func Test_BindMiddlewareDefault_Basic3(t *testing.T) {
}
func Test_BindMiddlewareDefault_Basic4(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -411,7 +388,6 @@ func Test_BindMiddlewareDefault_Basic4(t *testing.T) {
r.Response.Write("2")
r.Middleware.Next()
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -419,7 +395,7 @@ func Test_BindMiddlewareDefault_Basic4(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "21")
t.Assert(client.GetContent(ctx, "/test/test"), "2test1")
@@ -427,8 +403,7 @@ func Test_BindMiddlewareDefault_Basic4(t *testing.T) {
}
func Test_BindMiddlewareDefault_Basic5(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -440,7 +415,6 @@ func Test_BindMiddlewareDefault_Basic5(t *testing.T) {
r.Response.Write("2")
r.Middleware.Next()
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -448,7 +422,7 @@ func Test_BindMiddlewareDefault_Basic5(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "12")
t.Assert(client.GetContent(ctx, "/test/test"), "12test")
@@ -456,15 +430,13 @@ func Test_BindMiddlewareDefault_Basic5(t *testing.T) {
}
func Test_BindMiddlewareDefault_Status(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
s.BindMiddlewareDefault(func(r *ghttp.Request) {
r.Middleware.Next()
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -472,7 +444,7 @@ func Test_BindMiddlewareDefault_Status(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/test/test"), "test")
@@ -502,8 +474,7 @@ func (o *ObjectMiddleware) Info(r *ghttp.Request) {
}
func Test_BindMiddlewareDefault_Basic6(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindObject("/", new(ObjectMiddleware))
s.BindMiddlewareDefault(func(r *ghttp.Request) {
r.Response.Write("1")
@@ -515,7 +486,6 @@ func Test_BindMiddlewareDefault_Basic6(t *testing.T) {
r.Middleware.Next()
r.Response.Write("4")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -523,7 +493,7 @@ func Test_BindMiddlewareDefault_Basic6(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "13100Object Index20042")
t.Assert(client.GetContent(ctx, "/init"), "1342")
@@ -535,8 +505,7 @@ func Test_BindMiddlewareDefault_Basic6(t *testing.T) {
}
func Test_Hook_Middleware_Basic1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -562,7 +531,6 @@ func Test_Hook_Middleware_Basic1(t *testing.T) {
r.Middleware.Next()
r.Response.Write("4")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -570,7 +538,7 @@ func Test_Hook_Middleware_Basic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "ac1342bd")
t.Assert(client.GetContent(ctx, "/test/test"), "ac13test42bd")
@@ -592,8 +560,7 @@ func MiddlewareCORS(r *ghttp.Request) {
}
func Test_Middleware_CORSAndAuth(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Use(MiddlewareCORS)
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
group.Middleware(MiddlewareAuth)
@@ -601,14 +568,13 @@ func Test_Middleware_CORSAndAuth(t *testing.T) {
r.Response.Write("list")
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
// Common Checks.
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
@@ -646,8 +612,7 @@ func MiddlewareScope3(r *ghttp.Request) {
}
func Test_Middleware_Scope(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(MiddlewareScope1)
group.ALL("/scope1", func(r *ghttp.Request) {
@@ -666,14 +631,13 @@ func Test_Middleware_Scope(t *testing.T) {
})
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/scope1"), "a1b")
@@ -683,8 +647,7 @@ func Test_Middleware_Scope(t *testing.T) {
}
func Test_Middleware_Panic(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
i := 0
s.Group("/", func(group *ghttp.RouterGroup) {
group.Group("/", func(group *ghttp.RouterGroup) {
@@ -701,14 +664,13 @@ func Test_Middleware_Panic(t *testing.T) {
})
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "exception recovered: error")
})
diff --git a/net/ghttp/ghttp_z_unit_feature_middleware_cors_test.go b/net/ghttp/ghttp_z_unit_feature_middleware_cors_test.go
index 77abbcd68..d0f4752e7 100644
--- a/net/ghttp/ghttp_z_unit_feature_middleware_cors_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_middleware_cors_test.go
@@ -13,27 +13,25 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Middleware_CORS1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
group.Middleware(MiddlewareCORS)
group.POST("/user/list", func(r *ghttp.Request) {
r.Response.Write("list")
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
// Common Checks.
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
@@ -58,7 +56,7 @@ func Test_Middleware_CORS1(t *testing.T) {
// OPTIONS GET
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "GET")
resp, err := client.Options(ctx, "/api.v2/user/list")
t.Assert(err, nil)
@@ -70,7 +68,7 @@ func Test_Middleware_CORS1(t *testing.T) {
// OPTIONS POST
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "POST")
resp, err := client.Options(ctx, "/api.v2/user/list")
t.Assert(err, nil)
@@ -81,22 +79,20 @@ func Test_Middleware_CORS1(t *testing.T) {
}
func Test_Middleware_CORS2(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
group.Middleware(MiddlewareCORS)
group.GET("/user/list/{type}", func(r *ghttp.Request) {
r.Response.Write(r.Get("type"))
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
// Common Checks.
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
@@ -114,7 +110,7 @@ func Test_Middleware_CORS2(t *testing.T) {
// OPTIONS GET None.
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "GET")
resp, err := client.Options(ctx, "/api.v2/user")
t.Assert(err, nil)
@@ -125,7 +121,7 @@ func Test_Middleware_CORS2(t *testing.T) {
// OPTIONS GET
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "GET")
resp, err := client.Options(ctx, "/api.v2/user/list/1")
t.Assert(err, nil)
@@ -136,7 +132,7 @@ func Test_Middleware_CORS2(t *testing.T) {
// OPTIONS POST
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "POST")
resp, err := client.Options(ctx, "/api.v2/user/list/1")
t.Assert(err, nil)
diff --git a/net/ghttp/ghttp_z_unit_feature_openapi_swagger_test.go b/net/ghttp/ghttp_z_unit_feature_openapi_swagger_test.go
index 8aea1eb4c..749d67732 100644
--- a/net/ghttp/ghttp_z_unit_feature_openapi_swagger_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_openapi_swagger_test.go
@@ -15,10 +15,10 @@ import (
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gmeta"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_OpenApi_Swagger(t *testing.T) {
@@ -32,8 +32,7 @@ func Test_OpenApi_Swagger(t *testing.T) {
Age int
Name string
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.SetSwaggerPath("/swagger")
s.SetOpenApiPath("/api.json")
s.Use(ghttp.MiddlewareHandlerResponse)
@@ -51,7 +50,6 @@ func Test_OpenApi_Swagger(t *testing.T) {
Name: req.Name,
}, gerror.New("error")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -59,7 +57,7 @@ func Test_OpenApi_Swagger(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/test?age=18&name=john"), `{"code":0,"message":"","data":{"Id":1,"Age":18,"Name":"john"}}`)
t.Assert(c.GetContent(ctx, "/test/error"), `{"code":50,"message":"error","data":null}`)
diff --git a/net/ghttp/ghttp_z_unit_feature_otel_test.go b/net/ghttp/ghttp_z_unit_feature_otel_test.go
index f19370773..0400c4fc8 100644
--- a/net/ghttp/ghttp_z_unit_feature_otel_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_otel_test.go
@@ -13,29 +13,27 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/net/gtrace"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_OTEL_TraceID(t *testing.T) {
var (
traceId string
)
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/", func(r *ghttp.Request) {
traceId = gtrace.GetTraceID(r.Context())
r.Response.Write(r.GetUrl())
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
+ prefix := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())
client := g.Client()
client.SetBrowserMode(true)
client.SetPrefix(prefix)
diff --git a/net/ghttp/ghttp_z_unit_feature_pprof_test.go b/net/ghttp/ghttp_z_unit_feature_pprof_test.go
index b24fd873e..75ad0bc8f 100644
--- a/net/ghttp/ghttp_z_unit_feature_pprof_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_pprof_test.go
@@ -14,22 +14,20 @@ import (
"time"
"github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/net/gtcp"
. "github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func TestServer_EnablePProf(t *testing.T) {
C(t, func(t *T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.EnablePProf("/pprof")
s.SetDumpRouterMap(false)
- s.SetPort(p)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
r, err := client.Get(ctx, "/pprof/index")
Assert(err, nil)
diff --git a/net/ghttp/ghttp_z_unit_feature_request_ctx_test.go b/net/ghttp/ghttp_z_unit_feature_request_ctx_test.go
index c615e01aa..54b88a532 100644
--- a/net/ghttp/ghttp_z_unit_feature_request_ctx_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_request_ctx_test.go
@@ -14,13 +14,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Request_SetCtx(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
ctx := context.WithValue(r.Context(), "test", 1)
@@ -31,7 +30,6 @@ func Test_Request_SetCtx(t *testing.T) {
r.Response.Write(r.Context().Value("test"))
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -39,7 +37,7 @@ func Test_Request_SetCtx(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/"), "1")
})
diff --git a/net/ghttp/ghttp_z_unit_feature_request_file_test.go b/net/ghttp/ghttp_z_unit_feature_request_file_test.go
index 6b3d92dea..bf273f62a 100644
--- a/net/ghttp/ghttp_z_unit_feature_request_file_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_request_file_test.go
@@ -14,17 +14,16 @@ import (
"github.com/gogf/gf/v2/debug/gdebug"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gstr"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Params_File_Single(t *testing.T) {
dstDirPath := gfile.Temp(gtime.TimestampNanoStr())
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/upload/single", func(r *ghttp.Request) {
file := r.GetUploadFile("file")
if file == nil {
@@ -36,7 +35,6 @@ func Test_Params_File_Single(t *testing.T) {
}
r.Response.WriteExit("upload failed")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -44,7 +42,7 @@ func Test_Params_File_Single(t *testing.T) {
// normal name
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
srcPath := gdebug.TestDataPath("upload", "file1.txt")
dstPath := gfile.Join(dstDirPath, "file1.txt")
@@ -60,7 +58,7 @@ func Test_Params_File_Single(t *testing.T) {
// randomly rename.
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
srcPath := gdebug.TestDataPath("upload", "file2.txt")
content := client.PostContent(ctx, "/upload/single", g.Map{
@@ -77,8 +75,7 @@ func Test_Params_File_Single(t *testing.T) {
func Test_Params_File_CustomName(t *testing.T) {
dstDirPath := gfile.Temp(gtime.TimestampNanoStr())
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/upload/single", func(r *ghttp.Request) {
file := r.GetUploadFile("file")
if file == nil {
@@ -90,14 +87,13 @@ func Test_Params_File_CustomName(t *testing.T) {
}
r.Response.WriteExit("upload failed")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
srcPath := gdebug.TestDataPath("upload", "file1.txt")
dstPath := gfile.Join(dstDirPath, "my.txt")
@@ -114,8 +110,7 @@ func Test_Params_File_CustomName(t *testing.T) {
func Test_Params_File_Batch(t *testing.T) {
dstDirPath := gfile.Temp(gtime.TimestampNanoStr())
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/upload/batch", func(r *ghttp.Request) {
files := r.GetUploadFiles("file")
if files == nil {
@@ -126,7 +121,6 @@ func Test_Params_File_Batch(t *testing.T) {
}
r.Response.WriteExit("upload failed")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -134,7 +128,7 @@ func Test_Params_File_Batch(t *testing.T) {
// normal name
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
srcPath1 := gdebug.TestDataPath("upload", "file1.txt")
srcPath2 := gdebug.TestDataPath("upload", "file2.txt")
@@ -154,7 +148,7 @@ func Test_Params_File_Batch(t *testing.T) {
// randomly rename.
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
srcPath1 := gdebug.TestDataPath("upload", "file1.txt")
srcPath2 := gdebug.TestDataPath("upload", "file2.txt")
diff --git a/net/ghttp/ghttp_z_unit_feature_request_json_test.go b/net/ghttp/ghttp_z_unit_feature_request_json_test.go
index 2ccbf81e4..d219d29b2 100644
--- a/net/ghttp/ghttp_z_unit_feature_request_json_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_request_json_test.go
@@ -14,8 +14,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Params_Json_Request(t *testing.T) {
@@ -26,8 +26,7 @@ func Test_Params_Json_Request(t *testing.T) {
Pass1 string `p:"password1"`
Pass2 string `p:"password2" v:"password2@required|length:2,20|password3|same:password1#||密码强度不足|两次密码不一致"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/get", func(r *ghttp.Request) {
r.Response.WriteExit(r.Get("id"), r.Get("name"))
})
@@ -45,7 +44,6 @@ func Test_Params_Json_Request(t *testing.T) {
r.Response.WriteExit(user.Id, user.Name, user.Pass1, user.Pass2)
}
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -53,7 +51,7 @@ func Test_Params_Json_Request(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/get", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), ``)
t.Assert(client.GetContent(ctx, "/map", `{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}`), ``)
@@ -72,8 +70,7 @@ func Test_Params_Json_Response(t *testing.T) {
Pass2 string `json:"password2"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/json1", func(r *ghttp.Request) {
r.Response.WriteJson(User{
Uid: 100,
@@ -134,7 +131,6 @@ func Test_Params_Json_Response(t *testing.T) {
}
r.Response.WriteJson(responseJson)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -142,7 +138,7 @@ func Test_Params_Json_Response(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
map1 := make(map[string]interface{})
err1 := json.UnmarshalUseNumber([]byte(client.GetContent(ctx, "/json1")), &map1)
diff --git a/net/ghttp/ghttp_z_unit_feature_request_page_test.go b/net/ghttp/ghttp_z_unit_feature_request_page_test.go
index db140acfc..dcb1fea36 100644
--- a/net/ghttp/ghttp_z_unit_feature_request_page_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_request_page_test.go
@@ -13,13 +13,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Params_Page(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.GET("/list", func(r *ghttp.Request) {
page := r.GetPage(5, 2)
@@ -30,7 +29,6 @@ func Test_Params_Page(t *testing.T) {
r.Response.Write(page.GetContent(4))
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -38,7 +36,7 @@ func Test_Params_Page(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/list"), `首页上一页123下一页尾页`)
t.Assert(client.GetContent(ctx, "/list?page=3"), `首页上一页123下一页尾页`)
diff --git a/net/ghttp/ghttp_z_unit_feature_request_struct_test.go b/net/ghttp/ghttp_z_unit_feature_request_struct_test.go
index dc476c664..e6b05f991 100644
--- a/net/ghttp/ghttp_z_unit_feature_request_struct_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_request_struct_test.go
@@ -13,8 +13,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
"github.com/gogf/gf/v2/util/gvalid"
)
@@ -24,8 +24,7 @@ func Test_Params_Parse(t *testing.T) {
Name string
Map map[string]interface{}
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse", func(r *ghttp.Request) {
var user *User
if err := r.Parse(&user); err != nil {
@@ -33,7 +32,6 @@ func Test_Params_Parse(t *testing.T) {
}
r.Response.WriteExit(user.Map["id"], user.Map["score"])
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -41,7 +39,7 @@ func Test_Params_Parse(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.PostContent(ctx, "/parse", `{"id":1,"name":"john","map":{"id":1,"score":100}}`), `1100`)
})
}
@@ -51,8 +49,7 @@ func Test_Params_ParseQuery(t *testing.T) {
Id int
Name string
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse-query", func(r *ghttp.Request) {
var user *User
if err := r.ParseQuery(&user); err != nil {
@@ -60,7 +57,6 @@ func Test_Params_ParseQuery(t *testing.T) {
}
r.Response.WriteExit(user.Id, user.Name)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -68,7 +64,7 @@ func Test_Params_ParseQuery(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/parse-query"), `0`)
t.Assert(c.GetContent(ctx, "/parse-query?id=1&name=john"), `1john`)
t.Assert(c.PostContent(ctx, "/parse-query"), `0`)
@@ -84,8 +80,7 @@ func Test_Params_ParseForm(t *testing.T) {
Id int
Name string
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse-form", func(r *ghttp.Request) {
var user *User
if err := r.ParseForm(&user); err != nil {
@@ -93,7 +88,6 @@ func Test_Params_ParseForm(t *testing.T) {
}
r.Response.WriteExit(user.Id, user.Name)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -101,7 +95,7 @@ func Test_Params_ParseForm(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/parse-form"), `0`)
t.Assert(c.GetContent(ctx, "/parse-form", g.Map{
"id": 1,
@@ -183,8 +177,7 @@ func Test_Params_ComplexJsonStruct(t *testing.T) {
ReadinessProbe ItemProbe
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse", func(r *ghttp.Request) {
if m := r.GetMap(); len(m) > 0 {
var data *SaveRequest
@@ -194,7 +187,6 @@ func Test_Params_ComplexJsonStruct(t *testing.T) {
r.Response.WriteExit(data)
}
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -202,7 +194,7 @@ func Test_Params_ComplexJsonStruct(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
content := `
{
"app_id": 5,
@@ -295,8 +287,7 @@ func Test_Params_Parse_Attr_Pointer1(t *testing.T) {
Id *int
Name *string
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse1", func(r *ghttp.Request) {
if m := r.GetMap(); len(m) > 0 {
var user *User
@@ -315,7 +306,6 @@ func Test_Params_Parse_Attr_Pointer1(t *testing.T) {
r.Response.WriteExit(user.Id, user.Name)
}
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -323,7 +313,7 @@ func Test_Params_Parse_Attr_Pointer1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.PostContent(ctx, "/parse1", `{"id":1,"name":"john"}`), `1john`)
t.Assert(client.PostContent(ctx, "/parse2", `{"id":1,"name":"john"}`), `1john`)
t.Assert(client.PostContent(ctx, "/parse2?id=1&name=john"), `1john`)
@@ -335,8 +325,7 @@ func Test_Params_Parse_Attr_Pointer2(t *testing.T) {
type User struct {
Id *int `v:"required"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse", func(r *ghttp.Request) {
var user *User
if err := r.Parse(&user); err != nil {
@@ -344,7 +333,6 @@ func Test_Params_Parse_Attr_Pointer2(t *testing.T) {
}
r.Response.WriteExit(user.Id)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -352,7 +340,7 @@ func Test_Params_Parse_Attr_Pointer2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.PostContent(ctx, "/parse"), `The Id field is required`)
t.Assert(client.PostContent(ctx, "/parse?id=1"), `1`)
})
@@ -365,8 +353,7 @@ func Test_Params_Parse_Attr_Pointer2(t *testing.T) {
// Name string
// Scores [][]int
// }
-// p, _ := gtcp.GetFreePort()
-// s := g.Server(p)
+// // s := g.Server(guid.S())
// s.BindHandler("/parse", func(r *ghttp.Request) {
// if m := r.GetMap(); len(m) > 0 {
// var user *User
@@ -376,15 +363,14 @@ func Test_Params_Parse_Attr_Pointer2(t *testing.T) {
// r.Response.WriteExit(user.Scores)
// }
// })
-// s.SetPort(p)
-// s.SetDumpRouterMap(false)
+// // s.SetDumpRouterMap(false)
// s.Start()
// defer s.Shutdown()
//
// time.Sleep(100 * time.Millisecond)
// gtest.C(t, func(t *gtest.T) {
// client := g.Client()
-// client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+// client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
// t.Assert(client.PostContent(ctx, "/parse", `{"id":1,"name":"john","scores":[[1,2,3]]}`), `1100`)
// })
// }
@@ -397,8 +383,7 @@ func Test_Params_Struct(t *testing.T) {
Pass1 string `p:"password1"`
Pass2 string `p:"password2" v:"password2 @required|length:2,20|password3#||密码强度不足"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/struct1", func(r *ghttp.Request) {
if m := r.GetMap(); len(m) > 0 {
user := new(User)
@@ -439,7 +424,6 @@ func Test_Params_Struct(t *testing.T) {
r.Response.WriteExit(user.Id, user.Name, user.Pass1, user.Pass2)
}
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -447,7 +431,7 @@ func Test_Params_Struct(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
t.Assert(client.PostContent(ctx, "/struct1", `id=1&name=john&password1=123&password2=456`), `1john123456`)
t.Assert(client.PostContent(ctx, "/struct2", `id=1&name=john&password1=123&password2=456`), `1john123456`)
@@ -466,8 +450,7 @@ func Test_Params_Structs(t *testing.T) {
Pass1 string `p:"password1"`
Pass2 string `p:"password2" v:"password2 @required|length:2,20|password3#||密码强度不足"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse1", func(r *ghttp.Request) {
var users []*User
if err := r.Parse(&users); err != nil {
@@ -475,7 +458,6 @@ func Test_Params_Structs(t *testing.T) {
}
r.Response.WriteExit(users[0].Id, users[1].Id)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -483,7 +465,7 @@ func Test_Params_Structs(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.PostContent(ctx,
"/parse1",
`[{"id":1,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}, {"id":2,"name":"john","password1":"123Abc!@#","password2":"123Abc!@#"}]`),
@@ -497,8 +479,7 @@ func Test_Params_Struct_Validation(t *testing.T) {
Id int `v:"required"`
Name string `v:"name@required-with:id"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.ALL("/", func(r *ghttp.Request) {
var (
@@ -512,7 +493,6 @@ func Test_Params_Struct_Validation(t *testing.T) {
r.Response.WriteExit(user.Id, user.Name)
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -520,7 +500,7 @@ func Test_Params_Struct_Validation(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/", ``), `The Id field is required`)
t.Assert(c.GetContent(ctx, "/", `id=1&name=john`), `1john`)
t.Assert(c.PostContent(ctx, "/", `id=1&name=john&password1=123&password2=456`), `1john`)
@@ -530,8 +510,7 @@ func Test_Params_Struct_Validation(t *testing.T) {
// https://github.com/gogf/gf/issues/1488
func Test_Params_Parse_Issue1488(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.ALL("/", func(r *ghttp.Request) {
type Request struct {
@@ -562,7 +541,6 @@ func Test_Params_Parse_Issue1488(t *testing.T) {
}
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -570,7 +548,7 @@ func Test_Params_Parse_Issue1488(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/", ``), `16161616161616161616`)
})
}
diff --git a/net/ghttp/ghttp_z_unit_feature_request_test.go b/net/ghttp/ghttp_z_unit_feature_request_test.go
index 2c8646117..b4b660811 100644
--- a/net/ghttp/ghttp_z_unit_feature_request_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_request_test.go
@@ -16,8 +16,8 @@ import (
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Params_Basic(t *testing.T) {
@@ -27,8 +27,7 @@ func Test_Params_Basic(t *testing.T) {
Pass1 string `params:"password1"`
Pass2 string `params:"password2"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
// GET
s.BindHandler("/get", func(r *ghttp.Request) {
if r.GetQuery("array") != nil {
@@ -259,7 +258,6 @@ func Test_Params_Basic(t *testing.T) {
r.Response.Write(user2.Id, user2.Name, user2.Pass.Pass1, user2.Pass.Pass2)
}
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -267,7 +265,7 @@ func Test_Params_Basic(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
// GET
t.Assert(client.GetContent(ctx, "/get", "array[]=1&array[]=2"), `["1","2"]`)
t.Assert(client.GetContent(ctx, "/get", "slice=1&slice=2"), `2`)
@@ -362,19 +360,17 @@ func Test_Params_Basic(t *testing.T) {
}
func Test_Params_Header(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/header", func(r *ghttp.Request) {
r.Response.Write(r.GetHeader("test"))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
+ prefix := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())
client := g.Client()
client.SetPrefix(prefix)
@@ -383,15 +379,13 @@ func Test_Params_Header(t *testing.T) {
}
func Test_Params_SupportChars(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/form-value", func(r *ghttp.Request) {
r.Response.Write(r.GetForm("test-value"))
})
s.BindHandler("/form-array", func(r *ghttp.Request) {
r.Response.Write(r.GetForm("test-array"))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -399,15 +393,14 @@ func Test_Params_SupportChars(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.PostContent(ctx, "/form-value", "test-value=100"), "100")
t.Assert(c.PostContent(ctx, "/form-array", "test-array[]=1&test-array[]=2"), `["1","2"]`)
})
}
func Test_Params_Priority(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/query", func(r *ghttp.Request) {
r.Response.Write(r.GetQuery("a"))
})
@@ -423,14 +416,13 @@ func Test_Params_Priority(t *testing.T) {
"b": 2,
}))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
+ prefix := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())
client := g.Client()
client.SetPrefix(prefix)
@@ -443,19 +435,17 @@ func Test_Params_Priority(t *testing.T) {
}
func Test_Params_GetRequestMap(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/map", func(r *ghttp.Request) {
r.Response.Write(r.GetRequestMap())
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
+ prefix := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())
client := g.Client()
client.SetPrefix(prefix)
@@ -470,8 +460,7 @@ func Test_Params_GetRequestMap(t *testing.T) {
}
func Test_Params_Modify(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/param/modify", func(r *ghttp.Request) {
param := r.GetMap()
param["id"] = 2
@@ -484,14 +473,13 @@ func Test_Params_Modify(t *testing.T) {
r.ReloadParam()
r.Response.Write(r.GetMap())
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
+ prefix := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())
client := g.Client()
client.SetPrefix(prefix)
@@ -510,8 +498,7 @@ func Test_Params_Parse_DefaultValueTag(t *testing.T) {
Name string `d:"john"`
Score float32 `d:"60"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse", func(r *ghttp.Request) {
var t *T
if err := r.Parse(&t); err != nil {
@@ -519,14 +506,13 @@ func Test_Params_Parse_DefaultValueTag(t *testing.T) {
}
r.Response.WriteExit(t)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
+ prefix := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())
client := g.Client()
client.SetPrefix(prefix)
@@ -543,8 +529,7 @@ func Test_Params_Parse_Validation(t *testing.T) {
Pass2 string `p:"password2" v:"required|length:6,30|same:password1#请确认密码|密码长度不够|两次密码不一致"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse", func(r *ghttp.Request) {
var req *RegisterReq
if err := r.Parse(&req); err != nil {
@@ -553,14 +538,13 @@ func Test_Params_Parse_Validation(t *testing.T) {
r.Response.Write("ok")
}
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
+ prefix := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())
client := g.Client()
client.SetPrefix(prefix)
@@ -589,8 +573,7 @@ func Test_Params_Parse_EmbeddedWithAliasName1(t *testing.T) {
Size int `d:"10" v:"max:50#分页数量最大50条"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse", func(r *ghttp.Request) {
var req *ContentGetListReq
if err := r.Parse(&req); err != nil {
@@ -599,14 +582,13 @@ func Test_Params_Parse_EmbeddedWithAliasName1(t *testing.T) {
r.Response.Write(req.ContentGetListInput)
}
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
+ prefix := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())
client := g.Client()
client.SetPrefix(prefix)
@@ -632,8 +614,7 @@ func Test_Params_Parse_EmbeddedWithAliasName2(t *testing.T) {
Size int `d:"10" v:"max:50#分页数量最大50条"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/parse", func(r *ghttp.Request) {
var req *ContentGetListReq
if err := r.Parse(&req); err != nil {
@@ -642,14 +623,13 @@ func Test_Params_Parse_EmbeddedWithAliasName2(t *testing.T) {
r.Response.Write(req.ContentGetListInput)
}
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
- prefix := fmt.Sprintf("http://127.0.0.1:%d", p)
+ prefix := fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())
client := g.Client()
client.SetPrefix(prefix)
diff --git a/net/ghttp/ghttp_z_unit_feature_request_xml_test.go b/net/ghttp/ghttp_z_unit_feature_request_xml_test.go
index c0ac37e2e..bc5da0abe 100644
--- a/net/ghttp/ghttp_z_unit_feature_request_xml_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_request_xml_test.go
@@ -13,8 +13,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Params_Xml_Request(t *testing.T) {
@@ -25,8 +25,7 @@ func Test_Params_Xml_Request(t *testing.T) {
Pass1 string `p:"password1"`
Pass2 string `p:"password2" v:"password2@required|length:2,20|password3|same:password1#||密码强度不足|两次密码不一致"`
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/get", func(r *ghttp.Request) {
r.Response.WriteExit(r.Get("id"), r.Get("name"))
})
@@ -44,7 +43,6 @@ func Test_Params_Xml_Request(t *testing.T) {
r.Response.WriteExit(user.Id, user.Name, user.Pass1, user.Pass2)
}
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -52,7 +50,7 @@ func Test_Params_Xml_Request(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
content1 := `1john123Abc!@#123Abc!@#`
content2 := `1john123Abc!@#123`
diff --git a/net/ghttp/ghttp_z_unit_feature_router_basic_test.go b/net/ghttp/ghttp_z_unit_feature_router_basic_test.go
index 249382889..72bf276c6 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_basic_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_basic_test.go
@@ -13,13 +13,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Router_Basic1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/:name", func(r *ghttp.Request) {
r.Response.Write("/:name")
})
@@ -35,7 +34,6 @@ func Test_Router_Basic1(t *testing.T) {
s.BindHandler("/user/list/{field}.html", func(r *ghttp.Request) {
r.Response.Write(r.Get("field"))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -43,7 +41,7 @@ func Test_Router_Basic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/john"), "")
t.Assert(client.GetContent(ctx, "/john/update"), "john")
t.Assert(client.GetContent(ctx, "/john/edit"), "edit")
@@ -52,15 +50,13 @@ func Test_Router_Basic1(t *testing.T) {
}
func Test_Router_Basic2(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/{hash}", func(r *ghttp.Request) {
r.Response.Write(r.Get("hash"))
})
s.BindHandler("/{hash}.{type}", func(r *ghttp.Request) {
r.Response.Write(r.Get("type"))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -68,15 +64,14 @@ func Test_Router_Basic2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/data"), "data")
t.Assert(client.GetContent(ctx, "/data.json"), "json")
})
}
func Test_Router_Value(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/{hash}", func(r *ghttp.Request) {
r.Response.Write(r.GetRouter("hash").String())
})
@@ -86,7 +81,6 @@ func Test_Router_Value(t *testing.T) {
s.BindHandler("/{hash}.{type}.map", func(r *ghttp.Request) {
r.Response.Write(r.GetRouterMap()["type"])
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -94,7 +88,7 @@ func Test_Router_Value(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/data"), "data")
t.Assert(client.GetContent(ctx, "/data.json"), "json")
t.Assert(client.GetContent(ctx, "/data.json.map"), "json")
@@ -103,15 +97,13 @@ func Test_Router_Value(t *testing.T) {
// HTTP method register.
func Test_Router_Method(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("GET:/get", func(r *ghttp.Request) {
})
s.BindHandler("POST:/post", func(r *ghttp.Request) {
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -119,7 +111,7 @@ func Test_Router_Method(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
resp1, err := client.Get(ctx, "/get")
defer resp1.Close()
@@ -145,14 +137,12 @@ func Test_Router_Method(t *testing.T) {
// Extra char '/' of the router.
func Test_Router_ExtraChar(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/api", func(group *ghttp.RouterGroup) {
group.GET("/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -160,7 +150,7 @@ func Test_Router_ExtraChar(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/api/test"), "test")
t.Assert(client.GetContent(ctx, "/api/test/"), "test")
@@ -173,8 +163,7 @@ func Test_Router_ExtraChar(t *testing.T) {
// Custom status handler.
func Test_Router_Status(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/200", func(r *ghttp.Request) {
r.Response.WriteStatus(200)
})
@@ -187,7 +176,6 @@ func Test_Router_Status(t *testing.T) {
s.BindHandler("/500", func(r *ghttp.Request) {
r.Response.WriteStatus(500)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -195,7 +183,7 @@ func Test_Router_Status(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
resp1, err := client.Get(ctx, "/200")
defer resp1.Close()
@@ -225,15 +213,13 @@ func Test_Router_Status(t *testing.T) {
}
func Test_Router_CustomStatusHandler(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("hello")
})
s.BindStatusHandler(404, func(r *ghttp.Request) {
r.Response.Write("404 page")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -241,7 +227,7 @@ func Test_Router_CustomStatusHandler(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "hello")
resp, err := client.Get(ctx, "/ThisDoesNotExist")
@@ -254,12 +240,10 @@ func Test_Router_CustomStatusHandler(t *testing.T) {
// 404 not found router.
func Test_Router_404(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("hello")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -267,7 +251,7 @@ func Test_Router_404(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "hello")
resp, err := client.Get(ctx, "/ThisDoesNotExist")
@@ -278,8 +262,7 @@ func Test_Router_404(t *testing.T) {
}
func Test_Router_Priority(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/admin", func(r *ghttp.Request) {
r.Response.Write("admin")
})
@@ -292,7 +275,6 @@ func Test_Router_Priority(t *testing.T) {
s.BindHandler("/admin-goods-{page}", func(r *ghttp.Request) {
r.Response.Write("admin-goods-{page}")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -300,7 +282,7 @@ func Test_Router_Priority(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/admin"), "admin")
t.Assert(client.GetContent(ctx, "/admin-1"), "admin-{page}")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_domain_basic_test.go b/net/ghttp/ghttp_z_unit_feature_router_domain_basic_test.go
index 92e95f841..c8c00d908 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_domain_basic_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_domain_basic_test.go
@@ -14,13 +14,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/intlog"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Router_DomainBasic(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
d := s.Domain("localhost, local")
d.BindHandler("/:name", func(r *ghttp.Request) {
r.Response.Write("/:name")
@@ -37,7 +36,6 @@ func Test_Router_DomainBasic(t *testing.T) {
d.BindHandler("/user/list/{field}.html", func(r *ghttp.Request) {
r.Response.Write(r.Get("field"))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -45,7 +43,7 @@ func Test_Router_DomainBasic(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/john"), "Not Found")
t.Assert(client.GetContent(ctx, "/john/update"), "Not Found")
t.Assert(client.GetContent(ctx, "/john/edit"), "Not Found")
@@ -53,7 +51,7 @@ func Test_Router_DomainBasic(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://localhost:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/john"), "")
t.Assert(client.GetContent(ctx, "/john/update"), "john")
t.Assert(client.GetContent(ctx, "/john/edit"), "edit")
@@ -61,7 +59,7 @@ func Test_Router_DomainBasic(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/john"), "")
t.Assert(client.GetContent(ctx, "/john/update"), "john")
t.Assert(client.GetContent(ctx, "/john/edit"), "edit")
@@ -70,8 +68,7 @@ func Test_Router_DomainBasic(t *testing.T) {
}
func Test_Router_DomainMethod(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
d := s.Domain("localhost, local")
d.BindHandler("GET:/get", func(r *ghttp.Request) {
@@ -79,7 +76,6 @@ func Test_Router_DomainMethod(t *testing.T) {
d.BindHandler("POST:/post", func(r *ghttp.Request) {
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -87,7 +83,7 @@ func Test_Router_DomainMethod(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
resp1, err := client.Get(ctx, "/get")
defer resp1.Close()
@@ -112,7 +108,7 @@ func Test_Router_DomainMethod(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://localhost:%d", s.GetListenedPort()))
resp1, err := client.Get(ctx, "/get")
defer resp1.Close()
@@ -137,7 +133,7 @@ func Test_Router_DomainMethod(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
resp1, err := client.Get(ctx, "/get")
defer resp1.Close()
@@ -162,8 +158,7 @@ func Test_Router_DomainMethod(t *testing.T) {
}
func Test_Router_DomainStatus(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
d := s.Domain("localhost, local")
d.BindHandler("/200", func(r *ghttp.Request) {
r.Response.WriteStatus(200)
@@ -177,7 +172,6 @@ func Test_Router_DomainStatus(t *testing.T) {
d.BindHandler("/500", func(r *ghttp.Request) {
r.Response.WriteStatus(500)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -185,7 +179,7 @@ func Test_Router_DomainStatus(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
resp1, err := client.Get(ctx, "/200")
defer resp1.Close()
@@ -209,7 +203,7 @@ func Test_Router_DomainStatus(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://localhost:%d", s.GetListenedPort()))
resp1, err := client.Get(ctx, "/200")
defer resp1.Close()
@@ -233,7 +227,7 @@ func Test_Router_DomainStatus(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
resp1, err := client.Get(ctx, "/200")
defer resp1.Close()
@@ -258,8 +252,7 @@ func Test_Router_DomainStatus(t *testing.T) {
}
func Test_Router_DomainCustomStatusHandler(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
d := s.Domain("localhost, local")
d.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("hello")
@@ -267,7 +260,6 @@ func Test_Router_DomainCustomStatusHandler(t *testing.T) {
d.BindStatusHandler(404, func(r *ghttp.Request) {
r.Response.Write("404 page")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -275,21 +267,21 @@ func Test_Router_DomainCustomStatusHandler(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/ThisDoesNotExist"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://localhost:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "hello")
t.Assert(client.GetContent(ctx, "/ThisDoesNotExist"), "404 page")
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "hello")
t.Assert(client.GetContent(ctx, "/ThisDoesNotExist"), "404 page")
@@ -297,13 +289,11 @@ func Test_Router_DomainCustomStatusHandler(t *testing.T) {
}
func Test_Router_Domain404(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
d := s.Domain("localhost, local")
d.BindHandler("/", func(r *ghttp.Request) {
r.Response.Write("hello")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -311,27 +301,26 @@ func Test_Router_Domain404(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://localhost:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "hello")
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "hello")
})
}
func Test_Router_DomainGroup(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
d := s.Domain("localhost, local")
d.Group("/", func(group *ghttp.RouterGroup) {
group.Group("/app", func(group *ghttp.RouterGroup) {
@@ -349,7 +338,6 @@ func Test_Router_DomainGroup(t *testing.T) {
})
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -357,10 +345,10 @@ func Test_Router_DomainGroup(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client1 := g.Client()
- client1.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client1.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
client2 := g.Client()
- client2.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client2.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client1.GetContent(ctx, "/app/t/list/2.html"), "t&2")
t.Assert(client2.GetContent(ctx, "/app/t/list/2.html"), "Not Found")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_domain_object_rest_test.go b/net/ghttp/ghttp_z_unit_feature_router_domain_object_rest_test.go
index 3f624d438..6b30f82a8 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_domain_object_rest_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_domain_object_rest_test.go
@@ -13,8 +13,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
type DomainObjectRest struct{}
@@ -56,11 +56,9 @@ func (o *DomainObjectRest) Head(r *ghttp.Request) {
}
func Test_Router_DomainObjectRest(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
d := s.Domain("localhost, local")
d.BindObjectRest("/", new(DomainObjectRest))
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -68,7 +66,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.PutContent(ctx, "/"), "Not Found")
@@ -86,7 +84,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://localhost:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "1Object Get2")
t.Assert(client.PutContent(ctx, "/"), "1Object Put2")
@@ -104,7 +102,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "1Object Get2")
t.Assert(client.PutContent(ctx, "/"), "1Object Put2")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_domain_object_test.go b/net/ghttp/ghttp_z_unit_feature_router_domain_object_test.go
index ecec2464d..48de90f6d 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_domain_object_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_domain_object_test.go
@@ -13,8 +13,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
type DomainObject struct{}
@@ -40,10 +40,8 @@ func (o *DomainObject) Info(r *ghttp.Request) {
}
func Test_Router_DomainObject1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Domain("localhost, local").BindObject("/", new(DomainObject))
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -51,7 +49,7 @@ func Test_Router_DomainObject1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/init"), "Not Found")
@@ -63,7 +61,7 @@ func Test_Router_DomainObject1(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://localhost:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "1Object Index2")
t.Assert(client.GetContent(ctx, "/init"), "Not Found")
@@ -76,7 +74,7 @@ func Test_Router_DomainObject1(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "1Object Index2")
t.Assert(client.GetContent(ctx, "/init"), "Not Found")
@@ -89,10 +87,8 @@ func Test_Router_DomainObject1(t *testing.T) {
}
func Test_Router_DomainObject2(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Domain("localhost, local").BindObject("/object", new(DomainObject), "Show, Info")
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -100,7 +96,7 @@ func Test_Router_DomainObject2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
@@ -113,7 +109,7 @@ func Test_Router_DomainObject2(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://localhost:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
@@ -126,7 +122,7 @@ func Test_Router_DomainObject2(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
@@ -140,10 +136,8 @@ func Test_Router_DomainObject2(t *testing.T) {
}
func Test_Router_DomainObjectMethod(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Domain("localhost, local").BindObjectMethod("/object-info", new(DomainObject), "Info")
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -151,7 +145,7 @@ func Test_Router_DomainObjectMethod(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
@@ -165,7 +159,7 @@ func Test_Router_DomainObjectMethod(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://localhost:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://localhost:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
@@ -179,7 +173,7 @@ func Test_Router_DomainObjectMethod(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://local:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://local:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_exit_test.go b/net/ghttp/ghttp_z_unit_feature_router_exit_test.go
index 46ffe4e14..e7c8648de 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_exit_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_exit_test.go
@@ -13,13 +13,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Router_Exit(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHookHandlerByMap("/*", map[string]ghttp.HandlerFunc{
ghttp.HookBeforeServe: func(r *ghttp.Request) { r.Response.Write("1") },
ghttp.HookAfterServe: func(r *ghttp.Request) { r.Response.Write("2") },
@@ -31,7 +30,6 @@ func Test_Router_Exit(t *testing.T) {
r.Exit()
r.Response.Write("test-end")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -39,7 +37,7 @@ func Test_Router_Exit(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "123")
t.Assert(client.GetContent(ctx, "/test/test"), "1test-start23")
@@ -47,8 +45,7 @@ func Test_Router_Exit(t *testing.T) {
}
func Test_Router_ExitHook(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/priority/show", func(r *ghttp.Request) {
r.Response.Write("show")
})
@@ -69,7 +66,6 @@ func Test_Router_ExitHook(t *testing.T) {
r.ExitHook()
},
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -77,7 +73,7 @@ func Test_Router_ExitHook(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/priority/show"), "3show")
@@ -85,8 +81,7 @@ func Test_Router_ExitHook(t *testing.T) {
}
func Test_Router_ExitAll(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/priority/show", func(r *ghttp.Request) {
r.Response.Write("show")
})
@@ -107,7 +102,6 @@ func Test_Router_ExitAll(t *testing.T) {
r.ExitAll()
},
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -115,7 +109,7 @@ func Test_Router_ExitAll(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/priority/show"), "3")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_group_group_test.go b/net/ghttp/ghttp_z_unit_feature_router_group_group_test.go
index 8adaa360e..1da856f15 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_group_group_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_group_group_test.go
@@ -13,13 +13,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Router_Group_Group(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
group.Middleware(func(r *ghttp.Request) {
r.Response.Write("1")
@@ -57,7 +56,6 @@ func Test_Router_Group_Group(t *testing.T) {
})
})
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -65,7 +63,7 @@ func Test_Router_Group_Group(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_group_hook_test.go b/net/ghttp/ghttp_z_unit_feature_router_group_hook_test.go
index cbf76c3a0..cc3ef8718 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_group_hook_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_group_hook_test.go
@@ -13,13 +13,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Router_Group_Hook1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
group := s.Group("/api")
group.GET("/handler", func(r *ghttp.Request) {
r.Response.Write("1")
@@ -31,7 +30,6 @@ func Test_Router_Group_Hook1(t *testing.T) {
r.Response.Write("2")
}, ghttp.HookAfterServe)
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -39,7 +37,7 @@ func Test_Router_Group_Hook1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/api/handler"), "012")
t.Assert(client.PostContent(ctx, "/api/handler"), "02")
t.Assert(client.GetContent(ctx, "/api/ThisDoesNotExist"), "Not Found")
@@ -47,8 +45,7 @@ func Test_Router_Group_Hook1(t *testing.T) {
}
func Test_Router_Group_Hook2(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
group := s.Group("/api")
group.GET("/handler", func(r *ghttp.Request) {
r.Response.Write("1")
@@ -60,7 +57,6 @@ func Test_Router_Group_Hook2(t *testing.T) {
r.Response.Write("2")
}, ghttp.HookAfterServe)
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -68,7 +64,7 @@ func Test_Router_Group_Hook2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/api/handler"), "012")
t.Assert(client.PostContent(ctx, "/api/handler"), "Not Found")
t.Assert(client.GetContent(ctx, "/api/ThisDoesNotExist"), "02")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_group_rest_test.go b/net/ghttp/ghttp_z_unit_feature_router_group_rest_test.go
index 9528b5cd5..b46c64cc0 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_group_rest_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_group_rest_test.go
@@ -13,8 +13,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
type GroupObjRest struct{}
@@ -56,13 +56,11 @@ func (o *GroupObjRest) Head(r *ghttp.Request) {
}
func Test_Router_GroupRest1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
group := s.Group("/api")
obj := new(GroupObjRest)
group.REST("/obj", obj)
group.REST("/{.struct}/{.method}", obj)
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -70,7 +68,7 @@ func Test_Router_GroupRest1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/api/obj"), "1Object Get2")
t.Assert(client.PutContent(ctx, "/api/obj"), "1Object Put2")
@@ -102,14 +100,12 @@ func Test_Router_GroupRest1(t *testing.T) {
}
func Test_Router_GroupRest2(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/api", func(group *ghttp.RouterGroup) {
obj := new(GroupObjRest)
group.REST("/obj", obj)
group.REST("/{.struct}/{.method}", obj)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -117,7 +113,7 @@ func Test_Router_GroupRest2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/api/obj"), "1Object Get2")
t.Assert(client.PutContent(ctx, "/api/obj"), "1Object Put2")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_group_test.go b/net/ghttp/ghttp_z_unit_feature_router_group_test.go
index c7a253ea0..c006d972e 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_group_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_group_test.go
@@ -15,6 +15,7 @@ import (
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
// 执行对象
@@ -45,8 +46,7 @@ func Handler(r *ghttp.Request) {
}
func Test_Router_GroupBasic1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
obj := new(GroupObject)
// 分组路由方法注册
group := s.Group("/api")
@@ -54,7 +54,6 @@ func Test_Router_GroupBasic1(t *testing.T) {
group.ALL("/obj", obj)
group.GET("/obj/my-show", obj, "Show")
group.REST("/obj/rest", obj)
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -62,7 +61,7 @@ func Test_Router_GroupBasic1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/api/handler"), "Handler")
@@ -80,13 +79,11 @@ func Test_Router_GroupBasic1(t *testing.T) {
}
func Test_Router_GroupBuildInVar(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
obj := new(GroupObject)
// 分组路由方法注册
group := s.Group("/api")
group.ALL("/{.struct}/{.method}", obj)
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -94,7 +91,7 @@ func Test_Router_GroupBuildInVar(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/api/group-object/index"), "1Object Index2")
t.Assert(client.GetContent(ctx, "/api/group-object/delete"), "1Object Delete2")
@@ -106,12 +103,10 @@ func Test_Router_GroupBuildInVar(t *testing.T) {
}
func Test_Router_Group_Methods(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
obj := new(GroupObject)
group := s.Group("/")
group.ALL("/obj", obj, "Show, Delete")
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -119,7 +114,7 @@ func Test_Router_Group_Methods(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/obj/show"), "1Object Show2")
t.Assert(client.GetContent(ctx, "/obj/delete"), "1Object Delete2")
})
@@ -167,15 +162,13 @@ func Test_Router_Group_Map(t *testing.T) {
testFuncPost := func(r *ghttp.Request) {
r.Response.Write("post")
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Map(map[string]interface{}{
"Get: /test": testFuncGet,
"Post:/test": testFuncPost,
})
})
- s.SetPort(p)
//s.SetDumpRouterMap(false)
gtest.Assert(s.Start(), nil)
defer s.Shutdown()
@@ -183,7 +176,7 @@ func Test_Router_Group_Map(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/test"), "get")
t.Assert(c.PostContent(ctx, "/test"), "post")
@@ -192,13 +185,11 @@ func Test_Router_Group_Map(t *testing.T) {
// https://github.com/gogf/gf/issues/1609
func Test_Issue1609(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
group := s.Group("/api/get")
group.GET("/", func(r *ghttp.Request) {
r.Response.Write("get")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
gtest.Assert(s.Start(), nil)
defer s.Shutdown()
@@ -206,7 +197,7 @@ func Test_Issue1609(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
c := g.Client()
- c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/api/get"), "get")
t.Assert(c.PostContent(ctx, "/test"), "Not Found")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_handler_extended_test.go b/net/ghttp/ghttp_z_unit_feature_router_handler_extended_test.go
index cd48c2687..5a8aaf6a3 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_handler_extended_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_handler_extended_test.go
@@ -15,8 +15,8 @@ import (
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Router_Handler_Extended_Handler_WithObject(t *testing.T) {
@@ -29,8 +29,7 @@ func Test_Router_Handler_Extended_Handler_WithObject(t *testing.T) {
Age int
Name string
}
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Use(ghttp.MiddlewareHandlerResponse)
s.BindHandler("/test", func(ctx context.Context, req *TestReq) (res *TestRes, err error) {
return &TestRes{
@@ -46,7 +45,6 @@ func Test_Router_Handler_Extended_Handler_WithObject(t *testing.T) {
Name: req.Name,
}, gerror.New("error")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -54,7 +52,7 @@ func Test_Router_Handler_Extended_Handler_WithObject(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/test?age=18&name=john"), `{"code":0,"message":"","data":{"Id":1,"Age":18,"Name":"john"}}`)
t.Assert(client.GetContent(ctx, "/test/error"), `{"code":50,"message":"error","data":null}`)
@@ -133,13 +131,11 @@ func (ControllerForHandlerWithObjectAndMeta2) Test4(ctx context.Context, req *Te
}, nil
}
func Test_Router_Handler_Extended_Handler_WithObjectAndMeta(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Use(ghttp.MiddlewareHandlerResponse)
s.Group("/", func(group *ghttp.RouterGroup) {
group.ALL("/", new(ControllerForHandlerWithObjectAndMeta1))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -147,7 +143,7 @@ func Test_Router_Handler_Extended_Handler_WithObjectAndMeta(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), `{"code":0,"message":"","data":null}`)
t.Assert(client.GetContent(ctx, "/custom-test1?age=18&name=john"), `{"code":0,"message":"","data":{"Id":1,"Age":18}}`)
@@ -157,8 +153,7 @@ func Test_Router_Handler_Extended_Handler_WithObjectAndMeta(t *testing.T) {
}
func Test_Router_Handler_Extended_Handler_Group_Bind(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.Use(ghttp.MiddlewareHandlerResponse)
s.Group("/api/v1", func(group *ghttp.RouterGroup) {
group.Bind(
@@ -172,7 +167,6 @@ func Test_Router_Handler_Extended_Handler_Group_Bind(t *testing.T) {
new(ControllerForHandlerWithObjectAndMeta2),
)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -180,7 +174,7 @@ func Test_Router_Handler_Extended_Handler_Group_Bind(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), `{"code":0,"message":"","data":null}`)
t.Assert(client.GetContent(ctx, "/api/v1/custom-test1?age=18&name=john"), `{"code":0,"message":"","data":{"Id":1,"Age":18}}`)
diff --git a/net/ghttp/ghttp_z_unit_feature_router_hook_test.go b/net/ghttp/ghttp_z_unit_feature_router_hook_test.go
index ee18e659a..a7d6ab618 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_hook_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_hook_test.go
@@ -13,13 +13,12 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Router_Hook_Basic(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHookHandlerByMap("/*", map[string]ghttp.HandlerFunc{
ghttp.HookBeforeServe: func(r *ghttp.Request) { r.Response.Write("1") },
ghttp.HookAfterServe: func(r *ghttp.Request) { r.Response.Write("2") },
@@ -29,7 +28,6 @@ func Test_Router_Hook_Basic(t *testing.T) {
s.BindHandler("/test/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -37,7 +35,7 @@ func Test_Router_Hook_Basic(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "123")
t.Assert(client.GetContent(ctx, "/test/test"), "1test23")
@@ -45,8 +43,7 @@ func Test_Router_Hook_Basic(t *testing.T) {
}
func Test_Router_Hook_Fuzzy_Router(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
i := 1000
pattern1 := "/:name/info"
s.BindHookHandlerByMap(pattern1, map[string]ghttp.HandlerFunc{
@@ -70,7 +67,6 @@ func Test_Router_Hook_Fuzzy_Router(t *testing.T) {
s.BindHandler(pattern2, func(r *ghttp.Request) {
r.Response.Write(r.Router.Uri)
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -78,7 +74,7 @@ func Test_Router_Hook_Fuzzy_Router(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/john"), "Not Found")
t.Assert(client.GetContent(ctx, "/john/info"), "1000")
@@ -89,8 +85,7 @@ func Test_Router_Hook_Fuzzy_Router(t *testing.T) {
}
func Test_Router_Hook_Priority(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/priority/show", func(r *ghttp.Request) {
r.Response.Write("show")
})
@@ -110,7 +105,6 @@ func Test_Router_Hook_Priority(t *testing.T) {
r.Response.Write("3")
},
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -118,7 +112,7 @@ func Test_Router_Hook_Priority(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/priority/show"), "312show")
@@ -128,8 +122,7 @@ func Test_Router_Hook_Priority(t *testing.T) {
}
func Test_Router_Hook_Multi(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/multi-hook", func(r *ghttp.Request) {
r.Response.Write("show")
})
@@ -144,7 +137,6 @@ func Test_Router_Hook_Multi(t *testing.T) {
r.Response.Write("2")
},
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -152,7 +144,7 @@ func Test_Router_Hook_Multi(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/multi-hook"), "12show")
@@ -160,8 +152,7 @@ func Test_Router_Hook_Multi(t *testing.T) {
}
func Test_Router_Hook_ExitAll(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/test", func(r *ghttp.Request) {
r.Response.Write("test")
})
@@ -179,7 +170,6 @@ func Test_Router_Hook_ExitAll(t *testing.T) {
r.Response.Write("hook")
r.ExitAll()
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -187,7 +177,7 @@ func Test_Router_Hook_ExitAll(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/test"), "test")
t.Assert(client.GetContent(ctx, "/hook/test"), "hook")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_names_test.go b/net/ghttp/ghttp_z_unit_feature_router_names_test.go
index 775cdd7c6..5b46aa2e6 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_names_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_names_test.go
@@ -13,8 +13,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
type NamesObject struct{}
@@ -24,11 +24,9 @@ func (o *NamesObject) ShowName(r *ghttp.Request) {
}
func Test_NameToUri_FullName(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.SetNameToUriType(ghttp.UriTypeFullName)
s.BindObject("/{.struct}/{.method}", new(NamesObject))
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -37,7 +35,7 @@ func Test_NameToUri_FullName(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
client.SetBrowserMode(true)
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/NamesObject"), "Not Found")
t.Assert(client.GetContent(ctx, "/NamesObject/ShowName"), "Object Show Name")
@@ -45,11 +43,9 @@ func Test_NameToUri_FullName(t *testing.T) {
}
func Test_NameToUri_AllLower(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.SetNameToUriType(ghttp.UriTypeAllLower)
s.BindObject("/{.struct}/{.method}", new(NamesObject))
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -58,7 +54,7 @@ func Test_NameToUri_AllLower(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
client.SetBrowserMode(true)
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/NamesObject"), "Not Found")
t.Assert(client.GetContent(ctx, "/namesobject/showname"), "Object Show Name")
@@ -66,11 +62,9 @@ func Test_NameToUri_AllLower(t *testing.T) {
}
func Test_NameToUri_Camel(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.SetNameToUriType(ghttp.UriTypeCamel)
s.BindObject("/{.struct}/{.method}", new(NamesObject))
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -79,7 +73,7 @@ func Test_NameToUri_Camel(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
client.SetBrowserMode(true)
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/NamesObject"), "Not Found")
t.Assert(client.GetContent(ctx, "/namesObject/showName"), "Object Show Name")
@@ -87,11 +81,9 @@ func Test_NameToUri_Camel(t *testing.T) {
}
func Test_NameToUri_Default(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.SetNameToUriType(ghttp.UriTypeDefault)
s.BindObject("/{.struct}/{.method}", new(NamesObject))
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -100,7 +92,7 @@ func Test_NameToUri_Default(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
client.SetBrowserMode(true)
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/NamesObject"), "Not Found")
t.Assert(client.GetContent(ctx, "/names-object/show-name"), "Object Show Name")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_object_rest1_test.go b/net/ghttp/ghttp_z_unit_feature_router_object_rest1_test.go
index 55e062367..840ddbb94 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_object_rest1_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_object_rest1_test.go
@@ -13,8 +13,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
type ObjectRest struct{}
@@ -56,11 +56,9 @@ func (o *ObjectRest) Head(r *ghttp.Request) {
}
func Test_Router_ObjectRest(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindObjectRest("/", new(ObjectRest))
s.BindObjectRest("/{.struct}/{.method}", new(ObjectRest))
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -68,7 +66,7 @@ func Test_Router_ObjectRest(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "1Object Get2")
t.Assert(client.PutContent(ctx, "/"), "1Object Put2")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_object_rest2_test.go b/net/ghttp/ghttp_z_unit_feature_router_object_rest2_test.go
index 8cc502d56..ed6bfdbcd 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_object_rest2_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_object_rest2_test.go
@@ -13,8 +13,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
type ObjectRest2 struct{}
@@ -44,10 +44,8 @@ func (o *ObjectRest2) Delete(r *ghttp.Request) {
}
func Test_Router_ObjectRest_Id(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindObjectRest("/object/:id", new(ObjectRest2))
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -55,7 +53,7 @@ func Test_Router_ObjectRest_Id(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/object/99"), "1Object Get992")
t.Assert(client.PutContent(ctx, "/object/99"), "1Object Put992")
diff --git a/net/ghttp/ghttp_z_unit_feature_router_object_test.go b/net/ghttp/ghttp_z_unit_feature_router_object_test.go
index 3cc13293b..932712832 100644
--- a/net/ghttp/ghttp_z_unit_feature_router_object_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_router_object_test.go
@@ -13,8 +13,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
type Object struct{}
@@ -40,11 +40,9 @@ func (o *Object) Info(r *ghttp.Request) {
}
func Test_Router_Object1(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindObject("/", new(Object))
s.BindObject("/{.struct}/{.method}", new(Object))
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -52,7 +50,7 @@ func Test_Router_Object1(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "1Object Index2")
t.Assert(client.GetContent(ctx, "/init"), "Not Found")
@@ -71,10 +69,8 @@ func Test_Router_Object1(t *testing.T) {
}
func Test_Router_Object2(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindObject("/object", new(Object), "Show, Info")
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -82,7 +78,7 @@ func Test_Router_Object2(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
@@ -97,10 +93,8 @@ func Test_Router_Object2(t *testing.T) {
}
func Test_Router_ObjectMethod(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindObjectMethod("/object-info", new(Object), "Info")
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -108,7 +102,7 @@ func Test_Router_ObjectMethod(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Not Found")
t.Assert(client.GetContent(ctx, "/object"), "Not Found")
diff --git a/net/ghttp/ghttp_z_unit_feature_server_util_test.go b/net/ghttp/ghttp_z_unit_feature_server_util_test.go
index 34165d879..75cfcf125 100644
--- a/net/ghttp/ghttp_z_unit_feature_server_util_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_server_util_test.go
@@ -14,8 +14,8 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
- "github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
type testWrapStdHTTPStruct struct {
@@ -31,8 +31,7 @@ func (t *testWrapStdHTTPStruct) ServeHTTP(w http.ResponseWriter, req *http.Reque
}
func Test_Server_Wrap_Handler(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
str1 := "hello"
str2 := "hello again"
s.Group("/api", func(group *ghttp.RouterGroup) {
@@ -46,14 +45,13 @@ func Test_Server_Wrap_Handler(t *testing.T) {
group.POST("/wraph", ghttp.WrapH(&testWrapStdHTTPStruct{t, str2}))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d/api", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d/api", s.GetListenedPort()))
response, er1 := client.Get(ctx, "/wrapf")
defer response.Close()
diff --git a/net/ghttp/ghttp_z_unit_feature_session_test.go b/net/ghttp/ghttp_z_unit_feature_session_test.go
index 9dbd6879b..59fe356dc 100644
--- a/net/ghttp/ghttp_z_unit_feature_session_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_session_test.go
@@ -15,11 +15,11 @@ import (
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/net/gtcp"
"github.com/gogf/gf/v2/test/gtest"
+ "github.com/gogf/gf/v2/util/guid"
)
func Test_Session_Cookie(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/set", func(r *ghttp.Request) {
r.Session.Set(r.Get("k").String(), r.Get("v").String())
})
@@ -32,7 +32,6 @@ func Test_Session_Cookie(t *testing.T) {
s.BindHandler("/clear", func(r *ghttp.Request) {
r.Session.RemoveAll()
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -41,7 +40,7 @@ func Test_Session_Cookie(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
client.SetBrowserMode(true)
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
r1, e1 := client.Get(ctx, "/set?k=key1&v=100")
if r1 != nil {
defer r1.Close()
@@ -65,8 +64,7 @@ func Test_Session_Cookie(t *testing.T) {
}
func Test_Session_Header(t *testing.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/set", func(r *ghttp.Request) {
r.Session.Set(r.Get("k").String(), r.Get("v").String())
})
@@ -79,7 +77,6 @@ func Test_Session_Header(t *testing.T) {
s.BindHandler("/clear", func(r *ghttp.Request) {
r.Session.RemoveAll()
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -87,7 +84,7 @@ func Test_Session_Header(t *testing.T) {
time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
response, e1 := client.Get(ctx, "/set?k=key1&v=100")
if response != nil {
defer response.Close()
@@ -116,8 +113,7 @@ func Test_Session_Header(t *testing.T) {
func Test_Session_StorageFile(t *testing.T) {
sessionId := ""
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.BindHandler("/set", func(r *ghttp.Request) {
r.Session.Set(r.Get("k").String(), r.Get("v").String())
r.Response.Write(r.Get("k").String(), "=", r.Get("v").String())
@@ -125,7 +121,6 @@ func Test_Session_StorageFile(t *testing.T) {
s.BindHandler("/get", func(r *ghttp.Request) {
r.Response.Write(r.Session.Get(r.Get("k").String()))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -134,7 +129,7 @@ func Test_Session_StorageFile(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
response, e1 := client.Get(ctx, "/set?k=key&v=100")
if response != nil {
defer response.Close()
@@ -147,7 +142,7 @@ func Test_Session_StorageFile(t *testing.T) {
time.Sleep(time.Second)
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader(s.GetSessionIdName(), sessionId)
t.Assert(client.GetContent(ctx, "/get?k=key"), "100")
t.Assert(client.GetContent(ctx, "/get?k=key1"), "")
@@ -174,7 +169,6 @@ func Test_Session_Custom_Id(t *testing.T) {
s.BindHandler("/value", func(r *ghttp.Request) {
r.Response.WriteExit(r.Session.Get(key))
})
- s.SetPort(p)
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
@@ -183,7 +177,7 @@ func Test_Session_Custom_Id(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
r, err := client.Get(ctx, "/id")
t.Assert(err, nil)
defer r.Close()
@@ -192,7 +186,7 @@ func Test_Session_Custom_Id(t *testing.T) {
})
gtest.C(t, func(t *gtest.T) {
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader(s.GetSessionIdName(), sessionId)
t.Assert(client.GetContent(ctx, "/value"), value)
})
diff --git a/net/ghttp/ghttp_z_unit_feature_static_test.go b/net/ghttp/ghttp_z_unit_feature_static_test.go
index 0d009c78d..da5e5df90 100644
--- a/net/ghttp/ghttp_z_unit_feature_static_test.go
+++ b/net/ghttp/ghttp_z_unit_feature_static_test.go
@@ -15,27 +15,25 @@ import (
"github.com/gogf/gf/v2/debug/gdebug"
"github.com/gogf/gf/v2/frame/g"
- "github.com/gogf/gf/v2/net/gtcp"
"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"
)
func Test_Static_ServerRoot(t *testing.T) {
// SetServerRoot with absolute path
gtest.C(t, func(t *gtest.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
- path := fmt.Sprintf(`%s/ghttp/static/test/%d`, gfile.Temp(), p)
+ s := g.Server(guid.S())
+ path := fmt.Sprintf(`%s/ghttp/static/test/%d`, gfile.Temp(), s.GetListenedPort())
defer gfile.Remove(path)
gfile.PutContents(path+"/index.htm", "index")
s.SetServerRoot(path)
- s.SetPort(p)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "index")
t.Assert(client.GetContent(ctx, "/index.htm"), "index")
@@ -43,18 +41,16 @@ func Test_Static_ServerRoot(t *testing.T) {
// SetServerRoot with relative path
gtest.C(t, func(t *gtest.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
- path := fmt.Sprintf(`static/test/%d`, p)
+ s := g.Server(guid.S())
+ path := fmt.Sprintf(`static/test/%d`, s.GetListenedPort())
defer gfile.Remove(path)
gfile.PutContents(path+"/index.htm", "index")
s.SetServerRoot(path)
- s.SetPort(p)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "index")
t.Assert(client.GetContent(ctx, "/index.htm"), "index")
@@ -63,15 +59,13 @@ func Test_Static_ServerRoot(t *testing.T) {
func Test_Static_ServerRoot_Security(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
+ s := g.Server(guid.S())
s.SetServerRoot(gdebug.TestDataPath("static1"))
- s.SetPort(p)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "index")
t.Assert(client.GetContent(ctx, "/index.htm"), "Not Found")
@@ -84,18 +78,16 @@ func Test_Static_ServerRoot_Security(t *testing.T) {
func Test_Static_Folder_Forbidden(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
- path := fmt.Sprintf(`%s/ghttp/static/test/%d`, gfile.Temp(), p)
+ s := g.Server(guid.S())
+ path := fmt.Sprintf(`%s/ghttp/static/test/%d`, gfile.Temp(), s.GetListenedPort())
defer gfile.Remove(path)
gfile.PutContents(path+"/test.html", "test")
s.SetServerRoot(path)
- s.SetPort(p)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(client.GetContent(ctx, "/"), "Forbidden")
t.Assert(client.GetContent(ctx, "/index.html"), "Not Found")
@@ -105,19 +97,17 @@ func Test_Static_Folder_Forbidden(t *testing.T) {
func Test_Static_IndexFolder(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
- p, _ := gtcp.GetFreePort()
- s := g.Server(p)
- path := fmt.Sprintf(`%s/ghttp/static/test/%d`, gfile.Temp(), p)
+ s := g.Server(guid.S())
+ path := fmt.Sprintf(`%s/ghttp/static/test/%d`, gfile.Temp(), s.GetListenedPort())
defer gfile.Remove(path)
gfile.PutContents(path+"/test.html", "test")
s.SetIndexFolder(true)
s.SetServerRoot(path)
- s.SetPort(p)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
client := g.Client()
- client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
+ client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.AssertNE(client.GetContent(ctx, "/"), "Forbidden")
t.AssertNE(gstr.Pos(client.GetContent(ctx, "/"), `{{.header}}
+{{end}}
\ No newline at end of file
diff --git a/net/ghttp/testdata/issue1611/index/layout.html b/net/ghttp/testdata/issue1611/index/layout.html
new file mode 100644
index 000000000..82e831ceb
--- /dev/null
+++ b/net/ghttp/testdata/issue1611/index/layout.html
@@ -0,0 +1,9 @@
+
+
+
+ GoFrame Layout
+
+
+{{template "header" .}}
+
+
\ No newline at end of file
diff --git a/net/gtcp/gtcp_func.go b/net/gtcp/gtcp_func.go
index adbeab966..78848cea8 100644
--- a/net/gtcp/gtcp_func.go
+++ b/net/gtcp/gtcp_func.go
@@ -196,7 +196,7 @@ func GetFreePort() (port int, err error) {
)
}
port = l.Addr().(*net.TCPAddr).Port
- _ = l.Close()
+ err = l.Close()
return
}
diff --git a/os/gcfg/gcfg_adapter_file.go b/os/gcfg/gcfg_adapter_file.go
index 3c70bf588..80ea4c4c7 100644
--- a/os/gcfg/gcfg_adapter_file.go
+++ b/os/gcfg/gcfg_adapter_file.go
@@ -47,7 +47,7 @@ var (
}
// Prefix array for trying searching in local system.
- localSystemTryFolders = []string{"", "hack/", "config/", "manifest/config"}
+ localSystemTryFolders = []string{"", "config/", "manifest/config"}
)
// NewAdapterFile returns a new configuration management object.
diff --git a/os/gview/gview_parse.go b/os/gview/gview_parse.go
index 943d9c232..b83096349 100644
--- a/os/gview/gview_parse.go
+++ b/os/gview/gview_parse.go
@@ -364,7 +364,7 @@ func (view *View) searchFile(ctx context.Context, file string) (path string, fol
`\/`,
)
if path, _ = gspath.Search(searchPath, relativePath); path != "" {
- folder = gfile.Dir(path)
+ folder = gfile.Join(searchPath, tryFolder)
return
}
}
diff --git a/test/gtest/gtest_util.go b/test/gtest/gtest_util.go
index d8fa33d1d..6ecb4bd9a 100644
--- a/test/gtest/gtest_util.go
+++ b/test/gtest/gtest_util.go
@@ -29,7 +29,7 @@ const (
func C(t *testing.T, f func(t *T)) {
defer func() {
if err := recover(); err != nil {
- fmt.Fprintf(os.Stderr, "%v\n%s", err, gdebug.StackWithFilter([]string{pathFilterKey}))
+ _, _ = fmt.Fprintf(os.Stderr, "%v\n%s", err, gdebug.StackWithFilter([]string{pathFilterKey}))
t.Fail()
}
}()
diff --git a/util/gconv/gconv_struct.go b/util/gconv/gconv_struct.go
index aaddf01be..628baf3c5 100644
--- a/util/gconv/gconv_struct.go
+++ b/util/gconv/gconv_struct.go
@@ -453,51 +453,84 @@ func bindVarToReflectValue(structFieldValue reflect.Value, value interface{}, ma
// Note that the slice element might be type of struct,
// so it uses Struct function doing the converting internally.
case reflect.Slice, reflect.Array:
- a := reflect.Value{}
- v := reflect.ValueOf(value)
- if v.Kind() == reflect.Slice || v.Kind() == reflect.Array {
- a = reflect.MakeSlice(structFieldValue.Type(), v.Len(), v.Len())
- if v.Len() > 0 {
- t := a.Index(0).Type()
- for i := 0; i < v.Len(); i++ {
- if t.Kind() == reflect.Ptr {
- e := reflect.New(t.Elem()).Elem()
- if err = doStruct(v.Index(i).Interface(), e, nil, ""); err != nil {
- // Note there's reflect conversion mechanism here.
- e.Set(reflect.ValueOf(v.Index(i).Interface()).Convert(t))
- }
- a.Index(i).Set(e.Addr())
- } else {
- e := reflect.New(t).Elem()
- if err = doStruct(v.Index(i).Interface(), e, nil, ""); err != nil {
- // Note there's reflect conversion mechanism here.
- e.Set(reflect.ValueOf(v.Index(i).Interface()).Convert(t))
- }
- a.Index(i).Set(e)
+ var (
+ reflectArray reflect.Value
+ reflectValue = reflect.ValueOf(value)
+ )
+ if reflectValue.Kind() == reflect.Slice || reflectValue.Kind() == reflect.Array {
+ reflectArray = reflect.MakeSlice(structFieldValue.Type(), reflectValue.Len(), reflectValue.Len())
+ if reflectValue.Len() > 0 {
+ var (
+ elemType = reflectArray.Index(0).Type()
+ elemTypeName string
+ converted bool
+ )
+ for i := 0; i < reflectValue.Len(); i++ {
+ converted = false
+ elemTypeName = elemType.Name()
+ if elemTypeName == "" {
+ elemTypeName = elemType.String()
}
+ var elem reflect.Value
+ if elemType.Kind() == reflect.Ptr {
+ elem = reflect.New(elemType.Elem()).Elem()
+ } else {
+ elem = reflect.New(elemType).Elem()
+ }
+ if elem.Kind() == reflect.Struct {
+ if err = doStruct(reflectValue.Index(i).Interface(), elem, nil, ""); err == nil {
+ converted = true
+ }
+ }
+ if !converted {
+ elem.Set(reflect.ValueOf(doConvert(doConvertInput{
+ FromValue: reflectValue.Index(i).Interface(),
+ ToTypeName: elemTypeName,
+ ReferValue: elem,
+ })))
+ }
+ if elemType.Kind() == reflect.Ptr {
+ // Before it sets the `elem` to array, do pointer converting if necessary.
+ elem = elem.Addr()
+ }
+ reflectArray.Index(i).Set(elem)
}
}
} else {
- a = reflect.MakeSlice(structFieldValue.Type(), 1, 1)
- t := a.Index(0).Type()
- if t.Kind() == reflect.Ptr {
- // Pointer element.
- e := reflect.New(t.Elem()).Elem()
- if err = doStruct(value, e, nil, ""); err != nil {
- // Note there's reflect conversion mechanism here.
- e.Set(reflect.ValueOf(value).Convert(t))
- }
- a.Index(0).Set(e.Addr())
- } else {
- // Just consider it as struct element. (Although it might be other types but not basic types, eg: map)
- e := reflect.New(t).Elem()
- if err = doStruct(value, e, nil, ""); err != nil {
- return err
- }
- a.Index(0).Set(e)
+ reflectArray = reflect.MakeSlice(structFieldValue.Type(), 1, 1)
+ var (
+ elem reflect.Value
+ elemType = reflectArray.Index(0).Type()
+ elemTypeName = elemType.Name()
+ converted bool
+ )
+ if elemTypeName == "" {
+ elemTypeName = elemType.String()
}
+ if elemType.Kind() == reflect.Ptr {
+ elem = reflect.New(elemType.Elem()).Elem()
+ } else {
+ elem = reflect.New(elemType).Elem()
+ }
+ if elem.Kind() == reflect.Struct {
+ if err = doStruct(value, elem, nil, ""); err == nil {
+ converted = true
+ }
+ }
+ if !converted {
+ elem.Set(reflect.ValueOf(doConvert(doConvertInput{
+ FromValue: value,
+ ToTypeName: elemTypeName,
+ ReferValue: elem,
+ })))
+ }
+ if elemType.Kind() == reflect.Ptr {
+ // Before it sets the `elem` to array, do pointer converting if necessary.
+ elem = elem.Addr()
+ }
+ reflectArray.Index(0).Set(elem)
}
- structFieldValue.Set(a)
+ structFieldValue.Set(reflectArray)
case reflect.Ptr:
item := reflect.New(structFieldValue.Type().Elem())
diff --git a/util/gconv/gconv_z_unit_all_test.go b/util/gconv/gconv_z_unit_all_test.go
index d42351889..6868e5d95 100644
--- a/util/gconv/gconv_z_unit_all_test.go
+++ b/util/gconv/gconv_z_unit_all_test.go
@@ -36,6 +36,103 @@ func (s1 S1) Error() string {
return "22222"
}
+// https://github.com/gogf/gf/issues/1227
+func Test_Issue1227(t *testing.T) {
+ gtest.C(t, func(t *gtest.T) {
+ type StructFromIssue1227 struct {
+ Name string `json:"n1"`
+ }
+ tests := []struct {
+ name string
+ origin interface{}
+ want string
+ }{
+ {
+ name: "Case1",
+ origin: `{"n1":"n1"}`,
+ want: "n1",
+ },
+ {
+ name: "Case2",
+ origin: `{"name":"name"}`,
+ want: "",
+ },
+ {
+ name: "Case3",
+ origin: `{"NaMe":"NaMe"}`,
+ want: "",
+ },
+ {
+ name: "Case4",
+ origin: g.Map{"n1": "n1"},
+ want: "n1",
+ },
+ {
+ name: "Case5",
+ origin: g.Map{"NaMe": "n1"},
+ want: "n1",
+ },
+ }
+ for _, tt := range tests {
+ p := StructFromIssue1227{}
+ if err := gconv.Struct(tt.origin, &p); err != nil {
+ t.Error(err)
+ }
+ t.Assert(p.Name, tt.want)
+ }
+ })
+
+ // Chinese key.
+ gtest.C(t, func(t *gtest.T) {
+ type StructFromIssue1227 struct {
+ Name string `json:"中文Key"`
+ }
+ tests := []struct {
+ name string
+ origin interface{}
+ want string
+ }{
+ {
+ name: "Case1",
+ origin: `{"中文Key":"n1"}`,
+ want: "n1",
+ },
+ {
+ name: "Case2",
+ origin: `{"Key":"name"}`,
+ want: "",
+ },
+ {
+ name: "Case3",
+ origin: `{"NaMe":"NaMe"}`,
+ want: "",
+ },
+ {
+ name: "Case4",
+ origin: g.Map{"中文Key": "n1"},
+ want: "n1",
+ },
+ {
+ name: "Case5",
+ origin: g.Map{"中文KEY": "n1"},
+ want: "n1",
+ },
+ {
+ name: "Case5",
+ origin: g.Map{"KEY": "n1"},
+ want: "",
+ },
+ }
+ for _, tt := range tests {
+ p := StructFromIssue1227{}
+ if err := gconv.Struct(tt.origin, &p); err != nil {
+ t.Error(err)
+ }
+ t.Assert(p.Name, tt.want)
+ }
+ })
+}
+
func Test_Bool_All(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
var any interface{} = nil
diff --git a/util/gconv/gconv_z_unit_struct_test.go b/util/gconv/gconv_z_unit_struct_test.go
index c91a66468..50b4a17f2 100644
--- a/util/gconv/gconv_z_unit_struct_test.go
+++ b/util/gconv/gconv_z_unit_struct_test.go
@@ -356,7 +356,7 @@ func Test_Struct_Attr_CustomType2(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
user := new(User)
err := gconv.Struct(g.Map{"id": g.Slice{1, 2}, "name": "john"}, user)
- t.Assert(err, nil)
+ t.AssertNil(err)
t.Assert(user.Id, g.Slice{1, 2})
t.Assert(user.Name, "john")
})
@@ -1301,3 +1301,22 @@ func Test_Struct_Issue1597(t *testing.T) {
t.Assert(s.B, `{"c":3}`)
})
}
+
+func Test_Scan_WithDoubleSliceAttribute(t *testing.T) {
+ inputData := [][]string{
+ {"aa", "bb", "cc"},
+ {"11", "22", "33"},
+ }
+ data := struct {
+ Data [][]string
+ }{
+ Data: inputData,
+ }
+ gtest.C(t, func(t *gtest.T) {
+ jv := gjson.New(gjson.MustEncodeString(data))
+ err := jv.Scan(&data)
+ t.AssertNil(err)
+ t.Assert(data.Data, inputData)
+ })
+
+}