mirror of
https://gitee.com/johng/gf
synced 2026-06-10 11:27:17 +08:00
Compare commits
15 Commits
contrib/dr
...
v2.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
| e0e00434cc | |||
| b95cb3180d | |||
| dec66dbd05 | |||
| cb44c40a9c | |||
| 2c22f4e17d | |||
| 83fa3593b1 | |||
| 4ad508c04d | |||
| 0d52386236 | |||
| 16a5318d32 | |||
| b1da02dff6 | |||
| b99db92113 | |||
| c0dff1dc16 | |||
| ef6ef506d6 | |||
| b71ac868b7 | |||
| d72997da04 |
@ -3,13 +3,13 @@ module github.com/gogf/gf/cmd/gf/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.1
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
github.com/minio/selfupdate v0.6.0
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
golang.org/x/mod v0.9.0
|
||||
|
||||
@ -179,7 +179,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gbase64"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gbuild"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/genv"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
@ -311,8 +312,9 @@ func (c cBuild) getBuildInVarStr(ctx context.Context, in cBuildInput) string {
|
||||
if buildInVarMap == nil {
|
||||
buildInVarMap = make(g.Map)
|
||||
}
|
||||
buildInVarMap["builtGit"] = c.getGitCommit(ctx)
|
||||
buildInVarMap["builtTime"] = gtime.Now().String()
|
||||
buildInVarMap[gbuild.BuiltGit] = c.getGitCommit(ctx)
|
||||
buildInVarMap[gbuild.BuiltTime] = gtime.Now().String()
|
||||
buildInVarMap[gbuild.BuiltVersion] = in.Version
|
||||
b, err := json.Marshal(buildInVarMap)
|
||||
if err != nil {
|
||||
mlog.Fatal(err)
|
||||
|
||||
@ -32,9 +32,12 @@ func (c *controllerGenerator) Generate(dstModuleFolderPath string, apiModuleApiI
|
||||
continue
|
||||
}
|
||||
// retrieve all api items of the same module.
|
||||
subItems := c.getSubItemsByModuleAndVersion(apiModuleApiItems, item.Module, item.Version)
|
||||
var (
|
||||
subItems = c.getSubItemsByModuleAndVersion(apiModuleApiItems, item.Module, item.Version)
|
||||
importPath = gstr.Replace(gfile.Dir(item.Import), "\\", "/", -1)
|
||||
)
|
||||
if err = c.doGenerateCtrlNewByModuleAndVersion(
|
||||
dstModuleFolderPath, item.Module, item.Version, gfile.Dir(item.Import),
|
||||
dstModuleFolderPath, item.Module, item.Version, importPath,
|
||||
); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ func (c *apiSdkGenerator) doGenerateSdkIClient(
|
||||
pkgName = gfile.Basename(sdkFolderPath)
|
||||
funcName = gstr.CaseCamel(module) + gstr.UcFirst(version)
|
||||
interfaceName = fmt.Sprintf(`I%s`, funcName)
|
||||
moduleImportPath = fmt.Sprintf(`"%s"`, gfile.Dir(versionImportPath))
|
||||
moduleImportPath = gstr.Replace(fmt.Sprintf(`"%s"`, gfile.Dir(versionImportPath)), "\\", "/", -1)
|
||||
iClientFilePath = gfile.Join(sdkFolderPath, fmt.Sprintf(`%s.iclient.go`, pkgName))
|
||||
interfaceFuncDefinition = fmt.Sprintf(
|
||||
`%s() %s.%s`,
|
||||
@ -142,7 +142,7 @@ func (c *apiSdkGenerator) doGenerateSdkImplementer(
|
||||
pkgName = gfile.Basename(sdkFolderPath)
|
||||
moduleNameCamel = gstr.CaseCamel(module)
|
||||
moduleNameSnake = gstr.CaseSnake(module)
|
||||
moduleImportPath = gfile.Dir(versionImportPath)
|
||||
moduleImportPath = gstr.Replace(gfile.Dir(versionImportPath), "\\", "/", -1)
|
||||
versionPrefix = ""
|
||||
implementerName = moduleNameCamel + gstr.UcFirst(version)
|
||||
implementerFilePath = gfile.Join(sdkFolderPath, fmt.Sprintf(
|
||||
|
||||
@ -7,6 +7,10 @@
|
||||
package consts
|
||||
|
||||
const TemplateGenCtrlControllerEmpty = `
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package {Module}
|
||||
|
||||
`
|
||||
|
||||
@ -25,7 +25,7 @@ type implementer struct {
|
||||
config httpclient.Config
|
||||
}
|
||||
|
||||
func New(config httpclient.Config) iClient {
|
||||
func New(config httpclient.Config) IClient {
|
||||
if !gstr.HasPrefix(config.URL, "http") {
|
||||
config.URL = fmt.Sprintf("http://%s", config.URL)
|
||||
}
|
||||
@ -49,7 +49,7 @@ package {PkgName}
|
||||
import (
|
||||
)
|
||||
|
||||
type iClient interface {
|
||||
type IClient interface {
|
||||
}
|
||||
`
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -13,6 +13,7 @@ import (
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// AnyAnyMap wraps map type `map[interface{}]interface{}` and provides more map features.
|
||||
@ -535,3 +536,28 @@ func (m *AnyAnyMap) IsSubOf(other *AnyAnyMap) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Diff compares current map `m` with map `other` and returns their different keys.
|
||||
// The returned `addedKeys` are the keys that are in map `m` but not in map `other`.
|
||||
// The returned `removedKeys` are the keys that are in map `other` but not in map `m`.
|
||||
// The returned `updatedKeys` are the keys that are both in map `m` and `other` but their values and not equal (`!=`).
|
||||
func (m *AnyAnyMap) Diff(other *AnyAnyMap) (addedKeys, removedKeys, updatedKeys []interface{}) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
other.mu.RLock()
|
||||
defer other.mu.RUnlock()
|
||||
|
||||
for key := range m.data {
|
||||
if _, ok := other.data[key]; !ok {
|
||||
removedKeys = append(removedKeys, key)
|
||||
} else if !reflect.DeepEqual(m.data[key], other.data[key]) {
|
||||
updatedKeys = append(updatedKeys, key)
|
||||
}
|
||||
}
|
||||
for key := range other.data {
|
||||
if _, ok := m.data[key]; !ok {
|
||||
addedKeys = append(addedKeys, key)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// IntAnyMap implements map[int]interface{} with RWMutex that has switch.
|
||||
@ -536,3 +537,28 @@ func (m *IntAnyMap) IsSubOf(other *IntAnyMap) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Diff compares current map `m` with map `other` and returns their different keys.
|
||||
// The returned `addedKeys` are the keys that are in map `m` but not in map `other`.
|
||||
// The returned `removedKeys` are the keys that are in map `other` but not in map `m`.
|
||||
// The returned `updatedKeys` are the keys that are both in map `m` and `other` but their values and not equal (`!=`).
|
||||
func (m *IntAnyMap) Diff(other *IntAnyMap) (addedKeys, removedKeys, updatedKeys []int) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
other.mu.RLock()
|
||||
defer other.mu.RUnlock()
|
||||
|
||||
for key := range m.data {
|
||||
if _, ok := other.data[key]; !ok {
|
||||
removedKeys = append(removedKeys, key)
|
||||
} else if !reflect.DeepEqual(m.data[key], other.data[key]) {
|
||||
updatedKeys = append(updatedKeys, key)
|
||||
}
|
||||
}
|
||||
for key := range other.data {
|
||||
if _, ok := m.data[key]; !ok {
|
||||
addedKeys = append(addedKeys, key)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -506,3 +506,28 @@ func (m *IntIntMap) IsSubOf(other *IntIntMap) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Diff compares current map `m` with map `other` and returns their different keys.
|
||||
// The returned `addedKeys` are the keys that are in map `m` but not in map `other`.
|
||||
// The returned `removedKeys` are the keys that are in map `other` but not in map `m`.
|
||||
// The returned `updatedKeys` are the keys that are both in map `m` and `other` but their values and not equal (`!=`).
|
||||
func (m *IntIntMap) Diff(other *IntIntMap) (addedKeys, removedKeys, updatedKeys []int) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
other.mu.RLock()
|
||||
defer other.mu.RUnlock()
|
||||
|
||||
for key := range m.data {
|
||||
if _, ok := other.data[key]; !ok {
|
||||
removedKeys = append(removedKeys, key)
|
||||
} else if m.data[key] != other.data[key] {
|
||||
updatedKeys = append(updatedKeys, key)
|
||||
}
|
||||
}
|
||||
for key := range other.data {
|
||||
if _, ok := m.data[key]; !ok {
|
||||
addedKeys = append(addedKeys, key)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -506,3 +506,28 @@ func (m *IntStrMap) IsSubOf(other *IntStrMap) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Diff compares current map `m` with map `other` and returns their different keys.
|
||||
// The returned `addedKeys` are the keys that are in map `m` but not in map `other`.
|
||||
// The returned `removedKeys` are the keys that are in map `other` but not in map `m`.
|
||||
// The returned `updatedKeys` are the keys that are both in map `m` and `other` but their values and not equal (`!=`).
|
||||
func (m *IntStrMap) Diff(other *IntStrMap) (addedKeys, removedKeys, updatedKeys []int) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
other.mu.RLock()
|
||||
defer other.mu.RUnlock()
|
||||
|
||||
for key := range m.data {
|
||||
if _, ok := other.data[key]; !ok {
|
||||
removedKeys = append(removedKeys, key)
|
||||
} else if m.data[key] != other.data[key] {
|
||||
updatedKeys = append(updatedKeys, key)
|
||||
}
|
||||
}
|
||||
for key := range other.data {
|
||||
if _, ok := m.data[key]; !ok {
|
||||
addedKeys = append(addedKeys, key)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/internal/rwmutex"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// StrAnyMap implements map[string]interface{} with RWMutex that has switch.
|
||||
@ -522,3 +523,28 @@ func (m *StrAnyMap) IsSubOf(other *StrAnyMap) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Diff compares current map `m` with map `other` and returns their different keys.
|
||||
// The returned `addedKeys` are the keys that are in map `m` but not in map `other`.
|
||||
// The returned `removedKeys` are the keys that are in map `other` but not in map `m`.
|
||||
// The returned `updatedKeys` are the keys that are both in map `m` and `other` but their values and not equal (`!=`).
|
||||
func (m *StrAnyMap) Diff(other *StrAnyMap) (addedKeys, removedKeys, updatedKeys []string) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
other.mu.RLock()
|
||||
defer other.mu.RUnlock()
|
||||
|
||||
for key := range m.data {
|
||||
if _, ok := other.data[key]; !ok {
|
||||
removedKeys = append(removedKeys, key)
|
||||
} else if !reflect.DeepEqual(m.data[key], other.data[key]) {
|
||||
updatedKeys = append(updatedKeys, key)
|
||||
}
|
||||
}
|
||||
for key := range other.data {
|
||||
if _, ok := m.data[key]; !ok {
|
||||
addedKeys = append(addedKeys, key)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -510,3 +510,28 @@ func (m *StrIntMap) IsSubOf(other *StrIntMap) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Diff compares current map `m` with map `other` and returns their different keys.
|
||||
// The returned `addedKeys` are the keys that are in map `m` but not in map `other`.
|
||||
// The returned `removedKeys` are the keys that are in map `other` but not in map `m`.
|
||||
// The returned `updatedKeys` are the keys that are both in map `m` and `other` but their values and not equal (`!=`).
|
||||
func (m *StrIntMap) Diff(other *StrIntMap) (addedKeys, removedKeys, updatedKeys []string) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
other.mu.RLock()
|
||||
defer other.mu.RUnlock()
|
||||
|
||||
for key := range m.data {
|
||||
if _, ok := other.data[key]; !ok {
|
||||
removedKeys = append(removedKeys, key)
|
||||
} else if m.data[key] != other.data[key] {
|
||||
updatedKeys = append(updatedKeys, key)
|
||||
}
|
||||
}
|
||||
for key := range other.data {
|
||||
if _, ok := m.data[key]; !ok {
|
||||
addedKeys = append(addedKeys, key)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -499,3 +499,28 @@ func (m *StrStrMap) IsSubOf(other *StrStrMap) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Diff compares current map `m` with map `other` and returns their different keys.
|
||||
// The returned `addedKeys` are the keys that are in map `m` but not in map `other`.
|
||||
// The returned `removedKeys` are the keys that are in map `other` but not in map `m`.
|
||||
// The returned `updatedKeys` are the keys that are both in map `m` and `other` but their values and not equal (`!=`).
|
||||
func (m *StrStrMap) Diff(other *StrStrMap) (addedKeys, removedKeys, updatedKeys []string) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
other.mu.RLock()
|
||||
defer other.mu.RUnlock()
|
||||
|
||||
for key := range m.data {
|
||||
if _, ok := other.data[key]; !ok {
|
||||
removedKeys = append(removedKeys, key)
|
||||
} else if m.data[key] != other.data[key] {
|
||||
updatedKeys = append(updatedKeys, key)
|
||||
}
|
||||
}
|
||||
for key := range other.data {
|
||||
if _, ok := m.data[key]; !ok {
|
||||
addedKeys = append(addedKeys, key)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -406,3 +406,24 @@ func Test_AnyAnyMap_IsSubOf(t *testing.T) {
|
||||
t.Assert(m2.IsSubOf(m2), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_AnyAnyMap_Diff(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m1 := gmap.NewAnyAnyMapFrom(g.MapAnyAny{
|
||||
"0": "v0",
|
||||
"1": "v1",
|
||||
2: "v2",
|
||||
3: 3,
|
||||
})
|
||||
m2 := gmap.NewAnyAnyMapFrom(g.MapAnyAny{
|
||||
"0": "v0",
|
||||
2: "v2",
|
||||
3: "v3",
|
||||
4: "v4",
|
||||
})
|
||||
addedKeys, removedKeys, updatedKeys := m1.Diff(m2)
|
||||
t.Assert(addedKeys, []interface{}{4})
|
||||
t.Assert(removedKeys, []interface{}{"1"})
|
||||
t.Assert(updatedKeys, []interface{}{3})
|
||||
})
|
||||
}
|
||||
|
||||
@ -390,3 +390,24 @@ func Test_IntAnyMap_IsSubOf(t *testing.T) {
|
||||
t.Assert(m2.IsSubOf(m2), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_IntAnyMap_Diff(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m1 := gmap.NewIntAnyMapFrom(g.MapIntAny{
|
||||
0: "v0",
|
||||
1: "v1",
|
||||
2: "v2",
|
||||
3: 3,
|
||||
})
|
||||
m2 := gmap.NewIntAnyMapFrom(g.MapIntAny{
|
||||
0: "v0",
|
||||
2: "v2",
|
||||
3: "v3",
|
||||
4: "v4",
|
||||
})
|
||||
addedKeys, removedKeys, updatedKeys := m1.Diff(m2)
|
||||
t.Assert(addedKeys, []int{4})
|
||||
t.Assert(removedKeys, []int{1})
|
||||
t.Assert(updatedKeys, []int{3})
|
||||
})
|
||||
}
|
||||
|
||||
@ -398,3 +398,24 @@ func Test_IntIntMap_IsSubOf(t *testing.T) {
|
||||
t.Assert(m2.IsSubOf(m2), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_IntIntMap_Diff(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m1 := gmap.NewIntIntMapFrom(g.MapIntInt{
|
||||
0: 0,
|
||||
1: 1,
|
||||
2: 2,
|
||||
3: 3,
|
||||
})
|
||||
m2 := gmap.NewIntIntMapFrom(g.MapIntInt{
|
||||
0: 0,
|
||||
2: 2,
|
||||
3: 31,
|
||||
4: 4,
|
||||
})
|
||||
addedKeys, removedKeys, updatedKeys := m1.Diff(m2)
|
||||
t.Assert(addedKeys, []int{4})
|
||||
t.Assert(removedKeys, []int{1})
|
||||
t.Assert(updatedKeys, []int{3})
|
||||
})
|
||||
}
|
||||
|
||||
@ -462,3 +462,24 @@ func Test_IntStrMap_IsSubOf(t *testing.T) {
|
||||
t.Assert(m2.IsSubOf(m2), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_IntStrMap_Diff(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m1 := gmap.NewIntStrMapFrom(g.MapIntStr{
|
||||
0: "0",
|
||||
1: "1",
|
||||
2: "2",
|
||||
3: "3",
|
||||
})
|
||||
m2 := gmap.NewIntStrMapFrom(g.MapIntStr{
|
||||
0: "0",
|
||||
2: "2",
|
||||
3: "31",
|
||||
4: "4",
|
||||
})
|
||||
addedKeys, removedKeys, updatedKeys := m1.Diff(m2)
|
||||
t.Assert(addedKeys, []int{4})
|
||||
t.Assert(removedKeys, []int{1})
|
||||
t.Assert(updatedKeys, []int{3})
|
||||
})
|
||||
}
|
||||
|
||||
@ -396,3 +396,24 @@ func Test_StrAnyMap_IsSubOf(t *testing.T) {
|
||||
t.Assert(m2.IsSubOf(m2), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_StrAnyMap_Diff(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m1 := gmap.NewStrAnyMapFrom(g.MapStrAny{
|
||||
"0": "v0",
|
||||
"1": "v1",
|
||||
"2": "v2",
|
||||
"3": 3,
|
||||
})
|
||||
m2 := gmap.NewStrAnyMapFrom(g.MapStrAny{
|
||||
"0": "v0",
|
||||
"2": "v2",
|
||||
"3": "v3",
|
||||
"4": "v4",
|
||||
})
|
||||
addedKeys, removedKeys, updatedKeys := m1.Diff(m2)
|
||||
t.Assert(addedKeys, []string{"4"})
|
||||
t.Assert(removedKeys, []string{"1"})
|
||||
t.Assert(updatedKeys, []string{"3"})
|
||||
})
|
||||
}
|
||||
|
||||
@ -404,3 +404,24 @@ func Test_StrIntMap_IsSubOf(t *testing.T) {
|
||||
t.Assert(m2.IsSubOf(m2), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_StrIntMap_Diff(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m1 := gmap.NewStrIntMapFrom(g.MapStrInt{
|
||||
"0": 0,
|
||||
"1": 1,
|
||||
"2": 2,
|
||||
"3": 3,
|
||||
})
|
||||
m2 := gmap.NewStrIntMapFrom(g.MapStrInt{
|
||||
"0": 0,
|
||||
"2": 2,
|
||||
"3": 31,
|
||||
"4": 4,
|
||||
})
|
||||
addedKeys, removedKeys, updatedKeys := m1.Diff(m2)
|
||||
t.Assert(addedKeys, []string{"4"})
|
||||
t.Assert(removedKeys, []string{"1"})
|
||||
t.Assert(updatedKeys, []string{"3"})
|
||||
})
|
||||
}
|
||||
|
||||
@ -403,3 +403,24 @@ func Test_StrStrMap_IsSubOf(t *testing.T) {
|
||||
t.Assert(m2.IsSubOf(m2), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_StrStrMap_Diff(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m1 := gmap.NewStrStrMapFrom(g.MapStrStr{
|
||||
"0": "0",
|
||||
"1": "1",
|
||||
"2": "2",
|
||||
"3": "3",
|
||||
})
|
||||
m2 := gmap.NewStrStrMapFrom(g.MapStrStr{
|
||||
"0": "0",
|
||||
"2": "2",
|
||||
"3": "31",
|
||||
"4": "4",
|
||||
})
|
||||
addedKeys, removedKeys, updatedKeys := m1.Diff(m2)
|
||||
t.Assert(addedKeys, []string{"4"})
|
||||
t.Assert(removedKeys, []string{"1"})
|
||||
t.Assert(updatedKeys, []string{"3"})
|
||||
})
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/apolloconfig/agollo/v4 v4.1.1
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -357,8 +357,8 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/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-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/kubecm/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
k8s.io/api v0.25.2
|
||||
k8s.io/apimachinery v0.25.2
|
||||
k8s.io/client-go v0.25.2
|
||||
|
||||
@ -495,7 +495,6 @@ 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-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/nacos/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
github.com/nacos-group/nacos-sdk-go v1.1.2
|
||||
)
|
||||
|
||||
|
||||
@ -157,7 +157,7 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/polaris/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
github.com/polarismesh/polaris-go v1.5.1
|
||||
)
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.15
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/shopspring/decimal v1.3.1
|
||||
)
|
||||
|
||||
@ -140,6 +140,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -6,5 +6,5 @@ replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
require (
|
||||
gitee.com/chunanyong/dm v1.8.10
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
)
|
||||
|
||||
@ -84,5 +84,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/denisenkom/go-mssqldb v0.11.0
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -85,5 +85,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -7,9 +7,8 @@
|
||||
// Package mssql implements gdb.Driver, which supports operations for database MSSql.
|
||||
//
|
||||
// Note:
|
||||
// 1. It needs manually import: _ "github.com/denisenkom/go-mssqldb"
|
||||
// 2. It does not support Save/Replace features.
|
||||
// 3. It does not support LastInsertId.
|
||||
// 1. It does not support Save/Replace features.
|
||||
// 2. It does not support LastInsertId.
|
||||
package mssql
|
||||
|
||||
import (
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -81,5 +81,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -760,3 +760,40 @@ func Test_Issue2439(t *testing.T) {
|
||||
t.Assert(r[0]["name"], "a")
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/2782
|
||||
func Test_Issue2787(t *testing.T) {
|
||||
table := createTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
m := db.Model("user")
|
||||
|
||||
condWhere, _ := m.Builder().
|
||||
Where("id", "").
|
||||
Where(m.Builder().
|
||||
Where("nickname", "foo").
|
||||
WhereOr("password", "abc123")).
|
||||
Where("passport", "pp").
|
||||
Build()
|
||||
t.Assert(condWhere, "(`id`=?) AND (((`nickname`=?) OR (`password`=?))) AND (`passport`=?)")
|
||||
|
||||
condWhere, _ = m.OmitEmpty().Builder().
|
||||
Where("id", "").
|
||||
Where(m.Builder().
|
||||
Where("nickname", "foo").
|
||||
WhereOr("password", "abc123")).
|
||||
Where("passport", "pp").
|
||||
Build()
|
||||
t.Assert(condWhere, "((`nickname`=?) OR (`password`=?)) AND (`passport`=?)")
|
||||
|
||||
condWhere, _ = m.OmitEmpty().Builder().
|
||||
Where(m.Builder().
|
||||
Where("nickname", "foo").
|
||||
WhereOr("password", "abc123")).
|
||||
Where("id", "").
|
||||
Where("passport", "pp").
|
||||
Build()
|
||||
t.Assert(condWhere, "((`nickname`=?) OR (`password`=?)) AND (`passport`=?)")
|
||||
})
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/oracle/v2
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
github.com/sijms/go-ora/v2 v2.4.20
|
||||
)
|
||||
|
||||
@ -27,7 +27,7 @@ require (
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -80,5 +80,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -7,9 +7,8 @@
|
||||
// Package oracle implements gdb.Driver, which supports operations for database Oracle.
|
||||
//
|
||||
// Note:
|
||||
// 1. It needs manually import: _ "github.com/sijms/go-ora/v2"
|
||||
// 2. It does not support Save/Replace features.
|
||||
// 3. It does not support LastInsertId.
|
||||
// 1. It does not support Save/Replace features.
|
||||
// 2. It does not support LastInsertId.
|
||||
package oracle
|
||||
|
||||
import (
|
||||
@ -19,7 +18,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
gora "github.com/sijms/go-ora/v2"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
@ -28,6 +26,7 @@ import (
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
)
|
||||
|
||||
// Driver is the driver for oracle database.
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/pgsql/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
github.com/lib/pq v1.10.4
|
||||
)
|
||||
|
||||
|
||||
@ -81,5 +81,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -7,8 +7,7 @@
|
||||
// Package pgsql implements gdb.Driver, which supports operations for database PostgreSQL.
|
||||
//
|
||||
// Note:
|
||||
// 1. It needs manually import: _ "github.com/lib/pq"
|
||||
// 2. It does not support Save/Replace features.
|
||||
// 1. It does not support Save/Replace features.
|
||||
package pgsql
|
||||
|
||||
import (
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/glebarez/go-sqlite v1.17.3
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -99,8 +99,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
|
||||
modernc.org/cc/v3 v3.36.0/go.mod h1:NFUHyPn4ekoC/JHeZFfZurN6ixxawE1BnVonP/oahEI=
|
||||
modernc.org/ccgo/v3 v3.0.0-20220428102840-41399a37e894/go.mod h1:eI31LL8EwEBKPpNpA4bU1/i+sKOwOrQy8D87zWUcRZc=
|
||||
|
||||
@ -7,8 +7,7 @@
|
||||
// Package sqlite implements gdb.Driver, which supports operations for database SQLite.
|
||||
//
|
||||
// Note:
|
||||
// 1. It needs manually import: _ "github.com/glebarez/go-sqlite"
|
||||
// 2. It does not support Save/Replace features.
|
||||
// 1. It does not support Save/Replace features.
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
@ -18,6 +17,7 @@ import (
|
||||
"strings"
|
||||
|
||||
_ "github.com/glebarez/go-sqlite"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/encoding/gurl"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
go.opentelemetry.io/otel v1.7.0
|
||||
go.opentelemetry.io/otel/trace v1.7.0
|
||||
)
|
||||
|
||||
@ -162,5 +162,5 @@ 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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -25,12 +25,13 @@ type Redis struct {
|
||||
}
|
||||
|
||||
const (
|
||||
defaultPoolMaxIdle = 10
|
||||
defaultPoolMaxActive = 100
|
||||
defaultPoolIdleTimeout = 10 * time.Second
|
||||
defaultPoolWaitTimeout = 10 * time.Second
|
||||
defaultPoolMaxLifeTime = 30 * time.Second
|
||||
defaultMaxRetries = -1
|
||||
defaultPoolMaxIdle = 10
|
||||
defaultPoolMaxActive = 100
|
||||
defaultPoolIdleTimeout = 10 * time.Second
|
||||
defaultPoolWaitTimeout = 10 * time.Second
|
||||
defaultPoolMaxLifeTime = 30 * time.Second
|
||||
defaultIdleCheckFrequency = 10 * time.Second
|
||||
defaultMaxRetries = -1
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -43,21 +44,22 @@ func init() {
|
||||
func New(config *gredis.Config) *Redis {
|
||||
fillWithDefaultConfiguration(config)
|
||||
opts := &redis.UniversalOptions{
|
||||
Addrs: gstr.SplitAndTrim(config.Address, ","),
|
||||
Username: config.User,
|
||||
Password: config.Pass,
|
||||
DB: config.Db,
|
||||
MaxRetries: defaultMaxRetries,
|
||||
PoolSize: config.MaxActive,
|
||||
MinIdleConns: config.MinIdle,
|
||||
MaxConnAge: config.MaxConnLifetime,
|
||||
IdleTimeout: config.IdleTimeout,
|
||||
PoolTimeout: config.WaitTimeout,
|
||||
DialTimeout: config.DialTimeout,
|
||||
ReadTimeout: config.ReadTimeout,
|
||||
WriteTimeout: config.WriteTimeout,
|
||||
MasterName: config.MasterName,
|
||||
TLSConfig: config.TLSConfig,
|
||||
Addrs: gstr.SplitAndTrim(config.Address, ","),
|
||||
Username: config.User,
|
||||
Password: config.Pass,
|
||||
DB: config.Db,
|
||||
MaxRetries: defaultMaxRetries,
|
||||
PoolSize: config.MaxActive,
|
||||
MinIdleConns: config.MinIdle,
|
||||
MaxConnAge: config.MaxConnLifetime,
|
||||
IdleTimeout: config.IdleTimeout,
|
||||
PoolTimeout: config.WaitTimeout,
|
||||
DialTimeout: config.DialTimeout,
|
||||
ReadTimeout: config.ReadTimeout,
|
||||
WriteTimeout: config.WriteTimeout,
|
||||
IdleCheckFrequency: defaultIdleCheckFrequency,
|
||||
MasterName: config.MasterName,
|
||||
TLSConfig: config.TLSConfig,
|
||||
}
|
||||
|
||||
var client redis.UniversalClient
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/etcd/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
go.etcd.io/etcd/client/v3 v3.5.4
|
||||
)
|
||||
|
||||
|
||||
@ -308,8 +308,9 @@ 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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/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=
|
||||
|
||||
@ -2,6 +2,6 @@ module github.com/gogf/gf/contrib/registry/file/v2
|
||||
|
||||
go 1.15
|
||||
|
||||
require github.com/gogf/gf/v2 v2.5.0
|
||||
require github.com/gogf/gf/v2 v2.5.1
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -79,5 +79,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/polaris/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
github.com/polarismesh/polaris-go v1.5.1
|
||||
)
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]gsvc.Serv
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
serviceInstances := instancesToServiceInstances(instancesResponse.GetInstances())
|
||||
// Service filter.
|
||||
filteredServices := make([]gsvc.Service, 0)
|
||||
@ -78,26 +79,29 @@ func instancesToServiceInstances(instances []model.Instance) []gsvc.Service {
|
||||
serviceInstances = make([]gsvc.Service, 0, len(instances))
|
||||
endpointStr bytes.Buffer
|
||||
)
|
||||
|
||||
for _, instance := range instances {
|
||||
if instance.IsHealthy() {
|
||||
endpointStr.WriteString(fmt.Sprintf("%s:%d%s", instance.GetHost(), instance.GetPort(), gsvc.EndpointsDelimiter))
|
||||
}
|
||||
}
|
||||
|
||||
for _, instance := range instances {
|
||||
if instance.IsHealthy() {
|
||||
serviceInstances = append(serviceInstances, instanceToServiceInstance(instance, gstr.TrimRight(endpointStr.String(), gsvc.EndpointsDelimiter)))
|
||||
if endpointStr.Len() > 0 {
|
||||
for _, instance := range instances {
|
||||
if instance.IsHealthy() {
|
||||
serviceInstances = append(serviceInstances, instanceToServiceInstance(instance, gstr.TrimRight(endpointStr.String(), gsvc.EndpointsDelimiter), ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
return serviceInstances
|
||||
}
|
||||
|
||||
func instanceToServiceInstance(instance model.Instance, endpointStr string) gsvc.Service {
|
||||
// instanceToServiceInstance converts the instance to service instance.
|
||||
// instanceID Must be null when creating and adding, and non-null when updating and deleting
|
||||
func instanceToServiceInstance(instance model.Instance, endpointStr, instanceID string) gsvc.Service {
|
||||
var (
|
||||
s *gsvc.LocalService
|
||||
metadata = instance.GetMetadata()
|
||||
names = strings.Split(instance.GetService(), instanceIDSeparator)
|
||||
// endpoints = gsvc.NewEndpoints(fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort()))
|
||||
s *gsvc.LocalService
|
||||
metadata = instance.GetMetadata()
|
||||
names = strings.Split(instance.GetService(), instanceIDSeparator)
|
||||
endpoints = gsvc.NewEndpoints(endpointStr)
|
||||
)
|
||||
if names != nil && len(names) > 4 {
|
||||
@ -126,9 +130,16 @@ func instanceToServiceInstance(instance model.Instance, endpointStr string) gsvc
|
||||
Endpoints: endpoints,
|
||||
}
|
||||
}
|
||||
return &Service{
|
||||
service := &Service{
|
||||
Service: s,
|
||||
}
|
||||
if instance.GetId() != "" {
|
||||
service.ID = instance.GetId()
|
||||
}
|
||||
if gstr.Trim(instanceID) != "" {
|
||||
service.ID = instanceID
|
||||
}
|
||||
return service
|
||||
}
|
||||
|
||||
// trimAndReplace trims the prefix and suffix separator and replaces the separator in the middle.
|
||||
|
||||
@ -68,10 +68,12 @@ func (w *Watcher) Proceed() ([]gsvc.Service, error) {
|
||||
}
|
||||
// handle DeleteEvent
|
||||
if instanceEvent.DeleteEvent != nil {
|
||||
var endpointStr bytes.Buffer
|
||||
for _, instance := range instanceEvent.DeleteEvent.Instances {
|
||||
// Iterate through existing service instances, deleting them if they exist
|
||||
for i, serviceInstance := range w.ServiceInstances {
|
||||
if serviceInstance.(*Service).ID == instance.GetId() {
|
||||
// remove equal
|
||||
endpointStr.WriteString(fmt.Sprintf("%s:%d%s", instance.GetHost(), instance.GetPort(), gsvc.EndpointsDelimiter))
|
||||
if len(w.ServiceInstances) <= 1 {
|
||||
w.ServiceInstances = w.ServiceInstances[0:0]
|
||||
continue
|
||||
@ -80,32 +82,92 @@ func (w *Watcher) Proceed() ([]gsvc.Service, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if endpointStr.Len() > 0 && len(w.ServiceInstances) > 0 {
|
||||
var (
|
||||
newEndpointStr bytes.Buffer
|
||||
serviceEndpointStr = w.ServiceInstances[0].(*Service).GetEndpoints().String()
|
||||
)
|
||||
for _, address := range gstr.SplitAndTrim(serviceEndpointStr, gsvc.EndpointsDelimiter) {
|
||||
if !gstr.Contains(endpointStr.String(), address) {
|
||||
newEndpointStr.WriteString(fmt.Sprintf("%s%s", address, gsvc.EndpointsDelimiter))
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < len(w.ServiceInstances); i++ {
|
||||
w.ServiceInstances[i] = instanceToServiceInstance(instanceEvent.DeleteEvent.Instances[0], gstr.TrimRight(newEndpointStr.String(), gsvc.EndpointsDelimiter), w.ServiceInstances[i].(*Service).ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
// handle UpdateEvent
|
||||
if instanceEvent.UpdateEvent != nil {
|
||||
for i, serviceInstance := range w.ServiceInstances {
|
||||
var endpointStr bytes.Buffer
|
||||
var (
|
||||
updateEndpointStr bytes.Buffer
|
||||
newEndpointStr bytes.Buffer
|
||||
)
|
||||
for _, serviceInstance := range w.ServiceInstances {
|
||||
// update the current department or all instances
|
||||
for _, update := range instanceEvent.UpdateEvent.UpdateList {
|
||||
if serviceInstance.(*Service).ID == update.Before.GetId() {
|
||||
endpointStr.WriteString(fmt.Sprintf("%s:%d%s", update.After.GetHost(), update.After.GetPort(), gsvc.EndpointsDelimiter))
|
||||
// update equal
|
||||
if update.After.IsHealthy() {
|
||||
newEndpointStr.WriteString(fmt.Sprintf("%s:%d%s", update.After.GetHost(), update.After.GetPort(), gsvc.EndpointsDelimiter))
|
||||
}
|
||||
updateEndpointStr.WriteString(fmt.Sprintf("%s:%d%s", update.Before.GetHost(), update.Before.GetPort(), gsvc.EndpointsDelimiter))
|
||||
}
|
||||
}
|
||||
for _, update := range instanceEvent.UpdateEvent.UpdateList {
|
||||
if serviceInstance.(*Service).ID == update.Before.GetId() {
|
||||
w.ServiceInstances[i] = instanceToServiceInstance(update.After, gstr.TrimRight(endpointStr.String(), gsvc.EndpointsDelimiter))
|
||||
}
|
||||
if len(w.ServiceInstances) > 0 {
|
||||
var serviceEndpointStr = w.ServiceInstances[0].(*Service).GetEndpoints().String()
|
||||
// old instance addresses are culled
|
||||
if updateEndpointStr.Len() > 0 {
|
||||
for _, address := range gstr.SplitAndTrim(serviceEndpointStr, gsvc.EndpointsDelimiter) {
|
||||
// If the historical instance is not in the change instance, it remains
|
||||
if !gstr.Contains(updateEndpointStr.String(), address) {
|
||||
newEndpointStr.WriteString(fmt.Sprintf("%s%s", address, gsvc.EndpointsDelimiter))
|
||||
}
|
||||
}
|
||||
}
|
||||
instance := instanceEvent.UpdateEvent.UpdateList[0].After
|
||||
for i := 0; i < len(w.ServiceInstances); i++ {
|
||||
w.ServiceInstances[i] = instanceToServiceInstance(instance, gstr.TrimRight(newEndpointStr.String(), gsvc.EndpointsDelimiter), w.ServiceInstances[i].(*Service).ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
// handle AddEvent
|
||||
if instanceEvent.AddEvent != nil {
|
||||
w.ServiceInstances = append(
|
||||
w.ServiceInstances,
|
||||
instancesToServiceInstances(instanceEvent.AddEvent.Instances)...,
|
||||
var (
|
||||
newEndpointStr bytes.Buffer
|
||||
allEndpointStr string
|
||||
)
|
||||
if len(w.ServiceInstances) > 0 {
|
||||
allEndpointStr = w.ServiceInstances[0].(*Service).GetEndpoints().String()
|
||||
}
|
||||
for i := 0; i < len(instanceEvent.AddEvent.Instances); i++ {
|
||||
instance := instanceEvent.AddEvent.Instances[i]
|
||||
if instance.IsHealthy() {
|
||||
address := fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort())
|
||||
if !gstr.Contains(allEndpointStr, address) {
|
||||
newEndpointStr.WriteString(fmt.Sprintf("%s%s", address, gsvc.EndpointsDelimiter))
|
||||
}
|
||||
}
|
||||
}
|
||||
if newEndpointStr.Len() > 0 {
|
||||
allEndpointStr = fmt.Sprintf("%s%s", newEndpointStr.String(), allEndpointStr)
|
||||
}
|
||||
for i := 0; i < len(w.ServiceInstances); i++ {
|
||||
w.ServiceInstances[i] = instanceToServiceInstance(instanceEvent.AddEvent.Instances[0], gstr.TrimRight(allEndpointStr, gsvc.EndpointsDelimiter), w.ServiceInstances[i].(*Service).ID)
|
||||
}
|
||||
|
||||
for i := 0; i < len(instanceEvent.AddEvent.Instances); i++ {
|
||||
instance := instanceEvent.AddEvent.Instances[i]
|
||||
if instance.IsHealthy() {
|
||||
w.ServiceInstances = append(w.ServiceInstances, instanceToServiceInstance(instance, gstr.TrimRight(allEndpointStr, gsvc.EndpointsDelimiter), ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return w.ServiceInstances, nil
|
||||
}
|
||||
|
||||
|
||||
@ -19,8 +19,8 @@ import (
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
// TestRegistry TestRegistryManyService
|
||||
func TestRegistry(t *testing.T) {
|
||||
// TestRegistry_Register TestRegistryManyService
|
||||
func TestRegistry_Register(t *testing.T) {
|
||||
conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"})
|
||||
conf.GetGlobal().GetStatReporter().SetEnable(false)
|
||||
conf.Consumer.LocalCache.SetPersistDir(os.TempDir() + "/polaris-registry/backup")
|
||||
@ -35,7 +35,39 @@ func TestRegistry(t *testing.T) {
|
||||
)
|
||||
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-0-tcp",
|
||||
Name: "goframe-provider-register-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
s, err := r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = r.Deregister(context.Background(), s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRegistry_Deregister TestRegistryManyService
|
||||
func TestRegistry_Deregister(t *testing.T) {
|
||||
conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"})
|
||||
conf.GetGlobal().GetStatReporter().SetEnable(false)
|
||||
conf.Consumer.LocalCache.SetPersistDir(os.TempDir() + "/polaris-registry/backup")
|
||||
if err := api.SetLoggersDir(os.TempDir() + "/polaris-registry/log"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := NewWithConfig(
|
||||
conf,
|
||||
WithTimeout(time.Second*10),
|
||||
WithTTL(100),
|
||||
)
|
||||
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-deregister-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
@ -113,8 +145,8 @@ func TestRegistryMany(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetService Test GetService
|
||||
func TestGetService(t *testing.T) {
|
||||
// TestRegistry_Search Test GetService
|
||||
func TestRegistry_Search(t *testing.T) {
|
||||
conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"})
|
||||
conf.GetGlobal().GetStatReporter().SetEnable(false)
|
||||
conf.Consumer.LocalCache.SetPersistDir(os.TempDir() + "/polaris-get-service/backup")
|
||||
@ -158,8 +190,8 @@ func TestGetService(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestWatch Test Watch
|
||||
func TestWatch(t *testing.T) {
|
||||
// TestRegistry_Watch Test Watch
|
||||
func TestRegistry_Watch(t *testing.T) {
|
||||
conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"})
|
||||
conf.GetGlobal().GetStatReporter().SetEnable(false)
|
||||
conf.Consumer.LocalCache.SetPersistDir(os.TempDir() + "/polaris-watch/backup")
|
||||
@ -192,6 +224,7 @@ func TestWatch(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("Register service success svc instance id:", s1.(*Service).ID)
|
||||
// watch svc
|
||||
time.Sleep(time.Second * 1)
|
||||
|
||||
@ -202,7 +235,7 @@ func TestWatch(t *testing.T) {
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output one instance
|
||||
t.Log("Register Proceed service: ", instance)
|
||||
t.Log("Register Proceed service: ", instance.GetEndpoints().String())
|
||||
}
|
||||
|
||||
if err = r.Deregister(context.Background(), s1); err != nil {
|
||||
@ -216,7 +249,7 @@ func TestWatch(t *testing.T) {
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output nothing
|
||||
t.Log("Deregister Proceed service: ", instance)
|
||||
t.Log("Deregister Proceed first delete service: ", instance.GetEndpoints().String(), ", instance id: ", instance.(*Service).ID)
|
||||
}
|
||||
|
||||
if err = watch.Close(); err != nil {
|
||||
@ -226,31 +259,159 @@ func TestWatch(t *testing.T) {
|
||||
// if nil, stop failed
|
||||
t.Fatal()
|
||||
}
|
||||
t.Log("Watch close success")
|
||||
}
|
||||
|
||||
// TestWatcher_Proceed Test Watch
|
||||
func TestWatcher_Proceed(t *testing.T) {
|
||||
conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"})
|
||||
conf.GetGlobal().GetStatReporter().SetEnable(false)
|
||||
conf.Consumer.LocalCache.SetPersistDir(os.TempDir() + "/polaris-watch/backup")
|
||||
if err := api.SetLoggersDir(os.TempDir() + "/polaris-watch/log"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := NewWithConfig(
|
||||
conf,
|
||||
WithTimeout(time.Second*10),
|
||||
WithTTL(100),
|
||||
)
|
||||
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-5-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
s := &Service{
|
||||
Service: svc,
|
||||
}
|
||||
svc1 := &gsvc.LocalService{
|
||||
Name: "goframe-provider-5-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9001"),
|
||||
}
|
||||
|
||||
watch, err := r.Watch(context.Background(), s.GetPrefix())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s1, err := r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("Register service success svc instance id:", s1.(*Service).ID)
|
||||
s22, err := r.Register(context.Background(), svc1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("Register service success svc1 instance id:", s22.(*Service).ID)
|
||||
// watch svc
|
||||
time.Sleep(time.Second * 1)
|
||||
|
||||
// svc register, AddEvent
|
||||
next, err := watch.Proceed()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output one instance
|
||||
t.Log("Register Proceed service: ", instance.GetEndpoints().String())
|
||||
}
|
||||
|
||||
if err = r.Deregister(context.Background(), s1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// svc deregister, DeleteEvent
|
||||
next, err = watch.Proceed()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output nothing
|
||||
t.Log("Deregister Proceed first delete service: ", instance.GetEndpoints().String(), ", instance id: ", instance.(*Service).ID)
|
||||
}
|
||||
|
||||
// ReRegister
|
||||
s1, err = r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("Register service Regin register svc instance id:", s1.(*Service).ID)
|
||||
// svc deregister, DeleteEvent
|
||||
next, err = watch.Proceed()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output nothing
|
||||
t.Log("Deregister Proceed second register service: ", instance.GetEndpoints().String(), ", instance id: ", instance.(*Service).ID)
|
||||
}
|
||||
|
||||
if err = r.Deregister(context.Background(), s22); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// svc deregister, DeleteEvent
|
||||
next, err = watch.Proceed()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output nothing
|
||||
t.Log("Deregister Proceed second delete service: ", instance.GetEndpoints().String(), ", instance id: ", instance.(*Service).ID)
|
||||
}
|
||||
|
||||
// svc register, deleteEvent Deregister s1
|
||||
if err = r.Deregister(context.Background(), s1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// svc deregister, DeleteEvent
|
||||
next, err = watch.Proceed()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output nothing
|
||||
t.Log("Deregister Proceed third delete service: ", instance.GetEndpoints().String(), ", instance id: ", instance.(*Service).ID)
|
||||
}
|
||||
|
||||
if err = watch.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = watch.Proceed(); err == nil {
|
||||
// if nil, stop failed
|
||||
t.Fatal()
|
||||
}
|
||||
t.Log("Watch close success")
|
||||
}
|
||||
|
||||
// BenchmarkRegister
|
||||
func BenchmarkRegister(b *testing.B) {
|
||||
conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"})
|
||||
conf.GetGlobal().GetStatReporter().SetEnable(false)
|
||||
conf.Consumer.LocalCache.SetPersistDir(os.TempDir() + "/polaris-registry/backup")
|
||||
if err := api.SetLoggersDir(os.TempDir() + "/polaris-registry/log"); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
r := NewWithConfig(
|
||||
conf,
|
||||
WithTimeout(time.Second*10),
|
||||
WithTTL(100),
|
||||
)
|
||||
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-0-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"})
|
||||
conf.GetGlobal().GetStatReporter().SetEnable(false)
|
||||
conf.Consumer.LocalCache.SetPersistDir(os.TempDir() + "/polaris-registry/backup")
|
||||
if err := api.SetLoggersDir(os.TempDir() + "/polaris-registry/log"); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
r := NewWithConfig(
|
||||
conf,
|
||||
WithTimeout(time.Second*10),
|
||||
WithTTL(100),
|
||||
)
|
||||
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-0-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
s, err := r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
@ -306,22 +467,26 @@ func TestRegistryManyForEndpoints(t *testing.T) {
|
||||
Endpoints: gsvc.NewEndpoints(endpointThree),
|
||||
}
|
||||
|
||||
// svc register, AddEvent
|
||||
s0, err := r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// svc register, AddEvent
|
||||
s1, err := r.Register(context.Background(), svc1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// svc register, AddEvent
|
||||
s2, err := r.Register(context.Background(), svc2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log("Register service success sleep 1s")
|
||||
time.Sleep(time.Second * 1)
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
// serviceName = "service-default-default-goframe-provider-tcp-latest"
|
||||
result, err := r.Search(context.Background(), gsvc.SearchInput{
|
||||
Name: serviceName,
|
||||
@ -355,5 +520,244 @@ func TestRegistryManyForEndpoints(t *testing.T) {
|
||||
if err = r.Deregister(context.Background(), s2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Log("Deregister success")
|
||||
}
|
||||
|
||||
// TestWatcher_Close Test Close
|
||||
func TestWatcher_Close(t *testing.T) {
|
||||
conf := config.NewDefaultConfiguration([]string{"127.0.0.1:8091"})
|
||||
conf.GetGlobal().GetStatReporter().SetEnable(false)
|
||||
conf.Consumer.LocalCache.SetPersistDir(os.TempDir() + "/polaris-watch/backup")
|
||||
if err := api.SetLoggersDir(os.TempDir() + "/polaris-watch/log"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := NewWithConfig(
|
||||
conf,
|
||||
WithTimeout(time.Second*10),
|
||||
WithTTL(100),
|
||||
)
|
||||
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-close-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
s := &Service{
|
||||
Service: svc,
|
||||
}
|
||||
|
||||
watch, err := r.Watch(context.Background(), s.GetPrefix())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s1, err := r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// watch svc
|
||||
time.Sleep(time.Second * 1)
|
||||
if err = r.Deregister(context.Background(), s1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = watch.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = watch.Proceed(); err == nil {
|
||||
// if nil, stop failed
|
||||
t.Fatal()
|
||||
}
|
||||
t.Log("Watch close success")
|
||||
}
|
||||
|
||||
// TestGetKey Test get key
|
||||
func TestGetKey(t *testing.T) {
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-key-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
s := &Service{
|
||||
Service: svc,
|
||||
}
|
||||
if s.GetKey() != "service-default-default-goframe-provider-key-tcp-test-127.0.0.1:9000" {
|
||||
t.Fatal("GetKey error key:", s.GetKey())
|
||||
}
|
||||
t.Log("GetKey success ")
|
||||
}
|
||||
|
||||
// TestService_GetPrefix Test GetPrefix
|
||||
func TestService_GetPrefix(t *testing.T) {
|
||||
type fields struct {
|
||||
Service gsvc.Service
|
||||
ID string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "TestService_GetPrefix-0",
|
||||
fields: fields{
|
||||
Service: &gsvc.LocalService{
|
||||
Name: "goframe-provider-0-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
},
|
||||
ID: "test",
|
||||
},
|
||||
want: "service-default-default-goframe-provider-0-tcp-test",
|
||||
},
|
||||
{
|
||||
name: "TestService_GetPrefix-1",
|
||||
fields: fields{
|
||||
Service: &gsvc.LocalService{
|
||||
Name: "goframe-provider-1-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9001"),
|
||||
},
|
||||
ID: "test",
|
||||
},
|
||||
want: "service-default-default-goframe-provider-1-tcp-test",
|
||||
},
|
||||
{
|
||||
name: "TestService_GetPrefix-2",
|
||||
fields: fields{
|
||||
Service: &gsvc.LocalService{
|
||||
Name: "goframe-provider-2-tcp",
|
||||
Version: "latest",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9002"),
|
||||
},
|
||||
ID: "latest",
|
||||
},
|
||||
want: "service-default-default-goframe-provider-2-tcp-latest",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &Service{
|
||||
Service: tt.fields.Service,
|
||||
ID: tt.fields.ID,
|
||||
}
|
||||
if got := s.GetPrefix(); got != tt.want {
|
||||
t.Errorf("GetPrefix() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestService_GetName Test GetName
|
||||
func TestService_GetKey(t *testing.T) {
|
||||
type fields struct {
|
||||
Service gsvc.Service
|
||||
ID string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "TestService_GetKey-0",
|
||||
fields: fields{
|
||||
Service: &gsvc.LocalService{
|
||||
Namespace: gsvc.DefaultNamespace,
|
||||
Deployment: gsvc.DefaultDeployment,
|
||||
Name: "goframe-provider-0-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
},
|
||||
ID: "test",
|
||||
},
|
||||
want: "service-default-default-goframe-provider-0-tcp-test-127.0.0.1:9000",
|
||||
},
|
||||
{
|
||||
name: "TestService_GetKey-1",
|
||||
fields: fields{
|
||||
Service: &gsvc.LocalService{
|
||||
Namespace: gsvc.DefaultNamespace,
|
||||
Deployment: gsvc.DefaultDeployment,
|
||||
Name: "goframe-provider-1-tcp",
|
||||
Version: "latest",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9001"),
|
||||
},
|
||||
ID: "latest",
|
||||
},
|
||||
want: "service-default-default-goframe-provider-1-tcp-latest-127.0.0.1:9001",
|
||||
},
|
||||
{
|
||||
name: "TestService_GetKey-2",
|
||||
fields: fields{
|
||||
Service: &gsvc.LocalService{
|
||||
Namespace: gsvc.DefaultNamespace,
|
||||
Deployment: gsvc.DefaultDeployment,
|
||||
Name: "goframe-provider-2-tcp",
|
||||
Version: "latest",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9002"),
|
||||
},
|
||||
ID: "latest",
|
||||
},
|
||||
want: "service-default-default-goframe-provider-2-tcp-latest-127.0.0.1:9002",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &Service{
|
||||
Service: tt.fields.Service,
|
||||
ID: tt.fields.ID,
|
||||
}
|
||||
if got := s.GetKey(); got != tt.want {
|
||||
t.Errorf("GetKey() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Test_trimAndReplace Test trimAndReplace
|
||||
func Test_trimAndReplace(t *testing.T) {
|
||||
type args struct {
|
||||
key string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "Test_trimAndReplace-0",
|
||||
args: args{key: "/service/default/default/goframe-provider-0-tcp/latest/127.0.0.1:9000"},
|
||||
want: "service-default-default-goframe-provider-0-tcp-latest-127.0.0.1:9000",
|
||||
},
|
||||
{
|
||||
name: "Test_trimAndReplace-1",
|
||||
args: args{key: "/service/default/default/goframe-provider-1-tcp/latest/127.0.0.1:9001"},
|
||||
want: "service-default-default-goframe-provider-1-tcp-latest-127.0.0.1:9001",
|
||||
},
|
||||
{
|
||||
name: "Test_trimAndReplace-2",
|
||||
args: args{key: "/service/default/default/goframe-provider-2-tcp/latest/127.0.0.1:9002"},
|
||||
want: "service-default-default-goframe-provider-2-tcp-latest-127.0.0.1:9002",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := trimAndReplace(tt.args.key); got != tt.want {
|
||||
t.Errorf("trimAndReplace() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/go-zookeeper/zk v1.0.3
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
golang.org/x/sync v0.1.0
|
||||
)
|
||||
|
||||
|
||||
@ -83,5 +83,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -3,8 +3,8 @@ module github.com/gogf/gf/contrib/rpc/grpcx/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.5.1
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
go.opentelemetry.io/otel v1.10.0
|
||||
go.opentelemetry.io/otel/trace v1.10.0
|
||||
golang.org/x/net v0.0.0-20220919232410-f2f64ebce3c1 // indirect
|
||||
|
||||
@ -193,7 +193,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
|
||||
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.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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/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=
|
||||
|
||||
@ -2,6 +2,6 @@ module github.com/gogf/gf/contrib/sdk/httpclient/v2
|
||||
|
||||
go 1.15
|
||||
|
||||
require github.com/gogf/gf/v2 v2.5.0
|
||||
require github.com/gogf/gf/v2 v2.5.1
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -79,5 +79,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/jaeger/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
go.opentelemetry.io/otel v1.7.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.7.0
|
||||
go.opentelemetry.io/otel/sdk v1.7.0
|
||||
|
||||
@ -82,5 +82,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/otlpgrpc/v2
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
go.opentelemetry.io/otel v1.16.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
|
||||
|
||||
@ -476,8 +476,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
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.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/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-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/otlphttp/v2
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
go.opentelemetry.io/otel v1.16.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0
|
||||
|
||||
@ -475,8 +475,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
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.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/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-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@ -115,7 +115,7 @@ func (b *WhereBuilder) convertWhereBuilder(where interface{}, args []interface{}
|
||||
}
|
||||
if builder != nil {
|
||||
conditionWhere, conditionArgs := builder.Build()
|
||||
if conditionWhere != "" && len(b.whereHolder) == 0 {
|
||||
if conditionWhere != "" && (len(b.whereHolder) == 0 || len(builder.whereHolder) > 1) {
|
||||
conditionWhere = "(" + conditionWhere + ")"
|
||||
}
|
||||
return conditionWhere, conditionArgs
|
||||
|
||||
@ -3,20 +3,20 @@ module github.com/gogf/gf/example
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/config/apollo/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/config/kubecm/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/config/nacos/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/config/polaris/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/registry/etcd/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/registry/polaris/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/trace/jaeger/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.5.0
|
||||
github.com/gogf/gf/v2 v2.5.0
|
||||
github.com/gogf/gf/contrib/config/apollo/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/config/kubecm/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/config/nacos/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/config/polaris/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/registry/etcd/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/registry/polaris/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/trace/jaeger/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.5.1
|
||||
github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.5.1
|
||||
github.com/gogf/gf/v2 v2.5.1
|
||||
github.com/nacos-group/nacos-sdk-go v1.1.2
|
||||
github.com/polarismesh/polaris-go v1.5.1
|
||||
google.golang.org/grpc v1.55.0
|
||||
|
||||
2
go.mod
2
go.mod
@ -16,5 +16,5 @@ require (
|
||||
go.opentelemetry.io/otel/trace v1.7.0
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
4
go.sum
4
go.sum
@ -79,5 +79,5 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
|
||||
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/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=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@ -8,32 +8,11 @@ package ghttp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
// neverDoneCtx never done.
|
||||
type neverDoneCtx struct {
|
||||
context.Context
|
||||
}
|
||||
|
||||
// Done forbids the context done from parent context.
|
||||
func (*neverDoneCtx) Done() <-chan struct{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deadline forbids the context deadline from parent context.
|
||||
func (*neverDoneCtx) Deadline() (deadline time.Time, ok bool) {
|
||||
return time.Time{}, false
|
||||
}
|
||||
|
||||
// Err forbids the context done from parent context.
|
||||
func (c *neverDoneCtx) Err() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RequestFromCtx retrieves and returns the Request object from context.
|
||||
func RequestFromCtx(ctx context.Context) *Request {
|
||||
if v := ctx.Value(ctxKeyForRequest); v != nil {
|
||||
@ -72,7 +51,7 @@ func (r *Request) GetCtx() context.Context {
|
||||
// This change is considered for common usage habits of developers for context propagation
|
||||
// in multiple goroutines creation in one HTTP request.
|
||||
func (r *Request) GetNeverDoneCtx() context.Context {
|
||||
return &neverDoneCtx{r.Context()}
|
||||
return gctx.NeverDone(r.Context())
|
||||
}
|
||||
|
||||
// SetCtx custom context for current request.
|
||||
|
||||
@ -447,6 +447,9 @@ func (s *Server) Run() {
|
||||
func Wait() {
|
||||
var ctx = context.TODO()
|
||||
|
||||
// Signal handler in asynchronous way.
|
||||
go handleProcessSignal()
|
||||
|
||||
<-allShutdownChan
|
||||
// Remove plugins.
|
||||
serverMapping.Iterator(func(k string, v interface{}) bool {
|
||||
|
||||
@ -280,3 +280,88 @@ func Test_Issue2334(t *testing.T) {
|
||||
t.Assert(res.StatusCode, 304)
|
||||
})
|
||||
}
|
||||
|
||||
type CreateOrderReq struct {
|
||||
g.Meta `path:"/order" tags:"订单" method:"put" summary:"创建订单"`
|
||||
Details []*OrderDetail `p:"detail" v:"required#请输入订单详情" dc:"订单详情"`
|
||||
}
|
||||
|
||||
type OrderDetail struct {
|
||||
Name string `p:"name" v:"required#请输入物料名称" dc:"物料名称"`
|
||||
Sn string `p:"sn" v:"required#请输入客户编号" dc:"客户编号"`
|
||||
Images string `p:"images" dc:"图片"`
|
||||
Desc string `p:"desc" dc:"备注"`
|
||||
Number int `p:"number" v:"required#请输入数量" dc:"数量"`
|
||||
Price float64 `p:"price" v:"required" dc:"单价"`
|
||||
}
|
||||
|
||||
type CreateOrderRes struct{}
|
||||
type OrderController struct{}
|
||||
|
||||
func (c *OrderController) CreateOrder(ctx context.Context, req *CreateOrderReq) (res *CreateOrderRes, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/2482
|
||||
func Test_Issue2482(t *testing.T) {
|
||||
s := g.Server(guid.S())
|
||||
s.Group("/api/v2", func(group *ghttp.RouterGroup) {
|
||||
group.Middleware(ghttp.MiddlewareHandlerResponse)
|
||||
group.Bind(OrderController{})
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
defer s.Shutdown()
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
|
||||
c := g.Client()
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
content := `
|
||||
{
|
||||
"detail": [
|
||||
{
|
||||
"images": "string",
|
||||
"desc": "string",
|
||||
"number": 0,
|
||||
"price": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
t.Assert(c.PutContent(ctx, "/api/v2/order", content), `{"code":51,"message":"请输入物料名称","data":null}`)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
content := `
|
||||
{
|
||||
"detail": [
|
||||
{
|
||||
"images": "string",
|
||||
"desc": "string",
|
||||
"number": 0,
|
||||
"name": "string",
|
||||
"price": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
t.Assert(c.PutContent(ctx, "/api/v2/order", content), `{"code":51,"message":"请输入客户编号","data":null}`)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
content := `
|
||||
{
|
||||
"detail": [
|
||||
{
|
||||
"images": "string",
|
||||
"desc": "string",
|
||||
"number": 0,
|
||||
"name": "string",
|
||||
"sn": "string",
|
||||
"price": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
`
|
||||
t.Assert(c.PutContent(ctx, "/api/v2/order", content), `{"code":0,"message":"","data":null}`)
|
||||
})
|
||||
}
|
||||
|
||||
@ -168,3 +168,16 @@ func Test_BuildParams(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_ServerSignal(t *testing.T) {
|
||||
s := g.Server(guid.S())
|
||||
s.BindHandler("/", func(r *ghttp.Request) {
|
||||
r.Response.Write("hello world")
|
||||
})
|
||||
gtest.Assert(s.Start(), nil)
|
||||
g.Wait()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertEQ(s.Shutdown(), nil)
|
||||
})
|
||||
}
|
||||
|
||||
@ -91,8 +91,7 @@ func watchAndUpdateService(watchedServiceMap *gmap.StrAnyMap, watcher Watcher, s
|
||||
)
|
||||
for {
|
||||
time.Sleep(time.Second)
|
||||
services, err = watcher.Proceed()
|
||||
if err != nil {
|
||||
if services, err = watcher.Proceed(); err != nil {
|
||||
intlog.Errorf(ctx, `%+v`, err)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -24,14 +24,16 @@ type BuildInfo struct {
|
||||
Golang string // Built used Golang version.
|
||||
Git string // Built used git repo. commit id and datetime.
|
||||
Time string // Built datetime.
|
||||
Version string // Built version.
|
||||
Data map[string]interface{} // All custom built data key-value pairs.
|
||||
}
|
||||
|
||||
const (
|
||||
gfVersion = `gfVersion`
|
||||
goVersion = `goVersion`
|
||||
builtGit = `builtGit`
|
||||
builtTime = `builtTime`
|
||||
gfVersion = `gfVersion`
|
||||
goVersion = `goVersion`
|
||||
BuiltGit = `builtGit`
|
||||
BuiltTime = `builtTime`
|
||||
BuiltVersion = `builtVersion`
|
||||
)
|
||||
|
||||
var (
|
||||
@ -61,8 +63,9 @@ func Info() BuildInfo {
|
||||
return BuildInfo{
|
||||
GoFrame: Get(gfVersion).String(),
|
||||
Golang: Get(goVersion).String(),
|
||||
Git: Get(builtGit).String(),
|
||||
Time: Get(builtTime).String(),
|
||||
Git: Get(BuiltGit).String(),
|
||||
Time: Get(BuiltTime).String(),
|
||||
Version: Get(BuiltVersion).String(),
|
||||
Data: Data(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ func Test_Info(t *testing.T) {
|
||||
"Golang": "",
|
||||
"Git": "",
|
||||
"Time": "",
|
||||
"Version": "",
|
||||
"Data": g.Map{},
|
||||
})
|
||||
})
|
||||
|
||||
38
os/gctx/gctx_never_done.go
Normal file
38
os/gctx/gctx_never_done.go
Normal file
@ -0,0 +1,38 @@
|
||||
// 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 gctx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// neverDoneCtx never done.
|
||||
type neverDoneCtx struct {
|
||||
context.Context
|
||||
}
|
||||
|
||||
// Done forbids the context done from parent context.
|
||||
func (*neverDoneCtx) Done() <-chan struct{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deadline forbids the context deadline from parent context.
|
||||
func (*neverDoneCtx) Deadline() (deadline time.Time, ok bool) {
|
||||
return time.Time{}, false
|
||||
}
|
||||
|
||||
// Err forbids the context done from parent context.
|
||||
func (c *neverDoneCtx) Err() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// NeverDone wraps and returns a new context object that will be never done,
|
||||
// which forbids the context manually done, to make the context can be propagated to asynchronous goroutines.
|
||||
func NeverDone(ctx context.Context) context.Context {
|
||||
return &neverDoneCtx{ctx}
|
||||
}
|
||||
38
os/gctx/gctx_z_unit_internal_test.go
Normal file
38
os/gctx/gctx_z_unit_internal_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
// 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 gctx_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
func Test_NeverDone(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
ctx, _ := context.WithDeadline(gctx.New(), time.Now().Add(time.Hour))
|
||||
t.AssertNE(ctx, nil)
|
||||
t.AssertNE(ctx.Done(), nil)
|
||||
t.Assert(ctx.Err(), nil)
|
||||
|
||||
tm, ok := ctx.Deadline()
|
||||
t.AssertNE(tm, time.Time{})
|
||||
t.Assert(ok, true)
|
||||
|
||||
ctx = gctx.NeverDone(ctx)
|
||||
t.AssertNE(ctx, nil)
|
||||
t.Assert(ctx.Done(), nil)
|
||||
t.Assert(ctx.Err(), nil)
|
||||
|
||||
tm, ok = ctx.Deadline()
|
||||
t.Assert(tm, time.Time{})
|
||||
t.Assert(ok, false)
|
||||
})
|
||||
}
|
||||
@ -147,82 +147,118 @@ func NewFromTimeStamp(timestamp int64) *Time {
|
||||
|
||||
// Timestamp returns the timestamp in seconds.
|
||||
func (t *Time) Timestamp() int64 {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return t.UnixNano() / 1e9
|
||||
}
|
||||
|
||||
// TimestampMilli returns the timestamp in milliseconds.
|
||||
func (t *Time) TimestampMilli() int64 {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return t.UnixNano() / 1e6
|
||||
}
|
||||
|
||||
// TimestampMicro returns the timestamp in microseconds.
|
||||
func (t *Time) TimestampMicro() int64 {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return t.UnixNano() / 1e3
|
||||
}
|
||||
|
||||
// TimestampNano returns the timestamp in nanoseconds.
|
||||
func (t *Time) TimestampNano() int64 {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return t.UnixNano()
|
||||
}
|
||||
|
||||
// TimestampStr is a convenience method which retrieves and returns
|
||||
// the timestamp in seconds as string.
|
||||
func (t *Time) TimestampStr() string {
|
||||
if t.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return strconv.FormatInt(t.Timestamp(), 10)
|
||||
}
|
||||
|
||||
// TimestampMilliStr is a convenience method which retrieves and returns
|
||||
// the timestamp in milliseconds as string.
|
||||
func (t *Time) TimestampMilliStr() string {
|
||||
if t.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return strconv.FormatInt(t.TimestampMilli(), 10)
|
||||
}
|
||||
|
||||
// TimestampMicroStr is a convenience method which retrieves and returns
|
||||
// the timestamp in microseconds as string.
|
||||
func (t *Time) TimestampMicroStr() string {
|
||||
if t.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return strconv.FormatInt(t.TimestampMicro(), 10)
|
||||
}
|
||||
|
||||
// TimestampNanoStr is a convenience method which retrieves and returns
|
||||
// the timestamp in nanoseconds as string.
|
||||
func (t *Time) TimestampNanoStr() string {
|
||||
if t.IsZero() {
|
||||
return ""
|
||||
}
|
||||
return strconv.FormatInt(t.TimestampNano(), 10)
|
||||
}
|
||||
|
||||
// Month returns the month of the year specified by t.
|
||||
func (t *Time) Month() int {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return int(t.Time.Month())
|
||||
}
|
||||
|
||||
// Second returns the second offset within the minute specified by t,
|
||||
// in the range [0, 59].
|
||||
func (t *Time) Second() int {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return t.Time.Second()
|
||||
}
|
||||
|
||||
// Millisecond returns the millisecond offset within the second specified by t,
|
||||
// in the range [0, 999].
|
||||
func (t *Time) Millisecond() int {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return t.Time.Nanosecond() / 1e6
|
||||
}
|
||||
|
||||
// Microsecond returns the microsecond offset within the second specified by t,
|
||||
// in the range [0, 999999].
|
||||
func (t *Time) Microsecond() int {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return t.Time.Nanosecond() / 1e3
|
||||
}
|
||||
|
||||
// Nanosecond returns the nanosecond offset within the second specified by t,
|
||||
// in the range [0, 999999999].
|
||||
func (t *Time) Nanosecond() int {
|
||||
if t.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return t.Time.Nanosecond()
|
||||
}
|
||||
|
||||
// String returns current time object as string.
|
||||
func (t *Time) String() string {
|
||||
if t == nil {
|
||||
return ""
|
||||
}
|
||||
if t.IsZero() {
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -71,6 +71,22 @@ func Test_New(t *testing.T) {
|
||||
t.Assert(gtime.New(gtime.Time{}), nil)
|
||||
t.Assert(gtime.New(>ime.Time{}), nil)
|
||||
})
|
||||
|
||||
// unconventional
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
|
||||
var testUnconventionalDates = []string{
|
||||
"2006-01.02",
|
||||
"2006.01-02",
|
||||
}
|
||||
|
||||
for _, item := range testUnconventionalDates {
|
||||
timeTemp := gtime.New(item)
|
||||
t.Assert(timeTemp.TimestampMilli(), 0)
|
||||
t.Assert(timeTemp.TimestampMilliStr(), "")
|
||||
t.Assert(timeTemp.String(), "")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Nil(t *testing.T) {
|
||||
|
||||
@ -528,7 +528,7 @@ field3:
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = json.Marshal(parsed)
|
||||
t.Assert(err.Error(), "json: unsupported type: map[interface {}]interface {}")
|
||||
t.AssertNil(err)
|
||||
|
||||
converted := gconv.MapDeep(parsed)
|
||||
jsonData, err := json.Marshal(converted)
|
||||
|
||||
@ -215,9 +215,9 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error
|
||||
// which have the most priority than `rules` and struct tag.
|
||||
if msg, ok := v.messages.(CustomMsg); ok && len(msg) > 0 {
|
||||
for k, msgName := range msg {
|
||||
if a, ok := fieldToAliasNameMap[k]; ok {
|
||||
if aliasName, ok := fieldToAliasNameMap[k]; ok {
|
||||
// Overwrite the key of field name.
|
||||
customMessage[a] = msgName
|
||||
customMessage[aliasName] = msgName
|
||||
} else {
|
||||
customMessage[k] = msgName
|
||||
}
|
||||
@ -245,13 +245,17 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// The `field.TagValue` is the alias name of field.Name().
|
||||
// Eg, value from struct tag `p`.
|
||||
if field.TagValue != "" {
|
||||
fieldToAliasNameMap[field.Name()] = field.TagValue
|
||||
}
|
||||
switch field.OriginalKind() {
|
||||
case reflect.Map, reflect.Struct, reflect.Slice, reflect.Array:
|
||||
// Recursively check attribute slice/map.
|
||||
_, value = gutil.MapPossibleItemByKey(inputParamMap, field.Name())
|
||||
value = getPossibleValueFromMap(
|
||||
inputParamMap, field.Name(), fieldToAliasNameMap[field.Name()],
|
||||
)
|
||||
if value == nil {
|
||||
switch field.Kind() {
|
||||
case reflect.Map, reflect.Ptr, reflect.Slice, reflect.Array:
|
||||
@ -279,12 +283,9 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error
|
||||
// The following logic is the same as some of CheckMap but with sequence support.
|
||||
for _, checkRuleItem := range checkRules {
|
||||
if !checkRuleItem.IsMeta {
|
||||
_, value = gutil.MapPossibleItemByKey(inputParamMap, checkRuleItem.Name)
|
||||
if value == nil {
|
||||
if aliasName := fieldToAliasNameMap[checkRuleItem.Name]; aliasName != "" {
|
||||
_, value = gutil.MapPossibleItemByKey(inputParamMap, aliasName)
|
||||
}
|
||||
}
|
||||
value = getPossibleValueFromMap(
|
||||
inputParamMap, checkRuleItem.Name, fieldToAliasNameMap[checkRuleItem.Name],
|
||||
)
|
||||
}
|
||||
// Empty json string checks according to mapping field kind.
|
||||
if value != nil {
|
||||
@ -347,3 +348,11 @@ func (v *Validator) doCheckStruct(ctx context.Context, object interface{}) Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPossibleValueFromMap(inputParamMap map[string]interface{}, fieldName, aliasName string) (value interface{}) {
|
||||
_, value = gutil.MapPossibleItemByKey(inputParamMap, fieldName)
|
||||
if value == nil && aliasName != "" {
|
||||
_, value = gutil.MapPossibleItemByKey(inputParamMap, aliasName)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -2,5 +2,5 @@ package gf
|
||||
|
||||
const (
|
||||
// VERSION is the current GoFrame version.
|
||||
VERSION = "v2.5.0"
|
||||
VERSION = "v2.5.1"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user