mirror of
https://gitee.com/johng/gf
synced 2026-06-10 11:27:17 +08:00
Compare commits
19 Commits
v2.4.0-rc4
...
v2.4.1
| Author | SHA1 | Date | |
|---|---|---|---|
| d6471d7d51 | |||
| aa9d66c53c | |||
| d9a7ee3e29 | |||
| 04c70f2037 | |||
| 2198f0cefe | |||
| c6b9b4d326 | |||
| 4c6ebe7808 | |||
| a9090e4a72 | |||
| 0126eb5470 | |||
| ed63617aa0 | |||
| 30f483a524 | |||
| 894f202b75 | |||
| 9171585b2c | |||
| 23d8ef32a3 | |||
| a031e112e5 | |||
| da8297d770 | |||
| 3991eb053c | |||
| 6fb26c44d7 | |||
| fdc027734c |
7
.github/workflows/gf.yml
vendored
7
.github/workflows/gf.yml
vendored
@ -120,13 +120,16 @@ jobs:
|
||||
- 9001:9001
|
||||
|
||||
# Polaris backend server.
|
||||
# docker run -d --name polaris -p 8090:8090 -p 8091:8091 -p 8093:8093 loads/polaris-server-standalone:1.11.2
|
||||
# docker run -d --name polaris -p 8090:8090 -p 8091:8091 -p 8093:8093 -p 9090:9090 -p 9091:9091 loads/polaris-server-standalone:1.11.2
|
||||
# docker run -d --name polaris -p 8090:8090 -p 8091:8091 -p 8093:8093 -p 9090:9090 -p 9091:9091 loads/polaris-standalone:v1.16.3
|
||||
polaris:
|
||||
image: loads/polaris-server-standalone:1.11.2
|
||||
image: loads/polaris-standalone:v1.16.4
|
||||
ports:
|
||||
- 8090:8090
|
||||
- 8091:8091
|
||||
- 8093:8093
|
||||
- 9090:9090
|
||||
- 9091:9091
|
||||
|
||||
# Oracle 11g server
|
||||
oracle-server:
|
||||
|
||||
12
.github/workflows/tag.yml
vendored
12
.github/workflows/tag.yml
vendored
@ -19,18 +19,6 @@ jobs:
|
||||
- name: Checkout Github Code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# - name: Update Dependencies
|
||||
# run: make gftidy
|
||||
#
|
||||
# - name: Commit & Push Changes
|
||||
# uses: actions-js/push@master
|
||||
# with:
|
||||
# github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
# branch: master
|
||||
# author_name: TagRobot
|
||||
# author_email: tagrobot@goframe.org
|
||||
# message: "auto update version to ${{ github.ref_name }}"
|
||||
|
||||
- name: Auto Creating Tags For Contrib Packages
|
||||
run: |
|
||||
git config --global user.email "tagrobot@goframe.org"
|
||||
|
||||
26
Makefile
26
Makefile
@ -15,21 +15,29 @@ tidy:
|
||||
lint:
|
||||
golangci-lint run
|
||||
|
||||
gftidy:
|
||||
$(eval files=$(shell find . -name go.mod))
|
||||
# make version to=v2.4.0
|
||||
.PHONY: version
|
||||
version:
|
||||
$(eval files=$(shell find . -name go.mod))
|
||||
@set -e; \
|
||||
# GITHUB_REF_NAME=v2.4.0; \
|
||||
if [[ $$GITHUB_REF_NAME =~ "v" ]]; then \
|
||||
latestVersion=$$GITHUB_REF_NAME; \
|
||||
newVersion=$(to); \
|
||||
echo "The version will be set to $$newVersion"; \
|
||||
if [[ $$newVersion =~ "v" ]]; then \
|
||||
latestVersion=$$newVersion; \
|
||||
echo "package gf" > version.go; \
|
||||
echo "" >> version.go; \
|
||||
echo "const (" >> version.go; \
|
||||
echo -e "\t// VERSION is the current GoFrame version." >> version.go; \
|
||||
echo -e "\tVERSION = \"$$latestVersion\"" >> version.go; \
|
||||
echo ")" >> version.go; \
|
||||
else \
|
||||
latestVersion=latest; \
|
||||
fi; \
|
||||
for file in ${files}; do \
|
||||
goModPath=$$(dirname $$file); \
|
||||
if [[ $$goModPath =~ "./contrib" || $$goModPath =~ "./cmd/gf" || $$goModPath =~ "./example" ]]; then \
|
||||
echo ""; \
|
||||
echo "" ; \
|
||||
echo "processing dir: $$goModPath"; \
|
||||
# Do not modify the order of any of the following sentences \
|
||||
cd $$goModPath; \
|
||||
go mod tidy; \
|
||||
go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@$$latestVersion{{end}}" -m all | grep "^github.com/gogf/gf/contrib" | xargs -L1 go get -v; \
|
||||
@ -37,4 +45,6 @@ gftidy:
|
||||
go mod tidy; \
|
||||
cd -; \
|
||||
fi \
|
||||
done
|
||||
done
|
||||
|
||||
|
||||
|
||||
@ -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.3.3
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.3.3
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.3.3
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.3.3
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.3.3
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.4.1
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.4.1
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.4.1
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.4.1
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.4.1
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.4.1
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
golang.org/x/tools v0.7.0
|
||||
)
|
||||
|
||||
@ -124,6 +124,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
@ -298,7 +304,7 @@ buildDone:
|
||||
return
|
||||
}
|
||||
|
||||
// getBuildInVarMapJson retrieves and returns the custom build-in variables in configuration
|
||||
// getBuildInVarStr retrieves and returns the custom build-in variables in configuration
|
||||
// file as json.
|
||||
func (c cBuild) getBuildInVarStr(ctx context.Context, in cBuildInput) string {
|
||||
buildInVarMap := in.VarMap
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@ -1,14 +1,21 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||
)
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
@ -12,6 +18,7 @@ var (
|
||||
type cGen struct {
|
||||
g.Meta `name:"gen" brief:"{cGenBrief}" dc:"{cGenDc}"`
|
||||
cGenDao
|
||||
cGenEnums
|
||||
cGenPb
|
||||
cGenPbEntity
|
||||
cGenService
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
15
cmd/gf/internal/cmd/cmd_gen_enums.go
Normal file
15
cmd/gf/internal/cmd/cmd_gen_enums.go
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genenums"
|
||||
)
|
||||
|
||||
type (
|
||||
cGenEnums = genenums.CGenEnums
|
||||
)
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/gogf/gf/cmd/gf/v2/internal/cmd/genpb"
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/gogf/gf/cmd/gf/v2/internal/cmd/genpbentity"
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@ -1,8 +1,15 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@ -10,6 +17,7 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
"github.com/gogf/gf/v2/os/gres"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gtag"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
|
||||
@ -37,6 +45,10 @@ gf init my-mono-repo -m
|
||||
name for the project. It will create a folder with NAME in current directory.
|
||||
The NAME will also be the module name for the project.
|
||||
`
|
||||
// cInitGitDir the git directory
|
||||
cInitGitDir = ".git"
|
||||
// cInitGitignore the gitignore file
|
||||
cInitGitignore = ".gitignore"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -57,17 +69,22 @@ type cInitInput struct {
|
||||
type cInitOutput struct{}
|
||||
|
||||
func (c cInit) Index(ctx context.Context, in cInitInput) (out *cInitOutput, err error) {
|
||||
var (
|
||||
overwrote = false
|
||||
)
|
||||
if !gfile.IsEmpty(in.Name) && !allyes.Check() {
|
||||
s := gcmd.Scanf(`the folder "%s" is not empty, files might be overwrote, continue? [y/n]: `, in.Name)
|
||||
if strings.EqualFold(s, "n") {
|
||||
return
|
||||
}
|
||||
overwrote = true
|
||||
}
|
||||
mlog.Print("initializing...")
|
||||
|
||||
// Create project folder and files.
|
||||
var (
|
||||
templateRepoName string
|
||||
gitignoreFile = in.Name + "/" + cInitGitignore
|
||||
)
|
||||
if in.Mono {
|
||||
templateRepoName = cInitMonoRepo
|
||||
@ -81,14 +98,35 @@ func (c cInit) Index(ctx context.Context, in cInitInput) (out *cInitOutput, err
|
||||
return
|
||||
}
|
||||
|
||||
// build ignoreFiles from the .gitignore file
|
||||
ignoreFiles := make([]string, 0, 10)
|
||||
ignoreFiles = append(ignoreFiles, cInitGitDir)
|
||||
if overwrote {
|
||||
err = gfile.ReadLines(gitignoreFile, func(line string) error {
|
||||
// Add only hidden files or directories
|
||||
// If other directories are added, it may cause the entire directory to be ignored
|
||||
// such as 'main' in the .gitignore file, but the path is 'D:\main\my-project'
|
||||
if line != "" && strings.HasPrefix(line, ".") {
|
||||
ignoreFiles = append(ignoreFiles, line)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// if not found the .gitignore file will skip os.ErrNotExist error
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Replace template name to project name.
|
||||
err = gfile.ReplaceDir(
|
||||
cInitRepoPrefix+templateRepoName,
|
||||
gfile.Basename(gfile.RealPath(in.Name)),
|
||||
in.Name,
|
||||
"*",
|
||||
true,
|
||||
)
|
||||
err = gfile.ReplaceDirFunc(func(path, content string) string {
|
||||
for _, ignoreFile := range ignoreFiles {
|
||||
if strings.Contains(path, ignoreFile) {
|
||||
return content
|
||||
}
|
||||
}
|
||||
return gstr.Replace(gfile.GetContents(path), cInitRepoPrefix+templateRepoName, gfile.Basename(gfile.RealPath(in.Name)))
|
||||
}, in.Name, "*", true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
@ -33,7 +39,7 @@ like json/xml/yaml/toml/ini.
|
||||
cTplParseEg = `
|
||||
gf tpl parse -p ./template -v values.json -r
|
||||
gf tpl parse -p ./template -v values.json -n *.tpl -r
|
||||
gf tpl parse -p ./template -v values.json -d '${,}}' -r
|
||||
gf tpl parse -p ./template -v values.json -d '${{,}}' -r
|
||||
gf tpl parse -p ./template -v values.json -o ./template.parsed
|
||||
`
|
||||
cTplSupportValuesFilePattern = `*.json,*.xml,*.yaml,*.yml,*.toml,*.ini`
|
||||
@ -63,7 +69,7 @@ func init() {
|
||||
}
|
||||
|
||||
func (c *cTpl) Parse(ctx context.Context, in cTplParseInput) (out *cTplParseOutput, err error) {
|
||||
if in.Output == "" && in.Replace == false {
|
||||
if in.Output == "" && !in.Replace {
|
||||
return nil, gerror.New(`parameter output and replace should not be both empty`)
|
||||
}
|
||||
delimiters := gstr.SplitAndTrim(in.Delimiters, ",")
|
||||
|
||||
@ -1,11 +1,18 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
|
||||
"github.com/gogf/gf/v2/container/gset"
|
||||
"runtime"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gendao
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gendao
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gendao
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gendao
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gendao
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package gendao
|
||||
|
||||
import (
|
||||
@ -5,11 +11,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
type generateStructDefinitionInput struct {
|
||||
@ -50,7 +57,7 @@ func generateStructDefinition(ctx context.Context, in generateStructDefinitionIn
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
// generateStructFieldForModel generates and returns the attribute definition for specified field.
|
||||
// generateStructFieldDefinition generates and returns the attribute definition for specified field.
|
||||
func generateStructFieldDefinition(
|
||||
ctx context.Context, field *gdb.TableField, in generateStructDefinitionInput,
|
||||
) []string {
|
||||
|
||||
83
cmd/gf/internal/cmd/genenums/genenums.go
Normal file
83
cmd/gf/internal/cmd/genenums/genenums.go
Normal file
@ -0,0 +1,83 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package genenums
|
||||
|
||||
import (
|
||||
"context"
|
||||
"golang.org/x/tools/go/packages"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gtag"
|
||||
)
|
||||
|
||||
type (
|
||||
CGenEnums struct{}
|
||||
CGenEnumsInput struct {
|
||||
g.Meta `name:"enums" config:"{CGenEnumsConfig}" brief:"{CGenEnumsBrief}" eg:"{CGenEnumsEg}"`
|
||||
Src string `name:"src" short:"s" dc:"source folder path to be parsed" d:"."`
|
||||
Path string `name:"path" short:"p" dc:"output go file path storing enums content" d:"internal/boot/boot_enums.go"`
|
||||
Prefix string `name:"prefix" short:"x" dc:"only exports packages that starts with specified prefix"`
|
||||
}
|
||||
CGenEnumsOutput struct{}
|
||||
)
|
||||
|
||||
const (
|
||||
CGenEnumsConfig = `gfcli.gen.enums`
|
||||
CGenEnumsBrief = `parse go files in current project and generate enums go file`
|
||||
CGenEnumsEg = `
|
||||
gf gen enums
|
||||
gf gen enums -p internal/boot/boot_enums.go
|
||||
gf gen enums -p internal/boot/boot_enums.go -s .
|
||||
gf gen enums -x github.com/gogf
|
||||
`
|
||||
)
|
||||
|
||||
func init() {
|
||||
gtag.Sets(g.MapStrStr{
|
||||
`CGenEnumsEg`: CGenEnumsEg,
|
||||
`CGenEnumsBrief`: CGenEnumsBrief,
|
||||
`CGenEnumsConfig`: CGenEnumsConfig,
|
||||
})
|
||||
}
|
||||
|
||||
func (c CGenEnums) Enums(ctx context.Context, in CGenEnumsInput) (out *CGenEnumsOutput, err error) {
|
||||
realPath := gfile.RealPath(in.Src)
|
||||
if realPath == "" {
|
||||
mlog.Fatalf(`source folder path "%s" does not exist`, in.Src)
|
||||
}
|
||||
err = gfile.Chdir(realPath)
|
||||
if err != nil {
|
||||
mlog.Fatal(err)
|
||||
}
|
||||
mlog.Printf(`scanning: %s`, realPath)
|
||||
cfg := &packages.Config{
|
||||
Dir: realPath,
|
||||
Mode: pkgLoadMode,
|
||||
Tests: false,
|
||||
}
|
||||
pkgs, err := packages.Load(cfg)
|
||||
if err != nil {
|
||||
mlog.Fatal(err)
|
||||
}
|
||||
p := NewEnumsParser(in.Prefix)
|
||||
p.ParsePackages(pkgs)
|
||||
var enumsContent = gstr.ReplaceByMap(consts.TemplateGenEnums, g.MapStrStr{
|
||||
"{PackageName}": gfile.Basename(gfile.Dir(in.Path)),
|
||||
"{EnumsJson}": "`" + p.Export() + "`",
|
||||
})
|
||||
enumsContent = gstr.Trim(enumsContent)
|
||||
if err = gfile.PutContents(in.Path, enumsContent); err != nil {
|
||||
return
|
||||
}
|
||||
mlog.Printf(`generated: %s`, in.Path)
|
||||
mlog.Print("done!")
|
||||
return
|
||||
}
|
||||
140
cmd/gf/internal/cmd/genenums/genenums_parser.go
Normal file
140
cmd/gf/internal/cmd/genenums/genenums_parser.go
Normal file
@ -0,0 +1,140 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package genenums
|
||||
|
||||
import (
|
||||
"go/constant"
|
||||
"go/types"
|
||||
"golang.org/x/tools/go/packages"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
const pkgLoadMode = 0xffffff
|
||||
|
||||
type EnumsParser struct {
|
||||
enums []EnumItem
|
||||
parsedPkg map[string]struct{}
|
||||
prefix string
|
||||
}
|
||||
|
||||
type EnumItem struct {
|
||||
Name string
|
||||
Value string
|
||||
Kind constant.Kind // String/Int/Bool/Float/Complex/Unknown
|
||||
Type string // Pkg.ID + TypeName
|
||||
}
|
||||
|
||||
var standardPackages = make(map[string]struct{})
|
||||
|
||||
func init() {
|
||||
stdPackages, err := packages.Load(nil, "std")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, p := range stdPackages {
|
||||
standardPackages[p.ID] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func NewEnumsParser(prefix string) *EnumsParser {
|
||||
return &EnumsParser{
|
||||
enums: make([]EnumItem, 0),
|
||||
parsedPkg: make(map[string]struct{}),
|
||||
prefix: prefix,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *EnumsParser) ParsePackages(pkgs []*packages.Package) {
|
||||
for _, pkg := range pkgs {
|
||||
p.ParsePackage(pkg)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *EnumsParser) ParsePackage(pkg *packages.Package) {
|
||||
// Ignore std packages.
|
||||
if _, ok := standardPackages[pkg.ID]; ok {
|
||||
return
|
||||
}
|
||||
// Ignore pared packages.
|
||||
if _, ok := p.parsedPkg[pkg.ID]; ok {
|
||||
return
|
||||
}
|
||||
p.parsedPkg[pkg.ID] = struct{}{}
|
||||
// Only parse specified prefix.
|
||||
if p.prefix != "" {
|
||||
if !gstr.HasPrefix(pkg.ID, p.prefix) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
scope = pkg.Types.Scope()
|
||||
names = scope.Names()
|
||||
)
|
||||
for _, name := range names {
|
||||
con, ok := scope.Lookup(name).(*types.Const)
|
||||
if !ok {
|
||||
// Only constants can be enums.
|
||||
continue
|
||||
}
|
||||
if !con.Exported() {
|
||||
// Ignore unexported values.
|
||||
continue
|
||||
}
|
||||
|
||||
var enumType = con.Type().String()
|
||||
if !gstr.Contains(enumType, "/") {
|
||||
// Ignore std types.
|
||||
continue
|
||||
}
|
||||
var (
|
||||
enumName = con.Name()
|
||||
enumValue = con.Val().ExactString()
|
||||
enumKind = con.Val().Kind()
|
||||
)
|
||||
if con.Val().Kind() == constant.String {
|
||||
enumValue = constant.StringVal(con.Val())
|
||||
}
|
||||
p.enums = append(p.enums, EnumItem{
|
||||
Name: enumName,
|
||||
Value: enumValue,
|
||||
Type: enumType,
|
||||
Kind: enumKind,
|
||||
})
|
||||
|
||||
}
|
||||
for _, im := range pkg.Imports {
|
||||
p.ParsePackage(im)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *EnumsParser) Export() string {
|
||||
var typeEnumMap = make(map[string][]interface{})
|
||||
for _, enum := range p.enums {
|
||||
if typeEnumMap[enum.Type] == nil {
|
||||
typeEnumMap[enum.Type] = make([]interface{}, 0)
|
||||
}
|
||||
var value interface{}
|
||||
switch enum.Kind {
|
||||
case constant.Int:
|
||||
value = gconv.Int64(enum.Value)
|
||||
case constant.String:
|
||||
value = enum.Value
|
||||
case constant.Float:
|
||||
value = gconv.Float64(enum.Value)
|
||||
case constant.Bool:
|
||||
value = gconv.Bool(enum.Value)
|
||||
default:
|
||||
value = enum.Value
|
||||
}
|
||||
typeEnumMap[enum.Type] = append(typeEnumMap[enum.Type], value)
|
||||
}
|
||||
return gjson.MustEncodeString(typeEnumMap)
|
||||
}
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package genpb
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package genpb
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package genpb
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package genpbentity
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package genservice
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package genservice
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package genservice
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package consts
|
||||
|
||||
const (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package consts
|
||||
|
||||
const TemplateGenDaoIndexContent = `
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package consts
|
||||
|
||||
const TemplateGenDaoDoContent = `
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package consts
|
||||
|
||||
const TemplateGenDaoEntityContent = `
|
||||
|
||||
23
cmd/gf/internal/consts/consts_gen_enums_template.go
Normal file
23
cmd/gf/internal/consts/consts_gen_enums_template.go
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package consts
|
||||
|
||||
const TemplateGenEnums = `
|
||||
// ================================================================================
|
||||
// Code generated by GoFrame CLI tool. DO NOT EDIT.
|
||||
// ================================================================================
|
||||
|
||||
package {PackageName}
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/util/gtag"
|
||||
)
|
||||
|
||||
func init() {
|
||||
gtag.SetGlobalEnums({EnumsJson})
|
||||
}
|
||||
`
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package consts
|
||||
|
||||
const TemplatePbEntityMessageContent = `
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package consts
|
||||
|
||||
const TemplateGenServiceContentHead = `
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package consts
|
||||
|
||||
const TemplateGenServiceLogicContent = `
|
||||
|
||||
@ -1 +1,7 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package packed
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
@ -142,7 +148,7 @@ func (s serviceInstall) IsInstalled() (*serviceInstallAvailablePath, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// getGoPathBinFilePath retrieves ad returns the GOPATH/bin path for binary.
|
||||
// getGoPathBin retrieves ad returns the GOPATH/bin path for binary.
|
||||
func (s serviceInstall) getGoPathBin() string {
|
||||
if goPath := genv.Get(`GOPATH`).String(); goPath != "" {
|
||||
return gfile.Join(goPath, "bin")
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package allyes
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package mlog
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
|
||||
@ -1,14 +1,21 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||
)
|
||||
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@ -795,11 +795,9 @@ func (a *Array) UnmarshalValue(value interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Filter `filter func(value interface{}, index int) bool` filter array, value
|
||||
// means the value of the current element, the index of the current original
|
||||
// color of value, when the custom function returns True, the element will be
|
||||
// filtered, otherwise it will not be filtered, `Filter` function returns a new
|
||||
// array, will not modify the original array.
|
||||
// Filter iterates array and filters elements using custom callback function.
|
||||
// It removes the element from array if callback function `filter` returns true,
|
||||
// it or else does nothing and continues iterating.
|
||||
func (a *Array) Filter(filter func(index int, value interface{}) bool) *Array {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
@ -788,11 +788,9 @@ func (a *IntArray) UnmarshalValue(value interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Filter `filter func(value int, index int) bool` filter array, value
|
||||
// means the value of the current element, the index of the current original
|
||||
// color of value, when the custom function returns True, the element will be
|
||||
// filtered, otherwise it will not be filtered, `Filter` function returns a new
|
||||
// array, will not modify the original array.
|
||||
// Filter iterates array and filters elements using custom callback function.
|
||||
// It removes the element from array if callback function `filter` returns true,
|
||||
// it or else does nothing and continues iterating.
|
||||
func (a *IntArray) Filter(filter func(index int, value int) bool) *IntArray {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
@ -799,11 +799,9 @@ func (a *StrArray) UnmarshalValue(value interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Filter `filter func(value string, index int) bool` filter array, value
|
||||
// means the value of the current element, the index of the current original
|
||||
// color of value, when the custom function returns True, the element will be
|
||||
// filtered, otherwise it will not be filtered, `Filter` function returns a new
|
||||
// array, will not modify the original array.
|
||||
// Filter iterates array and filters elements using custom callback function.
|
||||
// It removes the element from array if callback function `filter` returns true,
|
||||
// it or else does nothing and continues iterating.
|
||||
func (a *StrArray) Filter(filter func(index int, value string) bool) *StrArray {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
@ -761,11 +761,9 @@ func (a *SortedArray) FilterNil() *SortedArray {
|
||||
return a
|
||||
}
|
||||
|
||||
// Filter `filter func(value interface{}, index int) bool` filter array, value
|
||||
// means the value of the current element, the index of the current original
|
||||
// color of value, when the custom function returns True, the element will be
|
||||
// filtered, otherwise it will not be filtered, `Filter` function returns a new
|
||||
// array, will not modify the original array.
|
||||
// Filter iterates array and filters elements using custom callback function.
|
||||
// It removes the element from array if callback function `filter` returns true,
|
||||
// it or else does nothing and continues iterating.
|
||||
func (a *SortedArray) Filter(filter func(index int, value interface{}) bool) *SortedArray {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
@ -709,11 +709,9 @@ func (a *SortedIntArray) UnmarshalValue(value interface{}) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Filter `filter func(value int, index int) bool` filter array, value
|
||||
// means the value of the current element, the index of the current original
|
||||
// color of value, when the custom function returns True, the element will be
|
||||
// filtered, otherwise it will not be filtered, `Filter` function returns a new
|
||||
// array, will not modify the original array.
|
||||
// Filter iterates array and filters elements using custom callback function.
|
||||
// It removes the element from array if callback function `filter` returns true,
|
||||
// it or else does nothing and continues iterating.
|
||||
func (a *SortedIntArray) Filter(filter func(index int, value int) bool) *SortedIntArray {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
@ -722,11 +722,9 @@ func (a *SortedStrArray) UnmarshalValue(value interface{}) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Filter `filter func(value string, index int) bool` filter array, value
|
||||
// means the value of the current element, the index of the current original
|
||||
// color of value, when the custom function returns True, the element will be
|
||||
// filtered, otherwise it will not be filtered, `Filter` function returns a new
|
||||
// array, will not modify the original array.
|
||||
// Filter iterates array and filters elements using custom callback function.
|
||||
// It removes the element from array if callback function `filter` returns true,
|
||||
// it or else does nothing and continues iterating.
|
||||
func (a *SortedStrArray) Filter(filter func(index int, value string) bool) *SortedStrArray {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/apolloconfig/agollo/v4 v4.1.1
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/kubecm/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
k8s.io/api v0.25.2
|
||||
k8s.io/apimachinery v0.25.2
|
||||
k8s.io/client-go v0.25.2
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/nacos/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
github.com/nacos-group/nacos-sdk-go v1.1.2
|
||||
)
|
||||
|
||||
|
||||
@ -3,8 +3,13 @@ module github.com/gogf/gf/contrib/config/polaris/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/polarismesh/polaris-go v1.3.0
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
github.com/polarismesh/polaris-go v1.4.3
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
replace (
|
||||
golang.org/x/net v0.2.0 => golang.org/x/net v0.0.0-20221019024206-cb67ada4b0ad
|
||||
golang.org/x/sys v0.2.0 => golang.org/x/sys v0.0.0-20220906165534-d0df966e6959
|
||||
)
|
||||
|
||||
@ -227,8 +227,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/polarismesh/polaris-go v1.3.0 h1:KZKX//ow4OPPoS5+s7h07ptprg+2AcNVGrN6WakC9QM=
|
||||
github.com/polarismesh/polaris-go v1.3.0/go.mod h1:HsN0ierETIujHpmnnYJ3qkwQw4QGAECuHvBZTDaw1tI=
|
||||
github.com/polarismesh/polaris-go v1.4.3 h1:Ka2ancA4BCLt4pxhEJdRIHMWaj+wkwtw+4AlrSI24c0=
|
||||
github.com/polarismesh/polaris-go v1.4.3/go.mod h1:ymxU5F20Bs99P+jvt5tbLn5guOEt1JmT4i69AOmZSVI=
|
||||
github.com/polarismesh/specification v1.2.1 h1:NcFoinO+aSWIOIyKTAhvEbjaPvZAAm5/DwJAL2FGdXs=
|
||||
github.com/polarismesh/specification v1.2.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||
@ -276,6 +278,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
@ -302,6 +305,7 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
@ -333,8 +337,9 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
|
||||
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@ -364,12 +369,14 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.0.0-20221019024206-cb67ada4b0ad h1:Zx6wVVDwwNJFWXNIvDi7o952w3/1ckSwYk/7eykRmjM=
|
||||
golang.org/x/net v0.0.0-20221019024206-cb67ada4b0ad/go.mod h1:RpDiru2p0u2F0lLpEoqnP2+7xs0ifAuOcJ442g6GU2s=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@ -386,6 +393,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@ -430,11 +438,13 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959 h1:qSa+Hg9oBe6UJXrznE+yYvW51V9UbyIj/nj/KpDigo8=
|
||||
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@ -445,8 +455,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y=
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
|
||||
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
@ -492,8 +503,9 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
|
||||
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
|
||||
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
|
||||
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@ -568,8 +580,8 @@ google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
|
||||
google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ=
|
||||
google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
|
||||
google.golang.org/grpc v1.51.0 h1:E1eGv1FTqoLIdnBCZufiSHgKjlqG6fKFf6pPWtMTh8U=
|
||||
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
@ -583,8 +595,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
43
contrib/drivers/clickhouse/clickhouse_issue_test.go
Normal file
43
contrib/drivers/clickhouse/clickhouse_issue_test.go
Normal file
@ -0,0 +1,43 @@
|
||||
// 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 clickhouse
|
||||
|
||||
import (
|
||||
"github.com/shopspring/decimal"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
func Test_Issue2584(t *testing.T) {
|
||||
type TDecimal struct {
|
||||
F1 *decimal.Decimal `json:"f1"`
|
||||
}
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
p1 = TDecimal{}
|
||||
data1 = g.Map{"f1": gvar.New(1111.111)}
|
||||
err = gconv.Scan(data1, &p1)
|
||||
)
|
||||
t.AssertNil(err)
|
||||
t.Assert(p1.F1, 1111.111)
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
p2 = TDecimal{}
|
||||
data2 = g.Map{"f1": gvar.New("2222.222")}
|
||||
err = gconv.Scan(data2, &p2)
|
||||
)
|
||||
t.AssertNil(err)
|
||||
t.Assert(p2.F1, 2222.222)
|
||||
})
|
||||
}
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.15
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/shopspring/decimal v1.3.1
|
||||
)
|
||||
|
||||
@ -6,5 +6,5 @@ replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
require (
|
||||
gitee.com/chunanyong/dm v1.8.10
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
)
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/denisenkom/go-mssqldb v0.11.0
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -20,6 +20,7 @@ import (
|
||||
"strings"
|
||||
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
@ -285,7 +286,6 @@ ORDER BY a.id,a.colorder`,
|
||||
}
|
||||
fields = make(map[string]*gdb.TableField)
|
||||
for i, m := range result {
|
||||
|
||||
fields[m["Field"].String()] = &gdb.TableField{
|
||||
Index: i,
|
||||
Name: m["Field"].String(),
|
||||
|
||||
@ -256,7 +256,6 @@ func Test_DB_Insert(t *testing.T) {
|
||||
t.Assert(one["PASSPORT"].String(), "t4")
|
||||
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d713c07ad")
|
||||
t.Assert(one["NICKNAME"].String(), "name_4")
|
||||
t.Assert(one["CREATE_TIME"].GTime(), timeNow)
|
||||
|
||||
// batch with Insert
|
||||
timeNow = gtime.Now()
|
||||
@ -286,7 +285,6 @@ func Test_DB_Insert(t *testing.T) {
|
||||
t.Assert(one["PASSPORT"].String(), "t200")
|
||||
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d71qw07ad")
|
||||
t.Assert(one["NICKNAME"].String(), "T200")
|
||||
t.Assert(one["CREATE_TIME"].GTime(), timeNow)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ import (
|
||||
func TestPage(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
db.SetDebug(true)
|
||||
//db.SetDebug(true)
|
||||
result, err := db.Model(table).Page(1, 2).Order("id").All()
|
||||
gtest.Assert(err, nil)
|
||||
fmt.Println("page:1--------", result)
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -128,7 +128,7 @@ func Test_Model_Update_Data_DO(t *testing.T) {
|
||||
func Test_Model_Update_Pointer_Data_DO(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
db.SetDebug(true)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type NN string
|
||||
type Req struct {
|
||||
|
||||
@ -664,3 +664,65 @@ CREATE TABLE %s (
|
||||
t.AssertNil(err3)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/2561
|
||||
func Test_Issue2561(t *testing.T) {
|
||||
table := createTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
g.Meta `orm:"do:true"`
|
||||
Id interface{}
|
||||
Passport interface{}
|
||||
Password interface{}
|
||||
Nickname interface{}
|
||||
CreateTime interface{}
|
||||
}
|
||||
data := g.Slice{
|
||||
User{
|
||||
Id: 1,
|
||||
Passport: "user_1",
|
||||
},
|
||||
User{
|
||||
Id: 2,
|
||||
Password: "pass_2",
|
||||
},
|
||||
User{
|
||||
Id: 3,
|
||||
Password: "pass_3",
|
||||
},
|
||||
}
|
||||
result, err := db.Model(table).Data(data).Insert()
|
||||
t.AssertNil(err)
|
||||
m, _ := result.LastInsertId()
|
||||
t.Assert(m, 3)
|
||||
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 3)
|
||||
|
||||
one, err := db.Model(table).WherePri(1).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one[`id`], `1`)
|
||||
t.Assert(one[`passport`], `user_1`)
|
||||
t.Assert(one[`password`], ``)
|
||||
t.Assert(one[`nickname`], ``)
|
||||
t.Assert(one[`create_time`], ``)
|
||||
|
||||
one, err = db.Model(table).WherePri(2).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one[`id`], `2`)
|
||||
t.Assert(one[`passport`], ``)
|
||||
t.Assert(one[`password`], `pass_2`)
|
||||
t.Assert(one[`nickname`], ``)
|
||||
t.Assert(one[`create_time`], ``)
|
||||
|
||||
one, err = db.Model(table).WherePri(3).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one[`id`], `3`)
|
||||
t.Assert(one[`passport`], ``)
|
||||
t.Assert(one[`password`], `pass_3`)
|
||||
t.Assert(one[`nickname`], ``)
|
||||
t.Assert(one[`create_time`], ``)
|
||||
})
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/oracle/v2
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
github.com/sijms/go-ora/v2 v2.4.20
|
||||
)
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/pgsql/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
github.com/lib/pq v1.10.4
|
||||
)
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/glebarez/go-sqlite v1.17.3
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
go.opentelemetry.io/otel v1.7.0
|
||||
go.opentelemetry.io/otel/trace v1.7.0
|
||||
)
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/etcd/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
go.etcd.io/etcd/client/v3 v3.5.4
|
||||
)
|
||||
|
||||
|
||||
@ -19,10 +19,11 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
updateAtKey = "UpdateAt"
|
||||
serviceTTL = 20 * time.Second
|
||||
serviceUpdateInterval = 10 * time.Second
|
||||
defaultSeparator = "#"
|
||||
updateAtKey = "UpdateAt"
|
||||
serviceTTL = 20 * time.Second
|
||||
serviceUpdateInterval = 10 * time.Second
|
||||
defaultSeparator = "#"
|
||||
defaultEndpointHostPortDelimiter = "-"
|
||||
)
|
||||
|
||||
// Registry implements interface Registry using file.
|
||||
|
||||
@ -108,6 +108,8 @@ func (r *Registry) getServiceByFilePath(filePath string) (gsvc.Service, error) {
|
||||
fileContent = gfile.GetContents(filePath)
|
||||
serviceKey = gstr.Replace(fileName, defaultSeparator, gsvc.DefaultSeparator)
|
||||
)
|
||||
|
||||
serviceKey = gstr.Replace(serviceKey, defaultEndpointHostPortDelimiter, gsvc.EndpointHostPortDelimiter)
|
||||
serviceKey = gsvc.DefaultSeparator + serviceKey
|
||||
return gsvc.NewServiceWithKV(serviceKey, fileContent)
|
||||
}
|
||||
|
||||
@ -58,5 +58,6 @@ func (r *Registry) getServiceFileName(service gsvc.Service) string {
|
||||
func (r *Registry) getServiceKeyForFile(key string) string {
|
||||
key = gstr.Replace(key, gsvc.DefaultSeparator, defaultSeparator)
|
||||
key = gstr.Trim(key, defaultSeparator)
|
||||
key = gstr.Replace(key, gsvc.EndpointHostPortDelimiter, defaultEndpointHostPortDelimiter)
|
||||
return key
|
||||
}
|
||||
|
||||
50
contrib/registry/file/file_z_http_test.go
Normal file
50
contrib/registry/file/file_z_http_test.go
Normal file
@ -0,0 +1,50 @@
|
||||
// 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 file_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/contrib/registry/file/v2"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
)
|
||||
|
||||
var ctx = gctx.GetInitCtx()
|
||||
|
||||
func Test_HTTP_Registry(t *testing.T) {
|
||||
var (
|
||||
svcName = guid.S()
|
||||
dirPath = gfile.Temp(svcName)
|
||||
)
|
||||
defer gfile.Remove(dirPath)
|
||||
gsvc.SetRegistry(file.New(dirPath))
|
||||
|
||||
s := g.Server(svcName)
|
||||
s.BindHandler("/http-registry", func(r *ghttp.Request) {
|
||||
r.Response.Write(svcName)
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
defer s.Shutdown()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://%s", svcName))
|
||||
// GET
|
||||
t.Assert(client.GetContent(ctx, "/http-registry"), svcName)
|
||||
})
|
||||
}
|
||||
@ -2,6 +2,6 @@ module github.com/gogf/gf/contrib/registry/file/v2
|
||||
|
||||
go 1.15
|
||||
|
||||
require github.com/gogf/gf/v2 v2.3.3
|
||||
require github.com/gogf/gf/v2 v2.4.1
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
@ -35,10 +35,10 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"})
|
||||
conf := config.NewDefaultConfiguration([]string{"183.47.111.80:8091"})
|
||||
|
||||
// TTL egt 2*time.Second
|
||||
gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100)))
|
||||
gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(10)))
|
||||
|
||||
s := g.Server(`hello.svc`)
|
||||
s.BindHandler("/", func(r *ghttp.Request) {
|
||||
@ -68,9 +68,9 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"})
|
||||
conf := config.NewDefaultConfiguration([]string{"183.47.111.80:8091"})
|
||||
|
||||
gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100)))
|
||||
gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(10)))
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
res, err := g.Client().Get(gctx.New(), `http://hello.svc/`)
|
||||
|
||||
@ -41,10 +41,10 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"})
|
||||
conf := config.NewDefaultConfiguration([]string{"183.47.111.80:8091"})
|
||||
|
||||
// TTL egt 2*time.Second
|
||||
gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100)))
|
||||
gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(10)))
|
||||
|
||||
s := g.Server(`hello.svc`)
|
||||
s.BindHandler("/", func(r *ghttp.Request) {
|
||||
@ -75,9 +75,9 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
conf := config.NewDefaultConfiguration([]string{"192.168.100.222:8091"})
|
||||
conf := config.NewDefaultConfiguration([]string{"183.47.111.80:8091"})
|
||||
|
||||
gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(100)))
|
||||
gsvc.SetRegistry(polaris.NewRegistryWithConfig(conf, polaris.WithTTL(10)))
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
res, err := g.Client().Get(gctx.New(), `http://hello.svc/`)
|
||||
|
||||
@ -3,8 +3,13 @@ module github.com/gogf/gf/contrib/registry/polaris/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/polarismesh/polaris-go v1.3.0
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
github.com/polarismesh/polaris-go v1.4.3
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
replace (
|
||||
golang.org/x/net v0.2.0 => golang.org/x/net v0.0.0-20221019024206-cb67ada4b0ad
|
||||
golang.org/x/sys v0.2.0 => golang.org/x/sys v0.0.0-20220906165534-d0df966e6959
|
||||
)
|
||||
|
||||
@ -227,8 +227,10 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/polarismesh/polaris-go v1.3.0 h1:KZKX//ow4OPPoS5+s7h07ptprg+2AcNVGrN6WakC9QM=
|
||||
github.com/polarismesh/polaris-go v1.3.0/go.mod h1:HsN0ierETIujHpmnnYJ3qkwQw4QGAECuHvBZTDaw1tI=
|
||||
github.com/polarismesh/polaris-go v1.4.3 h1:Ka2ancA4BCLt4pxhEJdRIHMWaj+wkwtw+4AlrSI24c0=
|
||||
github.com/polarismesh/polaris-go v1.4.3/go.mod h1:ymxU5F20Bs99P+jvt5tbLn5guOEt1JmT4i69AOmZSVI=
|
||||
github.com/polarismesh/specification v1.2.1 h1:NcFoinO+aSWIOIyKTAhvEbjaPvZAAm5/DwJAL2FGdXs=
|
||||
github.com/polarismesh/specification v1.2.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||
@ -276,6 +278,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
@ -302,6 +305,7 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
@ -333,8 +337,9 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
|
||||
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@ -364,12 +369,14 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.0.0-20221019024206-cb67ada4b0ad h1:Zx6wVVDwwNJFWXNIvDi7o952w3/1ckSwYk/7eykRmjM=
|
||||
golang.org/x/net v0.0.0-20221019024206-cb67ada4b0ad/go.mod h1:RpDiru2p0u2F0lLpEoqnP2+7xs0ifAuOcJ442g6GU2s=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@ -386,6 +393,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@ -430,11 +438,13 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60=
|
||||
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959 h1:qSa+Hg9oBe6UJXrznE+yYvW51V9UbyIj/nj/KpDigo8=
|
||||
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@ -445,8 +455,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y=
|
||||
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
|
||||
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
@ -492,8 +503,9 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
|
||||
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
|
||||
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
|
||||
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@ -568,8 +580,8 @@ google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
|
||||
google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ=
|
||||
google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
|
||||
google.golang.org/grpc v1.51.0 h1:E1eGv1FTqoLIdnBCZufiSHgKjlqG6fKFf6pPWtMTh8U=
|
||||
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
@ -583,8 +595,9 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@ -47,12 +47,6 @@ type options struct {
|
||||
// To show service is healthy or not. Default value is True.
|
||||
Healthy bool
|
||||
|
||||
// Deprecated: Use RegisterInstance instead.
|
||||
// Service registration is performed synchronously,
|
||||
// and heartbeat reporting is automatically performed
|
||||
// Heartbeat enable .Not in polaris. Default value is True.
|
||||
Heartbeat bool
|
||||
|
||||
// To show service is isolate or not. Default value is False.
|
||||
Isolate bool
|
||||
|
||||
@ -78,7 +72,6 @@ type Registry struct {
|
||||
opt options
|
||||
provider polaris.ProviderAPI
|
||||
consumer polaris.ConsumerAPI
|
||||
c chan struct{}
|
||||
}
|
||||
|
||||
// WithNamespace with the Namespace option.
|
||||
@ -126,12 +119,6 @@ func WithRetryCount(retryCount int) Option {
|
||||
return func(o *options) { o.RetryCount = retryCount }
|
||||
}
|
||||
|
||||
// WithHeartbeat with the Heartbeat option.
|
||||
// Deprecated remove in v2.4.0
|
||||
func WithHeartbeat(heartbeat bool) Option {
|
||||
return func(o *options) { o.Heartbeat = heartbeat }
|
||||
}
|
||||
|
||||
// WithLogger with the Logger option.
|
||||
func WithLogger(logger glog.ILogger) Option {
|
||||
return func(o *options) { o.Logger = logger }
|
||||
@ -140,13 +127,12 @@ func WithLogger(logger glog.ILogger) Option {
|
||||
// New create a new registry.
|
||||
func New(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opts ...Option) gsvc.Registry {
|
||||
op := options{
|
||||
Namespace: "default",
|
||||
Namespace: gsvc.DefaultNamespace,
|
||||
ServiceToken: "",
|
||||
Protocol: nil,
|
||||
Weight: 0,
|
||||
Priority: 0,
|
||||
Healthy: true,
|
||||
Heartbeat: true,
|
||||
Isolate: false,
|
||||
TTL: 0,
|
||||
Timeout: 0,
|
||||
@ -160,7 +146,6 @@ func New(provider polaris.ProviderAPI, consumer polaris.ConsumerAPI, opts ...Opt
|
||||
opt: op,
|
||||
provider: provider,
|
||||
consumer: consumer,
|
||||
c: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
package polaris
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
@ -28,6 +29,7 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]gsvc.Serv
|
||||
}
|
||||
in.Prefix = service.GetPrefix()
|
||||
}
|
||||
in.Prefix = trimAndReplace(in.Prefix)
|
||||
// get all instances
|
||||
instancesResponse, err := r.consumer.GetAllInstances(&polaris.GetAllInstancesRequest{
|
||||
GetAllInstancesRequest: model.GetAllInstancesRequest{
|
||||
@ -44,7 +46,7 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]gsvc.Serv
|
||||
// Service filter.
|
||||
filteredServices := make([]gsvc.Service, 0)
|
||||
for _, service := range serviceInstances {
|
||||
if in.Prefix != "" && !gstr.HasPrefix(service.GetKey(), in.Prefix) {
|
||||
if in.Prefix != "" && !gstr.HasPrefix(trimAndReplace(service.GetKey()), in.Prefix) {
|
||||
continue
|
||||
}
|
||||
if in.Name != "" && service.GetName() != in.Name {
|
||||
@ -67,8 +69,8 @@ func (r *Registry) Search(ctx context.Context, in gsvc.SearchInput) ([]gsvc.Serv
|
||||
}
|
||||
|
||||
// Watch creates a watcher according to the service name.
|
||||
func (r *Registry) Watch(ctx context.Context, serviceName string) (gsvc.Watcher, error) {
|
||||
return newWatcher(ctx, r.opt.Namespace, serviceName, r.consumer)
|
||||
func (r *Registry) Watch(ctx context.Context, key string) (gsvc.Watcher, error) {
|
||||
return newWatcher(ctx, r.opt.Namespace, trimAndReplace(key), r.consumer)
|
||||
}
|
||||
|
||||
func instancesToServiceInstances(instances []model.Instance) []gsvc.Service {
|
||||
@ -89,11 +91,18 @@ func instanceToServiceInstance(instance model.Instance) gsvc.Service {
|
||||
endpoints = gsvc.NewEndpoints(fmt.Sprintf("%s:%d", instance.GetHost(), instance.GetPort()))
|
||||
)
|
||||
if names != nil && len(names) > 4 {
|
||||
var name bytes.Buffer
|
||||
for i := 3; i < len(names)-1; i++ {
|
||||
name.WriteString(names[i])
|
||||
if i < len(names)-2 {
|
||||
name.WriteString(instanceIDSeparator)
|
||||
}
|
||||
}
|
||||
s = &gsvc.LocalService{
|
||||
Head: names[0],
|
||||
Deployment: names[1],
|
||||
Namespace: names[2],
|
||||
Name: names[3],
|
||||
Name: name.String(),
|
||||
Version: metadata[metadataKeyVersion],
|
||||
Metadata: gconv.Map(metadata),
|
||||
Endpoints: endpoints,
|
||||
@ -111,3 +120,10 @@ func instanceToServiceInstance(instance model.Instance) gsvc.Service {
|
||||
Service: s,
|
||||
}
|
||||
}
|
||||
|
||||
// trimAndReplace trims the prefix and suffix separator and replaces the separator in the middle.
|
||||
func trimAndReplace(key string) string {
|
||||
key = gstr.Trim(key, gsvc.DefaultSeparator)
|
||||
key = gstr.Replace(key, gsvc.DefaultSeparator, instanceIDSeparator)
|
||||
return key
|
||||
}
|
||||
|
||||
@ -8,7 +8,6 @@ package polaris
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/polarismesh/polaris-go"
|
||||
"github.com/polarismesh/polaris-go/pkg/model"
|
||||
@ -25,17 +24,18 @@ func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Ser
|
||||
Service: service,
|
||||
}
|
||||
// Register logic.
|
||||
var (
|
||||
ids = make([]string, 0, len(service.GetEndpoints()))
|
||||
serviceVersion = service.GetVersion()
|
||||
)
|
||||
var ids = make([]string, 0, len(service.GetEndpoints()))
|
||||
for _, endpoint := range service.GetEndpoints() {
|
||||
// medata
|
||||
var rmd map[string]interface{}
|
||||
var (
|
||||
rmd map[string]interface{}
|
||||
serviceName = service.GetPrefix()
|
||||
serviceVersion = service.GetVersion()
|
||||
)
|
||||
if service.GetMetadata().IsEmpty() {
|
||||
rmd = map[string]interface{}{
|
||||
metadataKeyKind: gsvc.DefaultProtocol,
|
||||
metadataKeyVersion: service.GetVersion(),
|
||||
metadataKeyVersion: serviceVersion,
|
||||
}
|
||||
} else {
|
||||
rmd = make(map[string]interface{}, len(service.GetMetadata())+2)
|
||||
@ -53,7 +53,7 @@ func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Ser
|
||||
registeredService, err := r.provider.RegisterInstance(
|
||||
&polaris.InstanceRegisterRequest{
|
||||
InstanceRegisterRequest: model.InstanceRegisterRequest{
|
||||
Service: service.GetPrefix(),
|
||||
Service: serviceName,
|
||||
ServiceToken: r.opt.ServiceToken,
|
||||
Namespace: r.opt.Namespace,
|
||||
Host: endpoint.Host(),
|
||||
@ -73,9 +73,6 @@ func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Ser
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.opt.Heartbeat {
|
||||
// r.doHeartBeat(ctx, registeredService.InstanceID, service, endpoint)
|
||||
}
|
||||
ids = append(ids, registeredService.InstanceID)
|
||||
}
|
||||
// need to set InstanceID for Deregister
|
||||
@ -85,7 +82,6 @@ func (r *Registry) Register(ctx context.Context, service gsvc.Service) (gsvc.Ser
|
||||
|
||||
// Deregister the registration.
|
||||
func (r *Registry) Deregister(ctx context.Context, service gsvc.Service) error {
|
||||
// r.c <- struct{}{}
|
||||
var (
|
||||
err error
|
||||
split = gstr.Split(service.(*Service).ID, instanceIDSeparator)
|
||||
@ -112,37 +108,3 @@ func (r *Registry) Deregister(ctx context.Context, service gsvc.Service) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deprecated .
|
||||
func (r *Registry) doHeartBeat(ctx context.Context, instanceID string, service gsvc.Service, endpoint gsvc.Endpoint) {
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second * time.Duration(r.opt.TTL))
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
err := r.provider.Heartbeat(&polaris.InstanceHeartbeatRequest{
|
||||
InstanceHeartbeatRequest: model.InstanceHeartbeatRequest{
|
||||
Service: service.GetPrefix(),
|
||||
Namespace: r.opt.Namespace,
|
||||
Host: endpoint.Host(),
|
||||
Port: endpoint.Port(),
|
||||
ServiceToken: r.opt.ServiceToken,
|
||||
InstanceID: instanceID,
|
||||
Timeout: &r.opt.Timeout,
|
||||
RetryCount: &r.opt.RetryCount,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
r.opt.Logger.Error(ctx, err.Error())
|
||||
continue
|
||||
}
|
||||
r.opt.Logger.Debug(ctx, "heartbeat success")
|
||||
case <-r.c:
|
||||
r.opt.Logger.Debug(ctx, "stop heartbeat")
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@ -9,9 +9,10 @@ package polaris
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/polarismesh/polaris-go"
|
||||
"github.com/polarismesh/polaris-go/pkg/model"
|
||||
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
)
|
||||
|
||||
// Watcher is a service watcher.
|
||||
@ -24,12 +25,12 @@ type Watcher struct {
|
||||
ServiceInstances []gsvc.Service
|
||||
}
|
||||
|
||||
func newWatcher(ctx context.Context, namespace string, serviceName string, consumer polaris.ConsumerAPI) (*Watcher, error) {
|
||||
func newWatcher(ctx context.Context, namespace string, key string, consumer polaris.ConsumerAPI) (*Watcher, error) {
|
||||
watchServiceResponse, err := consumer.WatchService(&polaris.WatchServiceRequest{
|
||||
WatchServiceRequest: model.WatchServiceRequest{
|
||||
Key: model.ServiceKey{
|
||||
Namespace: namespace,
|
||||
Service: serviceName,
|
||||
Service: key,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -39,7 +40,7 @@ func newWatcher(ctx context.Context, namespace string, serviceName string, consu
|
||||
|
||||
w := &Watcher{
|
||||
Namespace: namespace,
|
||||
ServiceName: serviceName,
|
||||
ServiceName: key,
|
||||
Channel: watchServiceResponse.EventChannel,
|
||||
ServiceInstances: instancesToServiceInstances(watchServiceResponse.GetAllInstancesResp.GetInstances()),
|
||||
}
|
||||
|
||||
@ -8,18 +8,24 @@ package polaris
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/polarismesh/polaris-go/api"
|
||||
"github.com/polarismesh/polaris-go/pkg/config"
|
||||
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
)
|
||||
|
||||
// TestRegistry TestRegistryManyService
|
||||
func TestRegistry(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,
|
||||
@ -27,8 +33,6 @@ func TestRegistry(t *testing.T) {
|
||||
WithTTL(100),
|
||||
)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-0-tcp",
|
||||
Version: "test",
|
||||
@ -36,13 +40,12 @@ func TestRegistry(t *testing.T) {
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
s, err := r.Register(ctx, svc)
|
||||
s, err := r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Deregister(ctx, s)
|
||||
if err != nil {
|
||||
if err = r.Deregister(context.Background(), s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -50,6 +53,11 @@ func TestRegistry(t *testing.T) {
|
||||
// TestRegistryMany TestRegistryManyService
|
||||
func TestRegistryMany(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-many/backup")
|
||||
if err := api.SetLoggersDir(os.TempDir() + "/polaris-registry-many/log"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := NewWithConfig(
|
||||
conf,
|
||||
@ -91,18 +99,15 @@ func TestRegistryMany(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Deregister(context.Background(), s0)
|
||||
if err != nil {
|
||||
if err = r.Deregister(context.Background(), s0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Deregister(context.Background(), s1)
|
||||
if err != nil {
|
||||
if err = r.Deregister(context.Background(), s1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = r.Deregister(context.Background(), s2)
|
||||
if err != nil {
|
||||
if err = r.Deregister(context.Background(), s2); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -110,6 +115,11 @@ func TestRegistryMany(t *testing.T) {
|
||||
// TestGetService Test GetService
|
||||
func TestGetService(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")
|
||||
if err := api.SetLoggersDir(os.TempDir() + "/polaris-get-service/log"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
r := NewWithConfig(
|
||||
conf,
|
||||
@ -117,8 +127,6 @@ func TestGetService(t *testing.T) {
|
||||
WithTTL(100),
|
||||
)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-4-tcp",
|
||||
Version: "test",
|
||||
@ -126,12 +134,12 @@ func TestGetService(t *testing.T) {
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
}
|
||||
|
||||
s, err := r.Register(ctx, svc)
|
||||
s, err := r.Register(context.Background(), svc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(time.Second * 1)
|
||||
serviceInstances, err := r.Search(ctx, gsvc.SearchInput{
|
||||
serviceInstances, err := r.Search(context.Background(), gsvc.SearchInput{
|
||||
Prefix: s.GetPrefix(),
|
||||
Name: svc.Name,
|
||||
Version: svc.Version,
|
||||
@ -141,11 +149,10 @@ func TestGetService(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, instance := range serviceInstances {
|
||||
g.Log().Info(ctx, instance)
|
||||
t.Log(instance)
|
||||
}
|
||||
|
||||
err = r.Deregister(ctx, s)
|
||||
if err != nil {
|
||||
if err = r.Deregister(context.Background(), s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -153,17 +160,19 @@ func TestGetService(t *testing.T) {
|
||||
// TestWatch Test Watch
|
||||
func TestWatch(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),
|
||||
)
|
||||
|
||||
ctx := gctx.New()
|
||||
|
||||
svc := &gsvc.LocalService{
|
||||
Name: "goframe-provider-4-tcp",
|
||||
Name: "goframe-provider-5-tcp",
|
||||
Version: "test",
|
||||
Metadata: map[string]interface{}{"app": "goframe", gsvc.MDProtocol: "tcp"},
|
||||
Endpoints: gsvc.NewEndpoints("127.0.0.1:9000"),
|
||||
@ -192,11 +201,10 @@ func TestWatch(t *testing.T) {
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output one instance
|
||||
g.Log().Info(ctx, "Register Proceed service: ", instance)
|
||||
t.Log("Register Proceed service: ", instance)
|
||||
}
|
||||
|
||||
err = r.Deregister(context.Background(), s1)
|
||||
if err != nil {
|
||||
if err = r.Deregister(context.Background(), s1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -207,16 +215,48 @@ func TestWatch(t *testing.T) {
|
||||
}
|
||||
for _, instance := range next {
|
||||
// it will output nothing
|
||||
g.Log().Info(ctx, "Deregister Proceed service: ", instance)
|
||||
t.Log("Deregister Proceed service: ", instance)
|
||||
}
|
||||
|
||||
err = watch.Close()
|
||||
if err != nil {
|
||||
if err = watch.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = watch.Proceed()
|
||||
if err == nil {
|
||||
if _, err = watch.Proceed(); err == nil {
|
||||
// if nil, stop failed
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
// BenchmarkRegister
|
||||
func BenchmarkRegister(b *testing.B) {
|
||||
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)
|
||||
}
|
||||
|
||||
if err = r.Deregister(context.Background(), s); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.15
|
||||
|
||||
require (
|
||||
github.com/go-zookeeper/zk v1.0.3
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.1
|
||||
golang.org/x/sync v0.1.0
|
||||
)
|
||||
|
||||
|
||||
@ -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.3.3
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.4.1
|
||||
github.com/gogf/gf/v2 v2.4.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
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
package grpcx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
@ -25,6 +26,7 @@ import (
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// GrpcServer is the server for GRPC protocol.
|
||||
@ -104,19 +106,19 @@ func (s *GrpcServer) Run() {
|
||||
// Create listener to bind listening ip and port.
|
||||
s.listener, err = net.Listen("tcp", s.config.Address)
|
||||
if err != nil {
|
||||
s.config.Logger.Fatalf(ctx, `%+v`, err)
|
||||
s.Logger().Fatalf(ctx, `%+v`, err)
|
||||
}
|
||||
|
||||
// Start listening.
|
||||
go func() {
|
||||
if err = s.Server.Serve(s.listener); err != nil {
|
||||
s.config.Logger.Fatalf(ctx, `%+v`, err)
|
||||
s.Logger().Fatalf(ctx, `%+v`, err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Service register.
|
||||
s.doServiceRegister()
|
||||
s.config.Logger.Infof(
|
||||
s.Logger().Infof(
|
||||
ctx,
|
||||
"pid[%d]: grpc server started listening on [%s]",
|
||||
gproc.Pid(), s.GetListenedAddress(),
|
||||
@ -147,7 +149,7 @@ func (s *GrpcServer) doSignalListen() {
|
||||
syscall.SIGKILL,
|
||||
syscall.SIGTERM,
|
||||
syscall.SIGABRT:
|
||||
s.config.Logger.Infof(ctx, "signal received: %s, gracefully shutting down", sig.String())
|
||||
s.Logger().Infof(ctx, "signal received: %s, gracefully shutting down", sig.String())
|
||||
s.doServiceDeregister()
|
||||
time.Sleep(time.Second)
|
||||
s.Stop()
|
||||
@ -156,6 +158,11 @@ func (s *GrpcServer) doSignalListen() {
|
||||
}
|
||||
}
|
||||
|
||||
// Logger is alias of GetLogger.
|
||||
func (s *GrpcServer) Logger() *glog.Logger {
|
||||
return s.config.Logger
|
||||
}
|
||||
|
||||
// doServiceRegister registers current service to Registry.
|
||||
func (s *GrpcServer) doServiceRegister() {
|
||||
if s.registrar == nil {
|
||||
@ -176,15 +183,19 @@ func (s *GrpcServer) doServiceRegister() {
|
||||
for i, service := range s.services {
|
||||
service = &gsvc.LocalService{
|
||||
Name: service.GetName(),
|
||||
Endpoints: s.calculateListenedEndpoints(),
|
||||
Endpoints: s.calculateListenedEndpoints(ctx),
|
||||
Metadata: service.GetMetadata(),
|
||||
}
|
||||
service.GetMetadata().Sets(gsvc.Metadata{
|
||||
gsvc.MDProtocol: protocol,
|
||||
})
|
||||
s.config.Logger.Debugf(ctx, `service register: %+v`, service)
|
||||
s.Logger().Debugf(ctx, `service register: %+v`, service)
|
||||
if len(service.GetEndpoints()) == 0 {
|
||||
s.Logger().Warningf(ctx, `no endpoints found to register service, abort service registering`)
|
||||
return
|
||||
}
|
||||
if service, err = s.registrar.Register(ctx, service); err != nil {
|
||||
s.config.Logger.Fatalf(ctx, `%+v`, err)
|
||||
s.Logger().Fatalf(ctx, `%+v`, err)
|
||||
}
|
||||
s.services[i] = service
|
||||
}
|
||||
@ -197,9 +208,9 @@ func (s *GrpcServer) doServiceDeregister() {
|
||||
}
|
||||
var ctx = gctx.GetInitCtx()
|
||||
for _, service := range s.services {
|
||||
s.config.Logger.Debugf(ctx, `service deregister: %+v`, service)
|
||||
s.Logger().Debugf(ctx, `service deregister: %+v`, service)
|
||||
if err := s.registrar.Deregister(ctx, service); err != nil {
|
||||
s.config.Logger.Errorf(ctx, `%+v`, err)
|
||||
s.Logger().Errorf(ctx, `%+v`, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -249,22 +260,59 @@ func (s *GrpcServer) GetListenedPort() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (s *GrpcServer) calculateListenedEndpoints() gsvc.Endpoints {
|
||||
func (s *GrpcServer) calculateListenedEndpoints(ctx context.Context) gsvc.Endpoints {
|
||||
var (
|
||||
address = s.config.Address
|
||||
endpoints = make(gsvc.Endpoints, 0)
|
||||
listenedPort = s.GetListenedPort()
|
||||
listenedIps []string
|
||||
configAddr = s.config.Address
|
||||
endpoints = make(gsvc.Endpoints, 0)
|
||||
)
|
||||
var addrArray = gstr.Split(address, ":")
|
||||
switch addrArray[0] {
|
||||
case "0.0.0.0", "":
|
||||
listenedIps = []string{gipv4.MustGetIntranetIp()}
|
||||
default:
|
||||
listenedIps = []string{addrArray[0]}
|
||||
}
|
||||
for _, ip := range listenedIps {
|
||||
endpoints = append(endpoints, gsvc.NewEndpoint(fmt.Sprintf(`%s:%d`, ip, listenedPort)))
|
||||
for _, address := range gstr.SplitAndTrim(configAddr, ",") {
|
||||
var (
|
||||
addrArray = gstr.Split(address, ":")
|
||||
listenedIps []string
|
||||
listenedPorts []int
|
||||
)
|
||||
// IPs.
|
||||
switch addrArray[0] {
|
||||
case "127.0.0.1":
|
||||
// Nothing to do.
|
||||
case "0.0.0.0", "":
|
||||
intranetIps, err := gipv4.GetIntranetIpArray()
|
||||
if err != nil {
|
||||
s.Logger().Errorf(ctx, `error retrieving intranet ip: %+v`, err)
|
||||
return nil
|
||||
}
|
||||
// If no intranet ips found, it uses all ips that can be retrieved,
|
||||
// it may include internet ip.
|
||||
if len(intranetIps) == 0 {
|
||||
allIps, err := gipv4.GetIpArray()
|
||||
if err != nil {
|
||||
s.Logger().Errorf(ctx, `error retrieving ip from current node: %+v`, err)
|
||||
return nil
|
||||
}
|
||||
s.Logger().Noticef(
|
||||
ctx,
|
||||
`no intranet ip found, using internet ip to register service: %v`,
|
||||
allIps,
|
||||
)
|
||||
listenedIps = allIps
|
||||
break
|
||||
}
|
||||
listenedIps = intranetIps
|
||||
default:
|
||||
listenedIps = []string{addrArray[0]}
|
||||
}
|
||||
// Ports.
|
||||
switch addrArray[1] {
|
||||
case "0":
|
||||
listenedPorts = []int{s.GetListenedPort()}
|
||||
default:
|
||||
listenedPorts = []int{gconv.Int(addrArray[1])}
|
||||
}
|
||||
for _, ip := range listenedIps {
|
||||
for _, port := range listenedPorts {
|
||||
endpoints = append(endpoints, gsvc.NewEndpoint(fmt.Sprintf(`%s:%d`, ip, port)))
|
||||
}
|
||||
}
|
||||
}
|
||||
return endpoints
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/jaeger/v2
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.3.3
|
||||
github.com/gogf/gf/v2 v2.4.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
|
||||
|
||||
@ -14,6 +14,8 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/container/gset"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
@ -389,6 +391,29 @@ func (c *Core) Save(ctx context.Context, table string, data interface{}, batch .
|
||||
return c.Model(table).Ctx(ctx).Data(data).Save()
|
||||
}
|
||||
|
||||
func (c *Core) fieldsToSequence(ctx context.Context, table string, fields []string) ([]string, error) {
|
||||
var (
|
||||
fieldSet = gset.NewStrSetFrom(fields)
|
||||
fieldsResultInSequence = make([]string, 0)
|
||||
tableFields, err = c.db.TableFields(ctx, table)
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Sort the fields in order.
|
||||
var fieldsOfTableInSequence = make([]string, len(tableFields))
|
||||
for _, field := range tableFields {
|
||||
fieldsOfTableInSequence[field.Index] = field.Name
|
||||
}
|
||||
// Sort the input fields.
|
||||
for _, fieldName := range fieldsOfTableInSequence {
|
||||
if fieldSet.Contains(fieldName) {
|
||||
fieldsResultInSequence = append(fieldsResultInSequence, fieldName)
|
||||
}
|
||||
}
|
||||
return fieldsResultInSequence, nil
|
||||
}
|
||||
|
||||
// DoInsert inserts or updates data forF given table.
|
||||
// This function is usually used for custom interface definition, you do not need call it manually.
|
||||
// The parameter `data` can be type of map/gmap/struct/*struct/[]map/[]struct, etc.
|
||||
@ -408,9 +433,50 @@ func (c *Core) DoInsert(ctx context.Context, link Link, table string, list List,
|
||||
params []interface{} // Values that will be committed to underlying database driver.
|
||||
onDuplicateStr string // onDuplicateStr is used in "ON DUPLICATE KEY UPDATE" statement.
|
||||
)
|
||||
// Handle the field names and placeholders.
|
||||
for k := range list[0] {
|
||||
keys = append(keys, k)
|
||||
// Group the list by fields. Different fields to different list.
|
||||
// It here uses ListMap to keep sequence for data inserting.
|
||||
var keyListMap = gmap.NewListMap()
|
||||
for _, item := range list {
|
||||
var (
|
||||
tmpKeys = make([]string, 0)
|
||||
tmpKeysInSequenceStr string
|
||||
)
|
||||
for k := range item {
|
||||
tmpKeys = append(tmpKeys, k)
|
||||
}
|
||||
keys, err = c.fieldsToSequence(ctx, table, tmpKeys)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tmpKeysInSequenceStr = gstr.Join(keys, ",")
|
||||
|
||||
if !keyListMap.Contains(tmpKeysInSequenceStr) {
|
||||
keyListMap.Set(tmpKeysInSequenceStr, make(List, 0))
|
||||
}
|
||||
tmpKeysInSequenceList := keyListMap.Get(tmpKeysInSequenceStr).(List)
|
||||
tmpKeysInSequenceList = append(tmpKeysInSequenceList, item)
|
||||
keyListMap.Set(tmpKeysInSequenceStr, tmpKeysInSequenceList)
|
||||
}
|
||||
if keyListMap.Size() > 1 {
|
||||
var (
|
||||
tmpResult sql.Result
|
||||
sqlResult SqlResult
|
||||
rowsAffected int64
|
||||
)
|
||||
keyListMap.Iterator(func(key, value interface{}) bool {
|
||||
tmpResult, err = c.DoInsert(ctx, link, table, value.(List), option)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
rowsAffected, err = tmpResult.RowsAffected()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
sqlResult.Result = tmpResult
|
||||
sqlResult.Affected += rowsAffected
|
||||
return true
|
||||
})
|
||||
return &sqlResult, nil
|
||||
}
|
||||
// Prepare the batch result pointer.
|
||||
var (
|
||||
@ -571,7 +637,20 @@ func (c *Core) DoUpdate(ctx context.Context, link Link, table string, data inter
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range dataMap {
|
||||
// Sort the data keys in sequence of table fields.
|
||||
var (
|
||||
dataKeys = make([]string, 0)
|
||||
keysInSequence = make([]string, 0)
|
||||
)
|
||||
for k := range dataMap {
|
||||
dataKeys = append(dataKeys, k)
|
||||
}
|
||||
keysInSequence, err = c.fieldsToSequence(ctx, table, dataKeys)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, k := range keysInSequence {
|
||||
v := dataMap[k]
|
||||
switch value := v.(type) {
|
||||
case *Counter:
|
||||
counterHandler(k, *value)
|
||||
|
||||
@ -10,11 +10,12 @@ package gdb
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"reflect"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user