mirror of
https://gitee.com/johng/gf
synced 2026-06-08 02:27:42 +08:00
Compare commits
45 Commits
v2.7.2
...
contrib/dr
| Author | SHA1 | Date | |
|---|---|---|---|
| 79451e4624 | |||
| a716c6bfab | |||
| 5aa321dbde | |||
| 3f2b1cb329 | |||
| ab2c3b02ac | |||
| 76783fd72b | |||
| a1ce97ec9b | |||
| c13004e230 | |||
| 9af8393758 | |||
| e15b543a5b | |||
| 8a1c97f518 | |||
| d8e3e9d713 | |||
| 777c2e7117 | |||
| c4327f62e7 | |||
| fd33dcb97b | |||
| d8b06d056e | |||
| e186eab1a5 | |||
| 6a99931798 | |||
| 4ee5bf5c45 | |||
| e4669387b5 | |||
| 0e471eab38 | |||
| 3d63ebfe81 | |||
| 9b318bb57f | |||
| 6b3fb607cf | |||
| bb9a3b83eb | |||
| baea1c7a7a | |||
| 1b4ebc0812 | |||
| 803cb5a0bc | |||
| 448df14860 | |||
| 467a5c1093 | |||
| 26d2a98fb1 | |||
| 6e5ce98d23 | |||
| a6c361dcf7 | |||
| dc8bb809a8 | |||
| 9143b26182 | |||
| cd2d51ea30 | |||
| 144ad5f263 | |||
| 4fdafa4517 | |||
| ba322ba0ac | |||
| 559ae0e77e | |||
| 3e54839aa8 | |||
| 2565bb3d07 | |||
| 54423b6d84 | |||
| c3cfc01cf6 | |||
| 31a6ae2a19 |
34
.github/PULL_REQUEST_TEMPLATE.MD
vendored
34
.github/PULL_REQUEST_TEMPLATE.MD
vendored
@ -1,22 +1,44 @@
|
||||
**Please ensure you adhere to every item in this list.**
|
||||
+ The PR title is formatted as follows: `os/gtime: fixed time zone issues`
|
||||
+ The package name goes before the colon
|
||||
+ The PR title is formatted as follows: `<type>[optional scope]: <description>` For example, `fix(os/gtime): fix time zone issue`
|
||||
+ `<type>` is mandatory and can be one of `fix`, `feat`, `build`, `ci`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`
|
||||
+ fix: Used when a bug has been fixed.
|
||||
+ feat: Used when a new feature has been added.
|
||||
+ build: Used for modifications to the project build system, such as changes to dependencies, external interfaces, or upgrading Node version.
|
||||
+ ci: Used for modifications to continuous integration processes, such as changes to Travis, Jenkins workflow configurations.
|
||||
+ docs: Used for modifications to documentation, such as changes to README files, API documentation, etc.
|
||||
+ style: Used for changes to code style, such as adjustments to indentation, spaces, blank lines, etc.
|
||||
+ refactor: Used for code refactoring, such as changes to code structure, variable names, function names, without altering functionality.
|
||||
+ perf: Used for performance optimization, such as improving code performance, reducing memory usage, etc.
|
||||
+ test: Used for modifications to test cases, such as adding, deleting, or modifying test cases for code.
|
||||
+ chore: Used for modifications to non-business-related code, such as changes to build processes or tool configurations.
|
||||
+ After `<type>`, specify the affected package name or scope in parentheses, for example, `(os/gtime)`.
|
||||
+ The part after the colon uses the verb tense + phrase that completes the blank in
|
||||
+ Lowercase verb after the colon
|
||||
+ No trailing period
|
||||
+ Keep the title as short as possible. ideally under 76 characters or shorter
|
||||
+ Title not Markdown
|
||||
+ [Reference Documentation](https://www.conventionalcommits.org/en/v1.0.0/)
|
||||
+ If there is a corresponding issue, add either `Fixes #1234` or `Updates #1234`
|
||||
(the latter if this is not a complete fix) to this comment
|
||||
+ Delete these instructions once you have read and applied them
|
||||
|
||||
**提交前请遵守每个事项,感谢!**
|
||||
+ PR 标题格式如下:`os/gtime: fixed time zone issues`
|
||||
+ 冒号前是包名
|
||||
+ PR 标题格式如下:`<类型>[可选 范围]: <描述>` 例如 `fix(os/gtime): fix time zone issue`
|
||||
+ `<类型>`是必须的,可以是 `fix`、`feat`、`build`、`ci`、`docs`、`style`、`refactor`、`perf`、`test`、`chore` 中的一个
|
||||
+ fix: 用于修复了一个 bug
|
||||
+ feat: 用于新增了一个功能
|
||||
+ build: 用于修改项目构建系统,例如修改依赖库、外部接口或者升级 Node 版本等
|
||||
+ ci: 用于修改持续集成流程,例如修改 Travis、Jenkins 等工作流配置
|
||||
+ docs: 用于修改文档,例如修改 README 文件、API 文档等
|
||||
+ style: 用于修改代码的样式,例如调整缩进、空格、空行等
|
||||
+ refactor: 用于重构代码,例如修改代码结构、变量名、函数名等但不修改功能逻辑
|
||||
+ perf: 用于优化性能,例如提升代码的性能、减少内存占用等
|
||||
+ test: 用于修改测试用例,例如添加、删除、修改代码的测试用例等
|
||||
+ chore: 用于对非业务性代码进行修改,例如修改构建流程或者工具配置等
|
||||
+ `<类型>`后在括号中填写受影响的包名或范围,例如 `(os/gtime)`
|
||||
+ 冒号后使用动词时态 + 短语
|
||||
+ 冒号后的动词小写
|
||||
+ 不要有结尾句号
|
||||
+ 标题尽量保持简短,最好在 76 个字符或更短
|
||||
+ 标题不要使用 Markdown
|
||||
+ [参考文档](https://www.conventionalcommits.org/zh-hans/v1.0.0/)
|
||||
+ 如果有对应的 issue,请在此评论中添加 `Fixes #1234`,如果不是完全修复则添加 `Updates #1234`
|
||||
+ 应用这些规则后删除所有的说明
|
||||
|
||||
13
.github/workflows/ci-main.sh
vendored
13
.github/workflows/ci-main.sh
vendored
@ -7,23 +7,24 @@ for file in `find . -name go.mod`; do
|
||||
dirpath=$(dirname $file)
|
||||
echo $dirpath
|
||||
|
||||
# ignore mssql tests as its docker service failed
|
||||
# TODO remove this ignoring codes after the mssql docker service OK
|
||||
if [ "mssql" = $(basename $dirpath) ]; then
|
||||
continue 1
|
||||
fi
|
||||
|
||||
if [[ $file =~ "/testdata/" ]]; then
|
||||
echo "ignore testdata path $file"
|
||||
continue 1
|
||||
fi
|
||||
|
||||
# package kuhecm needs golang >= v1.19
|
||||
# package kuhecm was moved to sub ci procedure.
|
||||
if [ "kubecm" = $(basename $dirpath) ]; then
|
||||
continue 1
|
||||
if ! go version|grep -qE "go1.19|go1.[2-9][0-9]"; then
|
||||
echo "ignore kubecm as go version: $(go version)"
|
||||
continue 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# package consul needs golang >= v1.19
|
||||
if [ "consul" = $(basename $dirpath) ]; then
|
||||
continue 1
|
||||
if ! go version|grep -qE "go1.19|go1.[2-9][0-9]"; then
|
||||
echo "ignore consul as go version: $(go version)"
|
||||
continue 1
|
||||
|
||||
41
.github/workflows/ci-main.yml
vendored
41
.github/workflows/ci-main.yml
vendored
@ -58,6 +58,11 @@ jobs:
|
||||
- 6379:6379
|
||||
|
||||
# MySQL backend server.
|
||||
# docker run -d --name mysql \
|
||||
# -p 3306:3306 \
|
||||
# -e MYSQL_DATABASE=test \
|
||||
# -e MYSQL_ROOT_PASSWORD=12345678 \
|
||||
# loads/mysql:5.7
|
||||
mysql:
|
||||
image: loads/mysql:5.7
|
||||
env:
|
||||
@ -108,22 +113,24 @@ jobs:
|
||||
# -e MSSQL_USER=root \
|
||||
# -e MSSQL_PASSWORD=LoremIpsum86 \
|
||||
# loads/mssqldocker:14.0.3391.2
|
||||
mssql:
|
||||
image: loads/mssqldocker:14.0.3391.2
|
||||
env:
|
||||
ACCEPT_EULA: Y
|
||||
SA_PASSWORD: LoremIpsum86
|
||||
MSSQL_DB: test
|
||||
MSSQL_USER: root
|
||||
MSSQL_PASSWORD: LoremIpsum86
|
||||
ports:
|
||||
- 1433:1433
|
||||
options: >-
|
||||
--health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P LoremIpsum86 -l 30 -Q \"SELECT 1\" || exit 1"
|
||||
--health-start-period 10s
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 10
|
||||
|
||||
# TODO mssql docker failed, will be enabled later after it is OK in github action.
|
||||
# mssql:
|
||||
# image: loads/mssqldocker:14.0.3391.2
|
||||
# env:
|
||||
# ACCEPT_EULA: Y
|
||||
# SA_PASSWORD: LoremIpsum86
|
||||
# MSSQL_DB: test
|
||||
# MSSQL_USER: root
|
||||
# MSSQL_PASSWORD: LoremIpsum86
|
||||
# ports:
|
||||
# - 1433:1433
|
||||
# options: >-
|
||||
# --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P LoremIpsum86 -l 30 -Q \"SELECT 1\" || exit 1"
|
||||
# --health-start-period 10s
|
||||
# --health-interval 10s
|
||||
# --health-timeout 5s
|
||||
# --health-retries 10
|
||||
|
||||
# ClickHouse backend server.
|
||||
# docker run -d --name clickhouse \
|
||||
@ -185,7 +192,7 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ "1.18", "1.19", "1.20", "1.21", "1.22" ]
|
||||
go-version: [ "1.18", "1.19", "1.20", "1.21", "1.22", "1.23" ]
|
||||
goarch: [ "386", "amd64" ]
|
||||
|
||||
steps:
|
||||
|
||||
2
.github/workflows/ci-sub.yml
vendored
2
.github/workflows/ci-sub.yml
vendored
@ -37,7 +37,7 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ "1.18", "1.19", "1.20", "1.22" ]
|
||||
go-version: [ "1.18", "1.19", "1.20", "1.22", "1.23" ]
|
||||
goarch: [ "386", "amd64" ]
|
||||
|
||||
steps:
|
||||
|
||||
4
.github/workflows/golangci-lint.yml
vendored
4
.github/workflows/golangci-lint.yml
vendored
@ -36,7 +36,7 @@ jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ '1.18','1.19','1.20','1.21.4','1.22' ]
|
||||
go-version: [ '1.18','1.19','1.20','1.21.4','1.22','1.23' ]
|
||||
name: golangci-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@ -50,5 +50,5 @@ jobs:
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.58.2
|
||||
version: v1.60.1
|
||||
args: --timeout 3m0s
|
||||
|
||||
53
.github/workflows/sonarcloud.yaml
vendored
Normal file
53
.github/workflows/sonarcloud.yaml
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
name: Sonarcloud Scan
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Weekly on Saturdays.
|
||||
- cron: '30 1 * * 6'
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
# Declare default permissions as read only.
|
||||
permissions: read-all
|
||||
|
||||
jobs:
|
||||
analysis:
|
||||
name: Scorecards analysis
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
# Needed to upload the results to code-scanning dashboard.
|
||||
security-events: write
|
||||
# Used to receive a badge. (Upcoming feature)
|
||||
id-token: write
|
||||
# Needs for private repositories.
|
||||
contents: read
|
||||
actions: read
|
||||
|
||||
steps:
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
publish_results: true
|
||||
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
retention-days: 5
|
||||
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
@ -125,7 +125,7 @@ linters-settings:
|
||||
# Checks the number of lines in a function.
|
||||
# If lower than 0, disable the check.
|
||||
# Default: 60
|
||||
lines: 330
|
||||
lines: 340
|
||||
# Checks the number of statements in a function.
|
||||
# If lower than 0, disable the check.
|
||||
# Default: 40
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
.DEFAULT_GOAL := pack
|
||||
|
||||
pack: pack.template-single pack.template-mono pack.template-mono-app
|
||||
|
||||
@ -17,6 +18,9 @@ pack.template-mono:
|
||||
@cd temp && gf pack template-mono ../internal/packed/template-mono.go -n=packed -y
|
||||
@rm -fr temp
|
||||
|
||||
# Note:
|
||||
# command `sed` only works on MacOS.
|
||||
# use `grep -irl 'template-single' temp| xargs sed -i'' -e 's/template-single/template-mono-app/g'` on other platforms.
|
||||
pack.template-mono-app:
|
||||
@rm -fr temp
|
||||
@mkdir temp || exit 0
|
||||
@ -27,6 +31,6 @@ pack.template-mono-app:
|
||||
@rm -fr temp/template-mono-app/.gitignore
|
||||
@rm -fr temp/template-mono-app/go.mod
|
||||
@rm -fr temp/template-mono-app/go.sum
|
||||
@sed -i 's/template-single/template-mono-app/g' temp/template-mono-app/main.go
|
||||
@grep -irl 'template-single' temp| xargs sed -i '' -e 's/template-single/template-mono-app/g'
|
||||
@cd temp && gf pack template-mono-app ../internal/packed/template-mono-app.go -n=packed -y
|
||||
@rm -fr temp
|
||||
@ -3,14 +3,13 @@ module github.com/gogf/gf/cmd/gf/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.7.2
|
||||
github.com/gogf/gf/contrib/drivers/dm/v2 v2.7.1
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.7.2
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.2
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.7.2
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.7.2
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.7.4
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.7.4
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.7.4
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.7.4
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.7.4
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.7.4
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
golang.org/x/mod v0.17.0
|
||||
@ -19,7 +18,6 @@ require (
|
||||
|
||||
require (
|
||||
aead.dev/minisign v0.2.0 // indirect
|
||||
gitee.com/chunanyong/dm v1.8.12 // indirect
|
||||
github.com/BurntSushi/toml v1.3.2 // indirect
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.15 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
@ -33,7 +31,6 @@ require (
|
||||
github.com/go-sql-driver/mysql v1.7.1 // indirect
|
||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
|
||||
github.com/golang-sql/sqlexp v0.1.0 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/gorilla/websocket v1.5.1 // indirect
|
||||
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
aead.dev/minisign v0.2.0 h1:kAWrq/hBRu4AARY6AlciO83xhNnW9UaC8YipS2uhLPk=
|
||||
aead.dev/minisign v0.2.0/go.mod h1:zdq6LdSd9TbuSxchxwhpA9zEb9YXcVGoE8JakuiGaIQ=
|
||||
gitee.com/chunanyong/dm v1.8.12 h1:WupbFZL0MRNIIiCPaLDHgFi5jkdkjzjPReuWPaInGwk=
|
||||
gitee.com/chunanyong/dm v1.8.12/go.mod h1:EPRJnuPFgbyOFgJ0TRYCTGzhq+ZT4wdyaj/GW/LLcNg=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 h1:lGlwhPtrX6EVml1hO0ivjkUxsSyl4dsiw9qcA1k/3IQ=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 h1:sO0/P7g68FrryJzljemN+6GTssUXdANk6aJ7T1ZxnsQ=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 h1:6oNBlSdi1QqM1PNW7FPA6xOGA5UNsXnkaYZz9vdPGhA=
|
||||
@ -41,8 +39,6 @@ github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiU
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/gogf/gf/contrib/drivers/dm/v2 v2.7.1 h1:8zvXrUCH2ZE/3ZzH+T4Zt1/7H5VIKn2/jM8Qw59V3yg=
|
||||
github.com/gogf/gf/contrib/drivers/dm/v2 v2.7.1/go.mod h1:VbtQfqPKJIl8VUCT8po5M5JRlpP0CdFtdV1vZLOB3II=
|
||||
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f h1:7xfXR/BhG3JDqO1s45n65Oyx9t4E/UqDOXep6jXdLCM=
|
||||
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f/go.mod h1:HnYoio6S7VaFJdryKcD/r9HgX+4QzYfr00XiXUo/xz0=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
@ -52,8 +48,6 @@ github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2V
|
||||
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
|
||||
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
@ -167,7 +161,6 @@ golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
|
||||
@ -59,7 +59,7 @@ func (c cGF) Index(ctx context.Context, in cGFInput) (out *cGFOutput, err error)
|
||||
answer := "n"
|
||||
// No argument or option, do installation checks.
|
||||
if data, isInstalled := service.Install.IsInstalled(); !isInstalled {
|
||||
mlog.Print("hi, it seams it's the first time you installing gf cli.")
|
||||
mlog.Print("hi, it seems it's the first time you installing gf cli.")
|
||||
answer = gcmd.Scanf("do you want to install gf(%s) binary to your system? [y/n]: ", gf.VERSION)
|
||||
} else if !data.IsSelf {
|
||||
mlog.Print("hi, you have installed gf cli.")
|
||||
|
||||
@ -8,7 +8,7 @@ package cmd
|
||||
|
||||
import (
|
||||
_ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
|
||||
_ "github.com/gogf/gf/contrib/drivers/dm/v2"
|
||||
// _ "github.com/gogf/gf/contrib/drivers/dm/v2" // precompilation does not support certain target platforms.
|
||||
_ "github.com/gogf/gf/contrib/drivers/mssql/v2"
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
|
||||
|
||||
@ -142,8 +142,9 @@ func (c cUp) doUpgradeVersion(ctx context.Context, in cUpInput) (out *doUpgradeV
|
||||
}
|
||||
for _, pkg := range packages {
|
||||
mlog.Printf(`upgrading "%s" from "%s" to "latest"`, pkg.Name, pkg.Version)
|
||||
// go get -u
|
||||
command := fmt.Sprintf(`cd %s && go get -u %s@latest`, dirPath, pkg.Name)
|
||||
mlog.Printf(`running command: go get %s@latest`, pkg.Name)
|
||||
// go get @latest
|
||||
command := fmt.Sprintf(`cd %s && go get %s@latest`, dirPath, pkg.Name)
|
||||
if err = gproc.ShellRun(ctx, command); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -691,3 +691,74 @@ func Test_Gen_Dao_Issue3459(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3749
|
||||
func Test_Gen_Dao_Issue3749(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
db = testDB
|
||||
table = "table_user"
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`issue`, `3749`, `user.tpl.sql`),
|
||||
table,
|
||||
)
|
||||
)
|
||||
dropTableWithDb(db, table)
|
||||
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||
for _, v := range array {
|
||||
if _, err = db.Exec(ctx, v); err != nil {
|
||||
t.AssertNil(err)
|
||||
}
|
||||
}
|
||||
defer dropTableWithDb(db, table)
|
||||
|
||||
var (
|
||||
path = gfile.Temp(guid.S())
|
||||
group = "test"
|
||||
in = gendao.CGenDaoInput{
|
||||
Path: path,
|
||||
Link: link,
|
||||
Group: group,
|
||||
}
|
||||
)
|
||||
|
||||
err = gutil.FillStructWithDefault(&in)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
|
||||
// for go mod import path auto retrieve.
|
||||
err = gfile.Copy(
|
||||
gtest.DataPath("gendao", "go.mod.txt"),
|
||||
gfile.Join(path, "go.mod"),
|
||||
)
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
// files
|
||||
files, err := gfile.ScanDir(path, "*.go", true)
|
||||
t.AssertNil(err)
|
||||
t.Assert(files, []string{
|
||||
filepath.FromSlash(path + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(path + "/dao/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(path + "/model/entity/table_user.go"),
|
||||
})
|
||||
// content
|
||||
testPath := gtest.DataPath(`issue`, `3749`)
|
||||
expectFiles := []string{
|
||||
filepath.FromSlash(testPath + "/dao/internal/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/dao/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||
}
|
||||
for i, _ := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -208,9 +208,11 @@ type (
|
||||
NoModelComment bool `name:"noModelComment" short:"m" brief:"{CGenDaoBriefNoModelComment}" orphan:"true"`
|
||||
Clear bool `name:"clear" short:"a" brief:"{CGenDaoBriefClear}" orphan:"true"`
|
||||
|
||||
TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenDaoBriefTypeMapping}" orphan:"true"`
|
||||
FieldMapping map[DBTableFieldName]CustomAttributeType `name:"fieldMapping" short:"fm" brief:"{CGenDaoBriefFieldMapping}" orphan:"true"`
|
||||
genItems *CGenDaoInternalGenItems
|
||||
TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenDaoBriefTypeMapping}" orphan:"true"`
|
||||
FieldMapping map[DBTableFieldName]CustomAttributeType `name:"fieldMapping" short:"fm" brief:"{CGenDaoBriefFieldMapping}" orphan:"true"`
|
||||
|
||||
// internal usage purpose.
|
||||
genItems *CGenDaoInternalGenItems
|
||||
}
|
||||
CGenDaoOutput struct{}
|
||||
|
||||
|
||||
@ -58,8 +58,8 @@ func generateDaoSingle(ctx context.Context, in generateDaoSingleInput) {
|
||||
mlog.Fatalf(`fetching tables fields failed for table "%s": %+v`, in.TableName, err)
|
||||
}
|
||||
var (
|
||||
tableNameCamelCase = gstr.CaseCamel(strings.ToLower(in.NewTableName))
|
||||
tableNameCamelLowerCase = gstr.CaseCamelLower(strings.ToLower(in.NewTableName))
|
||||
tableNameCamelCase = formatFieldName(in.NewTableName, FieldNameCaseCamel)
|
||||
tableNameCamelLowerCase = formatFieldName(in.NewTableName, FieldNameCaseCamelLower)
|
||||
tableNameSnakeCase = gstr.CaseSnake(in.NewTableName)
|
||||
importPrefix = in.ImportPrefix
|
||||
)
|
||||
@ -179,7 +179,7 @@ func generateColumnNamesForDao(fieldMap map[string]*gdb.TableField, removeFieldP
|
||||
}
|
||||
|
||||
array[index] = []string{
|
||||
" #" + gstr.CaseCamel(strings.ToLower(newFiledName)) + ":",
|
||||
" #" + formatFieldName(newFiledName, FieldNameCaseCamel) + ":",
|
||||
fmt.Sprintf(` #"%s",`, field.Name),
|
||||
}
|
||||
}
|
||||
@ -219,7 +219,7 @@ func generateColumnDefinitionForDao(fieldMap map[string]*gdb.TableField, removeF
|
||||
newFiledName = gstr.TrimLeftStr(newFiledName, v, 1)
|
||||
}
|
||||
array[index] = []string{
|
||||
" #" + gstr.CaseCamel(strings.ToLower(newFiledName)),
|
||||
" #" + formatFieldName(newFiledName, FieldNameCaseCamel),
|
||||
" # " + "string",
|
||||
" #" + fmt.Sprintf(`// %s`, comment),
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
|
||||
structDefinition, _ = generateStructDefinition(ctx, generateStructDefinitionInput{
|
||||
CGenDaoInternalInput: in,
|
||||
TableName: tableName,
|
||||
StructName: gstr.CaseCamel(strings.ToLower(newTableName)),
|
||||
StructName: formatFieldName(newTableName, FieldNameCaseCamel),
|
||||
FieldMap: fieldMap,
|
||||
IsDo: true,
|
||||
})
|
||||
@ -61,7 +61,7 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
|
||||
ctx,
|
||||
in,
|
||||
tableName,
|
||||
gstr.CaseCamel(strings.ToLower(newTableName)),
|
||||
formatFieldName(newTableName, FieldNameCaseCamel),
|
||||
structDefinition,
|
||||
)
|
||||
in.genItems.AppendGeneratedFilePath(doFilePath)
|
||||
|
||||
@ -36,7 +36,7 @@ func generateEntity(ctx context.Context, in CGenDaoInternalInput) {
|
||||
structDefinition, appendImports = generateStructDefinition(ctx, generateStructDefinitionInput{
|
||||
CGenDaoInternalInput: in,
|
||||
TableName: tableName,
|
||||
StructName: gstr.CaseCamel(strings.ToLower(newTableName)),
|
||||
StructName: formatFieldName(newTableName, FieldNameCaseCamel),
|
||||
FieldMap: fieldMap,
|
||||
IsDo: false,
|
||||
})
|
||||
@ -44,7 +44,7 @@ func generateEntity(ctx context.Context, in CGenDaoInternalInput) {
|
||||
ctx,
|
||||
in,
|
||||
newTableName,
|
||||
gstr.CaseCamel(strings.ToLower(newTableName)),
|
||||
formatFieldName(newTableName, FieldNameCaseCamel),
|
||||
structDefinition,
|
||||
appendImports,
|
||||
)
|
||||
|
||||
@ -99,7 +99,7 @@ func generateStructFieldDefinition(
|
||||
}
|
||||
localTypeNameStr = string(localTypeName)
|
||||
switch localTypeName {
|
||||
case gdb.LocalTypeDate, gdb.LocalTypeDatetime:
|
||||
case gdb.LocalTypeDate, gdb.LocalTypeTime, gdb.LocalTypeDatetime:
|
||||
if in.StdTime {
|
||||
localTypeNameStr = "time.Time"
|
||||
} else {
|
||||
@ -140,7 +140,7 @@ func generateStructFieldDefinition(
|
||||
}
|
||||
|
||||
attrLines = []string{
|
||||
" #" + gstr.CaseCamel(strings.ToLower(newFiledName)),
|
||||
" #" + formatFieldName(newFiledName, FieldNameCaseCamel),
|
||||
" #" + localTypeNameStr,
|
||||
}
|
||||
attrLines = append(attrLines, fmt.Sprintf(` #%sjson:"%s"`, tagKey, jsonTag))
|
||||
@ -167,6 +167,43 @@ func generateStructFieldDefinition(
|
||||
return attrLines, appendImport
|
||||
}
|
||||
|
||||
type FieldNameCase string
|
||||
|
||||
const (
|
||||
FieldNameCaseCamel FieldNameCase = "CaseCamel"
|
||||
FieldNameCaseCamelLower FieldNameCase = "CaseCamelLower"
|
||||
)
|
||||
|
||||
// formatFieldName formats and returns a new field name that is used for golang codes generating.
|
||||
func formatFieldName(fieldName string, nameCase FieldNameCase) string {
|
||||
// For normal databases like mysql, pgsql, sqlite,
|
||||
// field/table names of that are in normal case.
|
||||
var newFieldName = fieldName
|
||||
if isAllUpper(fieldName) {
|
||||
// For special databases like dm, oracle,
|
||||
// field/table names of that are in upper case.
|
||||
newFieldName = strings.ToLower(fieldName)
|
||||
}
|
||||
switch nameCase {
|
||||
case FieldNameCaseCamel:
|
||||
return gstr.CaseCamel(newFieldName)
|
||||
case FieldNameCaseCamelLower:
|
||||
return gstr.CaseCamelLower(newFieldName)
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
// isAllUpper checks and returns whether given `fieldName` all letters are upper case.
|
||||
func isAllUpper(fieldName string) bool {
|
||||
for _, b := range fieldName {
|
||||
if b >= 'a' && b <= 'z' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// formatComment formats the comment string to fit the golang code without any lines.
|
||||
func formatComment(comment string) string {
|
||||
comment = gstr.ReplaceByArray(comment, g.SliceStr{
|
||||
|
||||
85
cmd/gf/internal/cmd/testdata/issue/3749/dao/internal/table_user.go
vendored
Normal file
85
cmd/gf/internal/cmd/testdata/issue/3749/dao/internal/table_user.go
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
// ==========================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// ==========================================================================
|
||||
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// TableUserDao is the data access object for table table_user.
|
||||
type TableUserDao struct {
|
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
||||
}
|
||||
|
||||
// TableUserColumns defines and stores column names for table table_user.
|
||||
type TableUserColumns struct {
|
||||
Id string // User ID
|
||||
ParentId string //
|
||||
Passport string // User Passport
|
||||
PassWord string // User Password
|
||||
Nickname2 string // User Nickname
|
||||
CreateAt string // Created Time
|
||||
UpdateAt string // Updated Time
|
||||
}
|
||||
|
||||
// tableUserColumns holds the columns for table table_user.
|
||||
var tableUserColumns = TableUserColumns{
|
||||
Id: "Id",
|
||||
ParentId: "parentId",
|
||||
Passport: "PASSPORT",
|
||||
PassWord: "PASS_WORD",
|
||||
Nickname2: "NICKNAME2",
|
||||
CreateAt: "create_at",
|
||||
UpdateAt: "update_at",
|
||||
}
|
||||
|
||||
// NewTableUserDao creates and returns a new DAO object for table data access.
|
||||
func NewTableUserDao() *TableUserDao {
|
||||
return &TableUserDao{
|
||||
group: "test",
|
||||
table: "table_user",
|
||||
columns: tableUserColumns,
|
||||
}
|
||||
}
|
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *TableUserDao) DB() gdb.DB {
|
||||
return g.DB(dao.group)
|
||||
}
|
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *TableUserDao) Table() string {
|
||||
return dao.table
|
||||
}
|
||||
|
||||
// Columns returns all column names of current dao.
|
||||
func (dao *TableUserDao) Columns() TableUserColumns {
|
||||
return dao.columns
|
||||
}
|
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *TableUserDao) Group() string {
|
||||
return dao.group
|
||||
}
|
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
||||
}
|
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||
// It commits the transaction and returns nil if function f returns nil.
|
||||
//
|
||||
// Note that, you should not Commit or Rollback the transaction in function f
|
||||
// as it is automatically handled by this function.
|
||||
func (dao *TableUserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||
}
|
||||
27
cmd/gf/internal/cmd/testdata/issue/3749/dao/table_user.go
vendored
Normal file
27
cmd/gf/internal/cmd/testdata/issue/3749/dao/table_user.go
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package dao
|
||||
|
||||
import (
|
||||
"for-gendao-test/pkg/dao/internal"
|
||||
)
|
||||
|
||||
// internalTableUserDao is internal type for wrapping internal DAO implements.
|
||||
type internalTableUserDao = *internal.TableUserDao
|
||||
|
||||
// tableUserDao is the data access object for table table_user.
|
||||
// You can define custom methods on it to extend its functionality as you wish.
|
||||
type tableUserDao struct {
|
||||
internalTableUserDao
|
||||
}
|
||||
|
||||
var (
|
||||
// TableUser is globally public accessible object for table table_user operations.
|
||||
TableUser = tableUserDao{
|
||||
internal.NewTableUserDao(),
|
||||
}
|
||||
)
|
||||
|
||||
// Fill with you ideas below.
|
||||
22
cmd/gf/internal/cmd/testdata/issue/3749/model/do/table_user.go
vendored
Normal file
22
cmd/gf/internal/cmd/testdata/issue/3749/model/do/table_user.go
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package do
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
||||
type TableUser struct {
|
||||
g.Meta `orm:"table:table_user, do:true"`
|
||||
Id interface{} // User ID
|
||||
ParentId interface{} //
|
||||
Passport interface{} // User Passport
|
||||
PassWord interface{} // User Password
|
||||
Nickname2 interface{} // User Nickname
|
||||
CreateAt *gtime.Time // Created Time
|
||||
UpdateAt *gtime.Time // Updated Time
|
||||
}
|
||||
20
cmd/gf/internal/cmd/testdata/issue/3749/model/entity/table_user.go
vendored
Normal file
20
cmd/gf/internal/cmd/testdata/issue/3749/model/entity/table_user.go
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package entity
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
// TableUser is the golang structure for table table_user.
|
||||
type TableUser struct {
|
||||
Id uint `json:"id" orm:"Id" ` // User ID
|
||||
ParentId string `json:"parentId" orm:"parentId" ` //
|
||||
Passport string `json:"pASSPORT" orm:"PASSPORT" ` // User Passport
|
||||
PassWord string `json:"pASSWORD" orm:"PASS_WORD" ` // User Password
|
||||
Nickname2 string `json:"nICKNAME2" orm:"NICKNAME2" ` // User Nickname
|
||||
CreateAt *gtime.Time `json:"createAt" orm:"create_at" ` // Created Time
|
||||
UpdateAt *gtime.Time `json:"updateAt" orm:"update_at" ` // Updated Time
|
||||
}
|
||||
10
cmd/gf/internal/cmd/testdata/issue/3749/user.tpl.sql
vendored
Normal file
10
cmd/gf/internal/cmd/testdata/issue/3749/user.tpl.sql
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
CREATE TABLE `%s` (
|
||||
`Id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'User ID',
|
||||
`parentId` varchar(45) NOT NULL COMMENT '',
|
||||
`PASSPORT` varchar(45) NOT NULL COMMENT 'User Passport',
|
||||
`PASS_WORD` varchar(45) NOT NULL COMMENT 'User Password',
|
||||
`NICKNAME2` varchar(45) NOT NULL COMMENT 'User Nickname',
|
||||
`create_at` datetime DEFAULT NULL COMMENT 'Created Time',
|
||||
`update_at` datetime DEFAULT NULL COMMENT 'Updated Time',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -5,7 +5,8 @@
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
//
|
||||
|
||||
// Package glist provides most commonly used doubly linked list container which also supports concurrent-safe/unsafe switch feature.
|
||||
// Package glist provides most commonly used doubly linked list container which also supports
|
||||
// concurrent-safe/unsafe switch feature.
|
||||
package glist
|
||||
|
||||
import (
|
||||
|
||||
@ -291,7 +291,7 @@ func TestRemove(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestIssue4103(t *testing.T) {
|
||||
func Test_Issue4103(t *testing.T) {
|
||||
l1 := New()
|
||||
l1.PushBack(1)
|
||||
l1.PushBack(2)
|
||||
@ -312,7 +312,7 @@ func TestIssue4103(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue6349(t *testing.T) {
|
||||
func Test_Issue6349(t *testing.T) {
|
||||
l := New()
|
||||
l.PushBack(1)
|
||||
l.PushBack(2)
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
// Package gring provides a concurrent-safe/unsafe ring(circular lists).
|
||||
//
|
||||
// Deprecated.
|
||||
package gring
|
||||
|
||||
import (
|
||||
@ -15,6 +17,8 @@ import (
|
||||
)
|
||||
|
||||
// Ring is a struct of ring structure.
|
||||
//
|
||||
// Deprecated.
|
||||
type Ring struct {
|
||||
mu *rwmutex.RWMutex
|
||||
ring *ring.Ring // Underlying ring.
|
||||
@ -31,6 +35,8 @@ type internalRingItem struct {
|
||||
// New creates and returns a Ring structure of `cap` elements.
|
||||
// The optional parameter `safe` specifies whether using this structure in concurrent safety,
|
||||
// which is false in default.
|
||||
//
|
||||
// Deprecated.
|
||||
func New(cap int, safe ...bool) *Ring {
|
||||
return &Ring{
|
||||
mu: rwmutex.New(safe...),
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// Set is consisted of interface{} items.
|
||||
type Set struct {
|
||||
mu rwmutex.RWMutex
|
||||
data map[interface{}]struct{}
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// IntSet is consisted of int items.
|
||||
type IntSet struct {
|
||||
mu rwmutex.RWMutex
|
||||
data map[int]struct{}
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// StrSet is consisted of string items.
|
||||
type StrSet struct {
|
||||
mu rwmutex.RWMutex
|
||||
data map[string]struct{}
|
||||
|
||||
@ -8,3 +8,133 @@
|
||||
//
|
||||
// Some implements are from: https://github.com/emirpasic/gods
|
||||
package gtree
|
||||
|
||||
import "github.com/gogf/gf/v2/container/gvar"
|
||||
|
||||
// iTree defines the interface for basic operations of a tree.
|
||||
type iTree interface {
|
||||
// Set inserts node into the tree.
|
||||
Set(key interface{}, value interface{})
|
||||
|
||||
// Sets batch sets key-values to the tree.
|
||||
Sets(data map[interface{}]interface{})
|
||||
|
||||
// SetIfNotExist sets `value` to the map if the `key` does not exist, and then returns true.
|
||||
// It returns false if `key` exists, and `value` would be ignored.
|
||||
SetIfNotExist(key interface{}, value interface{}) bool
|
||||
|
||||
// SetIfNotExistFunc sets value with return value of callback function `f`, and then returns true.
|
||||
// It returns false if `key` exists, and `value` would be ignored.
|
||||
SetIfNotExistFunc(key interface{}, f func() interface{}) bool
|
||||
|
||||
// SetIfNotExistFuncLock sets value with return value of callback function `f`, and then returns true.
|
||||
// It returns false if `key` exists, and `value` would be ignored.
|
||||
// SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that
|
||||
// it executes function `f` with mutex.Lock of the hash map.
|
||||
SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool
|
||||
|
||||
// Get searches the node in the tree by `key` and returns its value or nil if key is not found in tree.
|
||||
Get(key interface{}) (value interface{})
|
||||
|
||||
// GetOrSet returns the value by key,
|
||||
// or sets value with given `value` if it does not exist and then returns this value.
|
||||
GetOrSet(key interface{}, value interface{}) interface{}
|
||||
|
||||
// GetOrSetFunc returns the value by key,
|
||||
// or sets value with returned value of callback function `f` if it does not exist
|
||||
// and then returns this value.
|
||||
GetOrSetFunc(key interface{}, f func() interface{}) interface{}
|
||||
|
||||
// GetOrSetFuncLock returns the value by key,
|
||||
// or sets value with returned value of callback function `f` if it does not exist
|
||||
// and then returns this value.
|
||||
// GetOrSetFuncLock differs with GetOrSetFunc function is that it executes function `f`
|
||||
// with mutex.Lock of the hash map.
|
||||
GetOrSetFuncLock(key interface{}, f func() interface{}) interface{}
|
||||
|
||||
// GetVar returns a gvar.Var with the value by given `key`.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
GetVar(key interface{}) *gvar.Var
|
||||
|
||||
// GetVarOrSet returns a gvar.Var with result from GetVarOrSet.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
GetVarOrSet(key interface{}, value interface{}) *gvar.Var
|
||||
|
||||
// GetVarOrSetFunc returns a gvar.Var with result from GetOrSetFunc.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
GetVarOrSetFunc(key interface{}, f func() interface{}) *gvar.Var
|
||||
|
||||
// GetVarOrSetFuncLock returns a gvar.Var with result from GetOrSetFuncLock.
|
||||
// The returned gvar.Var is un-concurrent safe.
|
||||
GetVarOrSetFuncLock(key interface{}, f func() interface{}) *gvar.Var
|
||||
|
||||
// Search searches the tree with given `key`.
|
||||
// Second return parameter `found` is true if key was found, otherwise false.
|
||||
Search(key interface{}) (value interface{}, found bool)
|
||||
|
||||
// Contains checks whether `key` exists in the tree.
|
||||
Contains(key interface{}) bool
|
||||
|
||||
// Size returns number of nodes in the tree.
|
||||
Size() int
|
||||
|
||||
// IsEmpty returns true if tree does not contain any nodes.
|
||||
IsEmpty() bool
|
||||
|
||||
// Remove removes the node from the tree by key.
|
||||
// Key should adhere to the comparator's type assertion, otherwise method panics.
|
||||
Remove(key interface{}) (value interface{})
|
||||
|
||||
// Removes batch deletes values of the tree by `keys`.
|
||||
Removes(keys []interface{})
|
||||
|
||||
// Clear removes all nodes from the tree.
|
||||
Clear()
|
||||
|
||||
// Keys returns all keys in asc order.
|
||||
Keys() []interface{}
|
||||
|
||||
// Values returns all values in asc order based on the key.
|
||||
Values() []interface{}
|
||||
|
||||
// Replace the data of the tree with given `data`.
|
||||
Replace(data map[interface{}]interface{})
|
||||
|
||||
// Print prints the tree to stdout.
|
||||
Print()
|
||||
|
||||
// String returns a string representation of container
|
||||
String() string
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
MarshalJSON() (jsonBytes []byte, err error)
|
||||
|
||||
Map() map[interface{}]interface{}
|
||||
MapStrAny() map[string]interface{}
|
||||
|
||||
// Iterator is alias of IteratorAsc.
|
||||
Iterator(f func(key, value interface{}) bool)
|
||||
|
||||
// IteratorFrom is alias of IteratorAscFrom.
|
||||
IteratorFrom(key interface{}, match bool, f func(key, value interface{}) bool)
|
||||
|
||||
// IteratorAsc iterates the tree readonly in ascending order with given callback function `f`.
|
||||
// If `f` returns true, then it continues iterating; or false to stop.
|
||||
IteratorAsc(f func(key, value interface{}) bool)
|
||||
|
||||
// IteratorAscFrom iterates the tree readonly in ascending order with given callback function `f`.
|
||||
// The parameter `key` specifies the start entry for iterating. The `match` specifies whether
|
||||
// starting iterating if the `key` is fully matched, or else using index searching iterating.
|
||||
// If `f` returns true, then it continues iterating; or false to stop.
|
||||
IteratorAscFrom(key interface{}, match bool, f func(key, value interface{}) bool)
|
||||
|
||||
// IteratorDesc iterates the tree readonly in descending order with given callback function `f`.
|
||||
// If `f` returns true, then it continues iterating; or false to stop.
|
||||
IteratorDesc(f func(key, value interface{}) bool)
|
||||
|
||||
// IteratorDescFrom iterates the tree readonly in descending order with given callback function `f`.
|
||||
// The parameter `key` specifies the start entry for iterating. The `match` specifies whether
|
||||
// starting iterating if the `key` is fully matched, or else using index searching iterating.
|
||||
// If `f` returns true, then it continues iterating; or false to stop.
|
||||
IteratorDescFrom(key interface{}, match bool, f func(key, value interface{}) bool)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,8 @@ import (
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var _ iTree = (*BTree)(nil)
|
||||
|
||||
// BTree holds elements of the B-tree.
|
||||
type BTree struct {
|
||||
mu rwmutex.RWMutex
|
||||
@ -77,6 +79,45 @@ func (tree *BTree) Sets(data map[interface{}]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetIfNotExist sets `value` to the map if the `key` does not exist, and then returns true.
|
||||
// It returns false if `key` exists, and `value` would be ignored.
|
||||
func (tree *BTree) SetIfNotExist(key interface{}, value interface{}) bool {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
if _, ok := tree.doGet(key); !ok {
|
||||
tree.doSet(key, value)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetIfNotExistFunc sets value with return value of callback function `f`, and then returns true.
|
||||
// It returns false if `key` exists, and `value` would be ignored.
|
||||
func (tree *BTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
if _, ok := tree.doGet(key); !ok {
|
||||
tree.doSet(key, f())
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetIfNotExistFuncLock sets value with return value of callback function `f`, and then returns true.
|
||||
// It returns false if `key` exists, and `value` would be ignored.
|
||||
//
|
||||
// SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that
|
||||
// it executes function `f` with mutex.Lock of the hash map.
|
||||
func (tree *BTree) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
if _, ok := tree.doGet(key); !ok {
|
||||
tree.doSet(key, f)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Get searches the node in the tree by `key` and returns its value or nil if key is not found in tree.
|
||||
func (tree *BTree) Get(key interface{}) (value interface{}) {
|
||||
tree.mu.Lock()
|
||||
@ -150,45 +191,6 @@ func (tree *BTree) GetVarOrSetFuncLock(key interface{}, f func() interface{}) *g
|
||||
return gvar.New(tree.GetOrSetFuncLock(key, f))
|
||||
}
|
||||
|
||||
// SetIfNotExist sets `value` to the map if the `key` does not exist, and then returns true.
|
||||
// It returns false if `key` exists, and `value` would be ignored.
|
||||
func (tree *BTree) SetIfNotExist(key interface{}, value interface{}) bool {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
if _, ok := tree.doGet(key); !ok {
|
||||
tree.doSet(key, value)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetIfNotExistFunc sets value with return value of callback function `f`, and then returns true.
|
||||
// It returns false if `key` exists, and `value` would be ignored.
|
||||
func (tree *BTree) SetIfNotExistFunc(key interface{}, f func() interface{}) bool {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
if _, ok := tree.doGet(key); !ok {
|
||||
tree.doSet(key, f())
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SetIfNotExistFuncLock sets value with return value of callback function `f`, and then returns true.
|
||||
// It returns false if `key` exists, and `value` would be ignored.
|
||||
//
|
||||
// SetIfNotExistFuncLock differs with SetIfNotExistFunc function is that
|
||||
// it executes function `f` with mutex.Lock of the hash map.
|
||||
func (tree *BTree) SetIfNotExistFuncLock(key interface{}, f func() interface{}) bool {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
if _, ok := tree.doGet(key); !ok {
|
||||
tree.doSet(key, f)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Search searches the tree with given `key`.
|
||||
// Second return parameter `found` is true if key was found, otherwise false.
|
||||
func (tree *BTree) Search(key interface{}) (value interface{}, found bool) {
|
||||
@ -205,6 +207,20 @@ func (tree *BTree) Contains(key interface{}) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// Size returns number of nodes in the tree.
|
||||
func (tree *BTree) Size() int {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
return tree.tree.Size()
|
||||
}
|
||||
|
||||
// IsEmpty returns true if tree does not contain any nodes
|
||||
func (tree *BTree) IsEmpty() bool {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
return tree.tree.Size() == 0
|
||||
}
|
||||
|
||||
// Remove removes the node from the tree by `key`.
|
||||
func (tree *BTree) Remove(key interface{}) (value interface{}) {
|
||||
tree.mu.Lock()
|
||||
@ -221,18 +237,11 @@ func (tree *BTree) Removes(keys []interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// IsEmpty returns true if tree does not contain any nodes
|
||||
func (tree *BTree) IsEmpty() bool {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
return tree.tree.Size() == 0
|
||||
}
|
||||
|
||||
// Size returns number of nodes in the tree.
|
||||
func (tree *BTree) Size() int {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
return tree.tree.Size()
|
||||
// Clear removes all nodes from the tree.
|
||||
func (tree *BTree) Clear() {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
tree.tree.Clear()
|
||||
}
|
||||
|
||||
// Keys returns all keys in asc order.
|
||||
@ -249,6 +258,16 @@ func (tree *BTree) Values() []interface{} {
|
||||
return tree.tree.Values()
|
||||
}
|
||||
|
||||
// Replace the data of the tree with given `data`.
|
||||
func (tree *BTree) Replace(data map[interface{}]interface{}) {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
tree.tree.Clear()
|
||||
for k, v := range data {
|
||||
tree.doSet(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Map returns all key-value items as map.
|
||||
func (tree *BTree) Map() map[interface{}]interface{} {
|
||||
tree.mu.RLock()
|
||||
@ -273,56 +292,9 @@ func (tree *BTree) MapStrAny() map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
// Clear removes all nodes from the tree.
|
||||
func (tree *BTree) Clear() {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
tree.tree.Clear()
|
||||
}
|
||||
|
||||
// Replace the data of the tree with given `data`.
|
||||
func (tree *BTree) Replace(data map[interface{}]interface{}) {
|
||||
tree.mu.Lock()
|
||||
defer tree.mu.Unlock()
|
||||
tree.tree.Clear()
|
||||
for k, v := range data {
|
||||
tree.doSet(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
// Height returns the height of the tree.
|
||||
func (tree *BTree) Height() int {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
return tree.tree.Height()
|
||||
}
|
||||
|
||||
// Left returns the left-most (min) entry or nil if tree is empty.
|
||||
func (tree *BTree) Left() *BTreeEntry {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
node := tree.tree.Left()
|
||||
if node == nil || node.Entries == nil || len(node.Entries) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &BTreeEntry{
|
||||
Key: node.Entries[0].Key,
|
||||
Value: node.Entries[0].Value,
|
||||
}
|
||||
}
|
||||
|
||||
// Right returns the right-most (max) entry or nil if tree is empty.
|
||||
func (tree *BTree) Right() *BTreeEntry {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
node := tree.tree.Right()
|
||||
if node == nil || node.Entries == nil || len(node.Entries) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &BTreeEntry{
|
||||
Key: node.Entries[len(node.Entries)-1].Key,
|
||||
Value: node.Entries[len(node.Entries)-1].Value,
|
||||
}
|
||||
// Print prints the tree to stdout.
|
||||
func (tree *BTree) Print() {
|
||||
fmt.Println(tree.String())
|
||||
}
|
||||
|
||||
// String returns a string representation of container (for debugging purposes)
|
||||
@ -332,9 +304,11 @@ func (tree *BTree) String() string {
|
||||
return gstr.Replace(tree.tree.String(), "BTree\n", "")
|
||||
}
|
||||
|
||||
// Print prints the tree to stdout.
|
||||
func (tree *BTree) Print() {
|
||||
fmt.Println(tree.String())
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (tree *BTree) MarshalJSON() (jsonBytes []byte, err error) {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
return tree.tree.MarshalJSON()
|
||||
}
|
||||
|
||||
// Iterator is alias of IteratorAsc.
|
||||
@ -409,11 +383,39 @@ func (tree *BTree) IteratorDescFrom(key interface{}, match bool, f func(key, val
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalJSON implements the interface MarshalJSON for json.Marshal.
|
||||
func (tree *BTree) MarshalJSON() (jsonBytes []byte, err error) {
|
||||
// Height returns the height of the tree.
|
||||
func (tree *BTree) Height() int {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
return tree.tree.MarshalJSON()
|
||||
return tree.tree.Height()
|
||||
}
|
||||
|
||||
// Left returns the left-most (min) entry or nil if tree is empty.
|
||||
func (tree *BTree) Left() *BTreeEntry {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
node := tree.tree.Left()
|
||||
if node == nil || node.Entries == nil || len(node.Entries) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &BTreeEntry{
|
||||
Key: node.Entries[0].Key,
|
||||
Value: node.Entries[0].Value,
|
||||
}
|
||||
}
|
||||
|
||||
// Right returns the right-most (max) entry or nil if tree is empty.
|
||||
func (tree *BTree) Right() *BTreeEntry {
|
||||
tree.mu.RLock()
|
||||
defer tree.mu.RUnlock()
|
||||
node := tree.tree.Right()
|
||||
if node == nil || node.Entries == nil || len(node.Entries) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &BTreeEntry{
|
||||
Key: node.Entries[len(node.Entries)-1].Key,
|
||||
Value: node.Entries[len(node.Entries)-1].Value,
|
||||
}
|
||||
}
|
||||
|
||||
// doSet inserts key-value pair node into the tree.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -443,7 +443,7 @@ func ExampleAVLTree_Right() {
|
||||
fmt.Println(tree.Right().Key, tree.Right().Value)
|
||||
|
||||
emptyTree := gtree.NewAVLTree(gutil.ComparatorInt)
|
||||
fmt.Println(emptyTree.Left())
|
||||
fmt.Println(emptyTree.Right())
|
||||
|
||||
// Output:
|
||||
// 99 99
|
||||
|
||||
@ -592,6 +592,11 @@ func ExampleRedBlackTree_IteratorAscFrom_NoExistKeyAndMatchFalse() {
|
||||
})
|
||||
|
||||
// Output:
|
||||
// key: 1 , value: 10
|
||||
// key: 2 , value: 20
|
||||
// key: 3 , value: 30
|
||||
// key: 4 , value: 40
|
||||
// key: 5 , value: 50
|
||||
}
|
||||
|
||||
func ExampleRedBlackTree_IteratorDesc() {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
// Package gvar provides an universal variable type, like generics.
|
||||
// Package gvar provides an universal variable type, like runtime generics.
|
||||
package gvar
|
||||
|
||||
import (
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/apolloconfig/agollo/v4 v4.3.1
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/consul/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/hashicorp/consul/api v1.24.0
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2
|
||||
)
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/kubecm/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
k8s.io/api v0.27.4
|
||||
k8s.io/apimachinery v0.27.4
|
||||
k8s.io/client-go v0.27.4
|
||||
@ -54,7 +54,7 @@ require (
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@ -476,8 +476,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
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=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/nacos/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/nacos-group/nacos-sdk-go/v2 v2.2.5
|
||||
)
|
||||
|
||||
@ -59,7 +59,7 @@ require (
|
||||
golang.org/x/time v0.1.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
|
||||
google.golang.org/grpc v1.56.3 // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@ -577,8 +577,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
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=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/polaris/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/polarismesh/polaris-go v1.5.5
|
||||
)
|
||||
|
||||
@ -52,7 +52,7 @@ require (
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
|
||||
google.golang.org/grpc v1.59.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@ -978,8 +978,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
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=
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.15
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/shopspring/decimal v1.3.1
|
||||
)
|
||||
|
||||
@ -6,7 +6,7 @@ replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
require (
|
||||
gitee.com/chunanyong/dm v1.8.12
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/mssql/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/microsoft/go-mssqldb v1.7.1
|
||||
)
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -104,6 +104,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
"password": "25d55ad283aa400af464c76d713c07ad",
|
||||
"nickname": "T1",
|
||||
"create_time": gtime.Now().String(),
|
||||
"create_date": gtime.Date(),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
|
||||
@ -114,6 +115,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
"password": "25d55ad283aa400af464c76d713c07ad",
|
||||
"nickname": "name_2",
|
||||
"create_time": gtime.Now().String(),
|
||||
"create_date": gtime.Date(),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
@ -121,19 +123,22 @@ func Test_DB_Insert(t *testing.T) {
|
||||
|
||||
// struct
|
||||
type User struct {
|
||||
Id int `gconv:"id"`
|
||||
Passport string `json:"passport"`
|
||||
Password string `gconv:"password"`
|
||||
Nickname string `gconv:"nickname"`
|
||||
CreateTime string `json:"create_time"`
|
||||
Id int `gconv:"id"`
|
||||
Passport string `json:"passport"`
|
||||
Password string `gconv:"password"`
|
||||
Nickname string `gconv:"nickname"`
|
||||
CreateTime string `json:"create_time"`
|
||||
CreateDate *gtime.Time `json:"create_date"`
|
||||
}
|
||||
timeStr := gtime.New("2024-10-01 12:01:01").String()
|
||||
gTime := gtime.New("2024-10-01 12:01:01")
|
||||
timeStr, dateStr := gTime.String(), "2024-10-01 00:00:00"
|
||||
result, err = db.Insert(ctx, table, User{
|
||||
Id: 3,
|
||||
Passport: "user_3",
|
||||
Password: "25d55ad283aa400af464c76d713c07ad",
|
||||
Nickname: "name_3",
|
||||
CreateTime: timeStr,
|
||||
CreateDate: gTime,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
n, _ = result.RowsAffected()
|
||||
@ -147,15 +152,18 @@ func Test_DB_Insert(t *testing.T) {
|
||||
t.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad")
|
||||
t.Assert(one["nickname"].String(), "name_3")
|
||||
t.Assert(one["create_time"].GTime().String(), timeStr)
|
||||
t.Assert(one["create_date"].GTime().String(), dateStr)
|
||||
|
||||
// *struct
|
||||
timeStr = gtime.New("2024-10-01 12:01:01").String()
|
||||
gTime = gtime.New("2024-10-01 12:01:01")
|
||||
timeStr, dateStr = gTime.String(), "2024-10-01 00:00:00"
|
||||
result, err = db.Insert(ctx, table, &User{
|
||||
Id: 4,
|
||||
Passport: "t4",
|
||||
Password: "25d55ad283aa400af464c76d713c07ad",
|
||||
Nickname: "name_4",
|
||||
CreateTime: timeStr,
|
||||
CreateDate: gTime,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
n, _ = result.RowsAffected()
|
||||
@ -168,9 +176,11 @@ func Test_DB_Insert(t *testing.T) {
|
||||
t.Assert(one["password"].String(), "25d55ad283aa400af464c76d713c07ad")
|
||||
t.Assert(one["nickname"].String(), "name_4")
|
||||
t.Assert(one["create_time"].GTime().String(), timeStr)
|
||||
t.Assert(one["create_date"].GTime().String(), dateStr)
|
||||
|
||||
// batch with Insert
|
||||
timeStr = gtime.New("2024-10-01 12:01:01").String()
|
||||
gTime = gtime.New("2024-10-01 12:01:01")
|
||||
timeStr, dateStr = gTime.String(), "2024-10-01 00:00:00"
|
||||
r, err := db.Insert(ctx, table, g.Slice{
|
||||
g.Map{
|
||||
"id": 200,
|
||||
@ -178,6 +188,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
"password": "25d55ad283aa400af464c76d71qw07ad",
|
||||
"nickname": "T200",
|
||||
"create_time": timeStr,
|
||||
"create_date": gTime,
|
||||
},
|
||||
g.Map{
|
||||
"id": 300,
|
||||
@ -185,6 +196,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
"password": "25d55ad283aa400af464c76d713c07ad",
|
||||
"nickname": "T300",
|
||||
"create_time": timeStr,
|
||||
"create_date": gTime,
|
||||
},
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -198,6 +210,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
t.Assert(one["password"].String(), "25d55ad283aa400af464c76d71qw07ad")
|
||||
t.Assert(one["nickname"].String(), "T200")
|
||||
t.Assert(one["create_time"].GTime().String(), timeStr)
|
||||
t.Assert(one["create_date"].GTime().String(), dateStr)
|
||||
})
|
||||
}
|
||||
|
||||
@ -1644,7 +1657,7 @@ func Test_Core_ClearTableFields(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
fields, err := db.TableFields(ctx, table)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(fields), 5)
|
||||
t.Assert(len(fields), 6)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err := db.GetCore().ClearTableFields(ctx, table)
|
||||
|
||||
@ -129,6 +129,7 @@ func createTableWithDb(db gdb.DB, table ...string) (name string) {
|
||||
password char(32) NULL,
|
||||
nickname varchar(45) NULL,
|
||||
create_time timestamp(6) NULL,
|
||||
create_date date NULL,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
`, name,
|
||||
|
||||
@ -431,6 +431,45 @@ func Test_Issue1733(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/2012
|
||||
func Test_Issue2012(t *testing.T) {
|
||||
table := "time_only_" + guid.S()
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf(`
|
||||
CREATE TABLE %s(
|
||||
id int(8) unsigned zerofill NOT NULL AUTO_INCREMENT,
|
||||
time_only time,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
`, table,
|
||||
)); err != nil {
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
defer dropTable(table)
|
||||
|
||||
type TimeOnly struct {
|
||||
Id int `json:"id"`
|
||||
TimeOnly *gtime.Time `json:"timeOnly"`
|
||||
}
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
timeOnly := gtime.New("15:04:05")
|
||||
m := db.Model(table)
|
||||
|
||||
_, err := m.Insert(TimeOnly{
|
||||
TimeOnly: gtime.New(timeOnly),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = m.Insert(g.Map{
|
||||
"time_only": timeOnly,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = m.Insert("time_only", timeOnly)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/2105
|
||||
func Test_Issue2105(t *testing.T) {
|
||||
table := "issue2105"
|
||||
@ -1024,7 +1063,7 @@ func Test_Issue2552_ClearTableFieldsAll(t *testing.T) {
|
||||
ctx = context.Background()
|
||||
sqlArray, err = gdb.CatchSQL(ctx, func(ctx context.Context) error {
|
||||
one, err := db.Model(table).Ctx(ctx).One()
|
||||
t.Assert(len(one), 5)
|
||||
t.Assert(len(one), 6)
|
||||
return err
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -1039,7 +1078,7 @@ func Test_Issue2552_ClearTableFieldsAll(t *testing.T) {
|
||||
ctx = context.Background()
|
||||
sqlArray, err = gdb.CatchSQL(ctx, func(ctx context.Context) error {
|
||||
one, err := db.Model(table).Ctx(ctx).One()
|
||||
t.Assert(len(one), 4)
|
||||
t.Assert(len(one), 5)
|
||||
return err
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -1070,7 +1109,7 @@ func Test_Issue2552_ClearTableFields(t *testing.T) {
|
||||
ctx = context.Background()
|
||||
sqlArray, err = gdb.CatchSQL(ctx, func(ctx context.Context) error {
|
||||
one, err := db.Model(table).Ctx(ctx).One()
|
||||
t.Assert(len(one), 5)
|
||||
t.Assert(len(one), 6)
|
||||
return err
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -1085,7 +1124,7 @@ func Test_Issue2552_ClearTableFields(t *testing.T) {
|
||||
ctx = context.Background()
|
||||
sqlArray, err = gdb.CatchSQL(ctx, func(ctx context.Context) error {
|
||||
one, err := db.Model(table).Ctx(ctx).One()
|
||||
t.Assert(len(one), 4)
|
||||
t.Assert(len(one), 5)
|
||||
return err
|
||||
})
|
||||
t.AssertNil(err)
|
||||
@ -1160,3 +1199,82 @@ func Test_Issue3238(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3649
|
||||
func Test_Issue3649(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
sql, err := gdb.CatchSQL(context.Background(), func(ctx context.Context) (err error) {
|
||||
user := db.Model(table).Ctx(ctx)
|
||||
_, err = user.Where("create_time = ?", gdb.Raw("now()")).WhereLT("create_time", gdb.Raw("now()")).Count()
|
||||
return
|
||||
})
|
||||
t.AssertNil(err)
|
||||
sqlStr := fmt.Sprintf("SELECT COUNT(1) FROM `%s` WHERE (create_time = now()) AND (`create_time` < now())", table)
|
||||
t.Assert(sql[0], sqlStr)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3754
|
||||
func Test_Issue3754(t *testing.T) {
|
||||
table := "issue3754"
|
||||
array := gstr.SplitAndTrim(gtest.DataContent(`issue3754.sql`), ";")
|
||||
for _, v := range array {
|
||||
if _, err := db.Exec(ctx, v); err != nil {
|
||||
gtest.Error(err)
|
||||
}
|
||||
}
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
fieldsEx := []string{"delete_at", "create_at", "update_at"}
|
||||
// Insert.
|
||||
dataInsert := g.Map{
|
||||
"id": 1,
|
||||
"name": "name_1",
|
||||
}
|
||||
r, err := db.Model(table).Data(dataInsert).FieldsEx(fieldsEx).Insert()
|
||||
t.AssertNil(err)
|
||||
n, _ := r.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
oneInsert, err := db.Model(table).WherePri(1).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(oneInsert["id"].Int(), 1)
|
||||
t.Assert(oneInsert["name"].String(), "name_1")
|
||||
t.Assert(oneInsert["delete_at"].String(), "")
|
||||
t.Assert(oneInsert["create_at"].String(), "")
|
||||
t.Assert(oneInsert["update_at"].String(), "")
|
||||
|
||||
// Update.
|
||||
dataUpdate := g.Map{
|
||||
"name": "name_1000",
|
||||
}
|
||||
r, err = db.Model(table).Data(dataUpdate).FieldsEx(fieldsEx).WherePri(1).Update()
|
||||
t.AssertNil(err)
|
||||
n, _ = r.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
oneUpdate, err := db.Model(table).WherePri(1).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(oneUpdate["id"].Int(), 1)
|
||||
t.Assert(oneUpdate["name"].String(), "name_1000")
|
||||
t.Assert(oneUpdate["delete_at"].String(), "")
|
||||
t.Assert(oneUpdate["create_at"].String(), "")
|
||||
t.Assert(oneUpdate["update_at"].String(), "")
|
||||
|
||||
// FieldsEx does not affect Delete operation.
|
||||
r, err = db.Model(table).FieldsEx(fieldsEx).WherePri(1).Delete()
|
||||
n, _ = r.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
oneDeleteUnscoped, err := db.Model(table).Unscoped().WherePri(1).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(oneDeleteUnscoped["id"].Int(), 1)
|
||||
t.Assert(oneDeleteUnscoped["name"].String(), "name_1000")
|
||||
t.AssertNE(oneDeleteUnscoped["delete_at"].String(), "")
|
||||
t.Assert(oneDeleteUnscoped["create_at"].String(), "")
|
||||
t.Assert(oneDeleteUnscoped["update_at"].String(), "")
|
||||
})
|
||||
}
|
||||
|
||||
@ -2335,7 +2335,7 @@ func Test_Model_FieldsEx(t *testing.T) {
|
||||
r, err := db.Model(table).FieldsEx("create_time, id").Where("id in (?)", g.Slice{1, 2}).Order("id asc").All()
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(r), 2)
|
||||
t.Assert(len(r[0]), 3)
|
||||
t.Assert(len(r[0]), 4)
|
||||
t.Assert(r[0]["id"], "")
|
||||
t.Assert(r[0]["passport"], "user_1")
|
||||
t.Assert(r[0]["password"], "pass_1")
|
||||
@ -2982,7 +2982,7 @@ func Test_Model_FieldsEx_AutoMapping(t *testing.T) {
|
||||
"CreateTime": 1,
|
||||
}).Where("id", 2).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(one), 2)
|
||||
t.Assert(len(one), 3)
|
||||
t.Assert(one["id"], 2)
|
||||
t.Assert(one["nickname"], "name_2")
|
||||
})
|
||||
@ -2999,7 +2999,7 @@ func Test_Model_FieldsEx_AutoMapping(t *testing.T) {
|
||||
CreateTime: 0,
|
||||
}).Where("id", 2).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(one), 2)
|
||||
t.Assert(len(one), 3)
|
||||
t.Assert(one["id"], 2)
|
||||
t.Assert(one["nickname"], "name_2")
|
||||
})
|
||||
@ -3157,8 +3157,8 @@ func Test_TimeZoneInsert(t *testing.T) {
|
||||
gtest.AssertNil(err)
|
||||
|
||||
CreateTime := "2020-11-22 12:23:45"
|
||||
UpdateTime := "2020-11-22 13:23:45"
|
||||
DeleteTime := "2020-11-22 14:23:45"
|
||||
UpdateTime := "2020-11-22 13:23:46"
|
||||
DeleteTime := "2020-11-22 14:23:47"
|
||||
type User struct {
|
||||
Id int `json:"id"`
|
||||
CreatedAt *gtime.Time `json:"created_at"`
|
||||
@ -3176,13 +3176,14 @@ func Test_TimeZoneInsert(t *testing.T) {
|
||||
}
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
_, _ = db.Model(tableName).Unscoped().Insert(u)
|
||||
_, err = db.Model(tableName).Unscoped().Insert(u)
|
||||
t.AssertNil(err)
|
||||
userEntity := &User{}
|
||||
err := db.Model(tableName).Where("id", 1).Unscoped().Scan(&userEntity)
|
||||
err = db.Model(tableName).Where("id", 1).Unscoped().Scan(&userEntity)
|
||||
t.AssertNil(err)
|
||||
t.Assert(userEntity.CreatedAt.String(), "2020-11-22 11:23:45")
|
||||
t.Assert(userEntity.UpdatedAt.String(), "2020-11-22 12:23:45")
|
||||
t.Assert(gtime.NewFromTime(userEntity.DeletedAt).String(), "2020-11-22 13:23:45")
|
||||
t.Assert(userEntity.UpdatedAt.String(), "2020-11-22 12:23:46")
|
||||
t.Assert(gtime.NewFromTime(userEntity.DeletedAt).String(), "2020-11-22 13:23:47")
|
||||
})
|
||||
}
|
||||
|
||||
@ -4785,3 +4786,35 @@ func Test_Model_FixGdbJoin(t *testing.T) {
|
||||
t.Assert(gtest.DataContent(`fix_gdb_join_expect.sql`), sqlSlice[len(sqlSlice)-1])
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_Year_Date_Time_DateTime_Timestamp(t *testing.T) {
|
||||
table := "date_time_example"
|
||||
array := gstr.SplitAndTrim(gtest.DataContent(`date_time_example.sql`), ";")
|
||||
for _, v := range array {
|
||||
if _, err := db.Exec(ctx, v); err != nil {
|
||||
gtest.Error(err)
|
||||
}
|
||||
}
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
// insert.
|
||||
var now = gtime.Now()
|
||||
_, err := db.Model("date_time_example").Insert(g.Map{
|
||||
"year": now,
|
||||
"date": now,
|
||||
"time": now,
|
||||
"datetime": now,
|
||||
"timestamp": now,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
// select.
|
||||
one, err := db.Model("date_time_example").One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one["year"].String(), now.Format("Y"))
|
||||
t.Assert(one["date"].String(), now.Format("Y-m-d"))
|
||||
t.Assert(one["time"].String(), now.Format("H:i:s"))
|
||||
t.AssertLT(one["datetime"].GTime().Sub(now).Seconds(), 5)
|
||||
t.AssertLT(one["timestamp"].GTime().Sub(now).Seconds(), 5)
|
||||
})
|
||||
}
|
||||
|
||||
9
contrib/drivers/mysql/testdata/date_time_example.sql
vendored
Normal file
9
contrib/drivers/mysql/testdata/date_time_example.sql
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
CREATE TABLE `date_time_example` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT,
|
||||
`year` year DEFAULT NULL COMMENT 'year',
|
||||
`date` date DEFAULT NULL COMMENT 'Date',
|
||||
`time` time DEFAULT NULL COMMENT 'time',
|
||||
`datetime` datetime DEFAULT NULL COMMENT 'datetime',
|
||||
`timestamp` timestamp NULL DEFAULT NULL COMMENT 'Timestamp',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
8
contrib/drivers/mysql/testdata/issue3754.sql
vendored
Normal file
8
contrib/drivers/mysql/testdata/issue3754.sql
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
CREATE TABLE `issue3754` (
|
||||
id int(11) NOT NULL,
|
||||
name varchar(45) DEFAULT NULL,
|
||||
create_at datetime(0) DEFAULT NULL,
|
||||
update_at datetime(0) DEFAULT NULL,
|
||||
delete_at datetime(0) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/oracle/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/sijms/go-ora/v2 v2.7.10
|
||||
)
|
||||
|
||||
|
||||
12
contrib/drivers/oracle/oracle_order.go
Normal file
12
contrib/drivers/oracle/oracle_order.go
Normal file
@ -0,0 +1,12 @@
|
||||
// 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 oracle
|
||||
|
||||
// OrderRandomFunction returns the SQL function for random ordering.
|
||||
func (d *Driver) OrderRandomFunction() string {
|
||||
return "DBMS_RANDOM.VALUE()"
|
||||
}
|
||||
@ -1177,6 +1177,17 @@ func Test_Model_Replace(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_OrderRandom(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Model(table).OrderRandom().All()
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), TableSize)
|
||||
})
|
||||
}
|
||||
|
||||
/* not support the "AS"
|
||||
func Test_Model_Raw(t *testing.T) {
|
||||
table := createInitTable()
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/pgsql/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/lib/pq v1.10.9
|
||||
)
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"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/gogf/gf/v2/util/gconv"
|
||||
@ -19,17 +20,22 @@ import (
|
||||
|
||||
// ConvertValueForField converts value to database acceptable value.
|
||||
func (d *Driver) ConvertValueForField(ctx context.Context, fieldType string, fieldValue interface{}) (interface{}, error) {
|
||||
var (
|
||||
fieldValueKind = reflect.TypeOf(fieldValue).Kind()
|
||||
)
|
||||
if g.IsNil(fieldValue) {
|
||||
return d.Core.ConvertValueForField(ctx, fieldType, fieldValue)
|
||||
}
|
||||
|
||||
var fieldValueKind = reflect.TypeOf(fieldValue).Kind()
|
||||
|
||||
if fieldValueKind == reflect.Slice {
|
||||
fieldValue = gstr.ReplaceByMap(gconv.String(fieldValue),
|
||||
map[string]string{
|
||||
"[": "{",
|
||||
"]": "}",
|
||||
},
|
||||
)
|
||||
// For pgsql, json or jsonb require '[]'
|
||||
if !gstr.Contains(fieldType, "json") {
|
||||
fieldValue = gstr.ReplaceByMap(gconv.String(fieldValue),
|
||||
map[string]string{
|
||||
"[": "{",
|
||||
"]": "}",
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
return d.Core.ConvertValueForField(ctx, fieldType, fieldValue)
|
||||
}
|
||||
|
||||
12
contrib/drivers/pgsql/pgsql_order.go
Normal file
12
contrib/drivers/pgsql/pgsql_order.go
Normal file
@ -0,0 +1,12 @@
|
||||
// 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 pgsql
|
||||
|
||||
// OrderRandomFunction returns the SQL function for random ordering.
|
||||
func (d *Driver) OrderRandomFunction() string {
|
||||
return "RANDOM()"
|
||||
}
|
||||
@ -103,3 +103,72 @@ func Test_Issue3632(t *testing.T) {
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3671
|
||||
func Test_Issue3671(t *testing.T) {
|
||||
type SubMember struct {
|
||||
Seven string
|
||||
Eight int64
|
||||
}
|
||||
type Member struct {
|
||||
One []int64 `json:"one" orm:"one"`
|
||||
Two [][]string `json:"two" orm:"two"`
|
||||
Three []string `json:"three" orm:"three"`
|
||||
Four []int64 `json:"four" orm:"four"`
|
||||
Five []SubMember `json:"five" orm:"five"`
|
||||
}
|
||||
var (
|
||||
sqlText = gtest.DataContent("issues", "issue3671.sql")
|
||||
table = fmt.Sprintf(`%s_%d`, TablePrefix+"issue3632", gtime.TimestampNano())
|
||||
)
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf(sqlText, table)); err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
dao = db.Model(table)
|
||||
member = Member{
|
||||
One: []int64{1, 2, 3},
|
||||
Two: [][]string{{"a", "b"}, {"c", "d"}},
|
||||
Three: []string{"x", "y", "z"},
|
||||
Four: []int64{1, 2, 3},
|
||||
Five: []SubMember{{Seven: "1", Eight: 2}, {Seven: "3", Eight: 4}},
|
||||
}
|
||||
)
|
||||
|
||||
_, err := dao.Ctx(ctx).Data(&member).Insert()
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3668
|
||||
func Test_Issue3668(t *testing.T) {
|
||||
type Issue3668 struct {
|
||||
Text interface{}
|
||||
Number interface{}
|
||||
}
|
||||
var (
|
||||
sqlText = gtest.DataContent("issues", "issue3668.sql")
|
||||
table = fmt.Sprintf(`%s_%d`, TablePrefix+"issue3668", gtime.TimestampNano())
|
||||
)
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf(sqlText, table)); err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
dao = db.Model(table)
|
||||
data = Issue3668{
|
||||
Text: "我们都是自然的婴儿,卧在宇宙的摇篮里",
|
||||
Number: nil,
|
||||
}
|
||||
)
|
||||
_, err := dao.Ctx(ctx).
|
||||
Data(data).
|
||||
Insert()
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
@ -587,3 +587,14 @@ func Test_Model_OnDuplicateEx(t *testing.T) {
|
||||
t.Assert(one["nickname"], "name_1")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_OrderRandom(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Model(table).OrderRandom().All()
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), TableSize)
|
||||
})
|
||||
}
|
||||
|
||||
4
contrib/drivers/pgsql/testdata/issues/issue3668.sql
vendored
Normal file
4
contrib/drivers/pgsql/testdata/issues/issue3668.sql
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
CREATE TABLE "public"."%s" (
|
||||
"text" varchar(255) COLLATE "pg_catalog"."default",
|
||||
"number" int4
|
||||
);
|
||||
8
contrib/drivers/pgsql/testdata/issues/issue3671.sql
vendored
Normal file
8
contrib/drivers/pgsql/testdata/issues/issue3671.sql
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
CREATE TABLE "public"."%s"
|
||||
(
|
||||
"one" int8[] NOT NULL,
|
||||
"two" text[][] NOT NULL,
|
||||
"three" jsonb,
|
||||
"four" json,
|
||||
"five" jsonb
|
||||
);
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/glebarez/go-sqlite v1.21.2
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
12
contrib/drivers/sqlite/sqlite_order.go
Normal file
12
contrib/drivers/sqlite/sqlite_order.go
Normal file
@ -0,0 +1,12 @@
|
||||
// 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 sqlite
|
||||
|
||||
// OrderRandomFunction returns the SQL function for random ordering.
|
||||
func (d *Driver) OrderRandomFunction() string {
|
||||
return "RANDOM()"
|
||||
}
|
||||
@ -4299,3 +4299,14 @@ func TestResult_Structs1(t *testing.T) {
|
||||
t.Assert(array[1].Name, "smith")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_OrderRandom(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Model(table).OrderRandom().All()
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(result), TableSize)
|
||||
})
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/sqlitecgo/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/mattn/go-sqlite3 v1.14.17
|
||||
)
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/metric/otelmetric/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/prometheus/client_golang v1.19.0
|
||||
go.opentelemetry.io/contrib/instrumentation/runtime v0.49.0
|
||||
go.opentelemetry.io/otel v1.24.0
|
||||
@ -38,7 +38,7 @@ require (
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/protobuf v1.32.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
|
||||
@ -70,8 +70,8 @@ golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
||||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/nosql/redis/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/redis/go-redis/v9 v9.2.1
|
||||
go.opentelemetry.io/otel v1.14.0
|
||||
go.opentelemetry.io/otel/trace v1.14.0
|
||||
|
||||
@ -76,6 +76,9 @@ func (r GroupScript) ScriptExists(ctx context.Context, sha1 string, sha1s ...str
|
||||
s = append(s, "Exists")
|
||||
s = append(s, sha1Array...)
|
||||
result, err := r.Operation.Do(ctx, "Script", s...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
m = make(map[string]bool)
|
||||
resultArray = result.Vars()
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
etcd3 "go.etcd.io/etcd/client/v3"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
@ -38,11 +39,26 @@ type Registry struct {
|
||||
type Option struct {
|
||||
Logger glog.ILogger
|
||||
KeepaliveTTL time.Duration
|
||||
|
||||
// DialTimeout is the timeout for failing to establish a connection.
|
||||
DialTimeout time.Duration
|
||||
|
||||
// AutoSyncInterval is the interval to update endpoints with its latest members.
|
||||
AutoSyncInterval time.Duration
|
||||
|
||||
DialOptions []grpc.DialOption
|
||||
}
|
||||
|
||||
const (
|
||||
// DefaultKeepAliveTTL is the default keepalive TTL.
|
||||
DefaultKeepAliveTTL = 10 * time.Second
|
||||
|
||||
// DefaultDialTimeout is the timeout for failing to establish a connection.
|
||||
DefaultDialTimeout = time.Second * 5
|
||||
|
||||
// DefaultAutoSyncInterval is the interval to update endpoints with its latest members.
|
||||
// 0 disables auto-sync. By default auto-sync is disabled.
|
||||
DefaultAutoSyncInterval = time.Second
|
||||
)
|
||||
|
||||
// New creates and returns a new etcd registry.
|
||||
@ -80,6 +96,21 @@ func New(address string, option ...Option) gsvc.Registry {
|
||||
if password != "" {
|
||||
cfg.Password = password
|
||||
}
|
||||
|
||||
cfg.DialTimeout = DefaultDialTimeout
|
||||
cfg.AutoSyncInterval = DefaultAutoSyncInterval
|
||||
|
||||
var usedOption Option
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
if usedOption.DialTimeout > 0 {
|
||||
cfg.DialTimeout = usedOption.DialTimeout
|
||||
}
|
||||
if usedOption.AutoSyncInterval > 0 {
|
||||
cfg.AutoSyncInterval = usedOption.AutoSyncInterval
|
||||
}
|
||||
|
||||
client, err := etcd3.New(cfg)
|
||||
if err != nil {
|
||||
panic(gerror.Wrap(err, `create etcd client failed`))
|
||||
|
||||
@ -3,8 +3,9 @@ module github.com/gogf/gf/contrib/registry/etcd/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
go.etcd.io/etcd/client/v3 v3.5.7
|
||||
google.golang.org/grpc v1.59.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -41,8 +42,7 @@ require (
|
||||
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
|
||||
google.golang.org/grpc v1.59.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
|
||||
@ -120,8 +120,8 @@ google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
|
||||
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
|
||||
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.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/container/gtype"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
@ -55,8 +56,12 @@ func (r *Registry) Watch(ctx context.Context, key string) (watcher gsvc.Watcher,
|
||||
prefix: key,
|
||||
discovery: r,
|
||||
ch: make(chan gsvc.Service, 100),
|
||||
closed: gtype.NewBool(false),
|
||||
}
|
||||
_, err = gfsnotify.Add(r.path, func(event *gfsnotify.Event) {
|
||||
if fileWatcher.closed.Val() {
|
||||
return
|
||||
}
|
||||
if event.IsChmod() {
|
||||
return
|
||||
}
|
||||
|
||||
@ -9,6 +9,8 @@ package file
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gtype"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
)
|
||||
|
||||
@ -17,11 +19,15 @@ type Watcher struct {
|
||||
prefix string // Watched prefix key, not file name prefix.
|
||||
discovery gsvc.Discovery // Service discovery.
|
||||
ch chan gsvc.Service // Changes that caused by inotify.
|
||||
closed *gtype.Bool // Whether the channel has been closed
|
||||
}
|
||||
|
||||
// Proceed proceeds watch in blocking way.
|
||||
// It returns all complete services that watched by `key` if any change.
|
||||
func (w *Watcher) Proceed() (services []gsvc.Service, err error) {
|
||||
if w.closed.Val() {
|
||||
return nil, gerror.New("discovery service was closed")
|
||||
}
|
||||
<-w.ch
|
||||
return w.discovery.Search(context.Background(), gsvc.SearchInput{
|
||||
Prefix: w.prefix,
|
||||
@ -30,6 +36,8 @@ func (w *Watcher) Proceed() (services []gsvc.Service, err error) {
|
||||
|
||||
// Close closes the watcher.
|
||||
func (w *Watcher) Close() error {
|
||||
close(w.ch)
|
||||
if w.closed.Cas(false, true) {
|
||||
close(w.ch)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ module github.com/gogf/gf/contrib/registry/file/v2
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.7.2
|
||||
require github.com/gogf/gf/v2 v2.7.4
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.3.2 // indirect
|
||||
|
||||
@ -3,8 +3,8 @@ module github.com/gogf/gf/contrib/registry/nacos/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/joy999/nacos-sdk-go v0.0.0-20231120071639-10a34b3e7288
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/nacos-group/nacos-sdk-go/v2 v2.2.7
|
||||
)
|
||||
|
||||
require (
|
||||
@ -22,7 +22,7 @@ require (
|
||||
github.com/emirpasic/gods v1.18.1 // indirect
|
||||
github.com/fatih/color v1.16.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
@ -33,7 +33,7 @@ require (
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
@ -43,7 +43,6 @@ require (
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.32.1 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
go.opentelemetry.io/otel v1.14.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.14.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.14.0 // indirect
|
||||
@ -56,9 +55,9 @@ require (
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/time v0.1.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
|
||||
google.golang.org/grpc v1.57.2 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
|
||||
google.golang.org/grpc v1.56.3 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/ini.v1 v1.66.2 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@ -96,8 +96,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
@ -168,8 +168,6 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/joy999/nacos-sdk-go v0.0.0-20231120071639-10a34b3e7288 h1:GuL6co0J2oMb2Rd/hbxZfJz1QlZr+DpIsz3Wcvok65o=
|
||||
github.com/joy999/nacos-sdk-go v0.0.0-20231120071639-10a34b3e7288/go.mod h1:xF3RcNkFUEIik3RCihkvgORtZXZXlp+OeGK0aUALVYU=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
@ -197,9 +195,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
@ -211,6 +208,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nacos-group/nacos-sdk-go/v2 v2.2.7 h1:wCC1f3/VzIR1WD30YKeJGZAOchYCK/35mLC8qWt6Q6o=
|
||||
github.com/nacos-group/nacos-sdk-go/v2 v2.2.7/go.mod h1:VYlyDPlQchPC31PmfBustu81vsOkdpCuO5k0dRdQcFc=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
@ -241,9 +240,6 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
|
||||
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
|
||||
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
@ -522,8 +518,8 @@ google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7Fc
|
||||
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 h1:0nDDozoAU19Qb2HwhXadU8OcsiO/09cnTqhUtq2MEOM=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA=
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A=
|
||||
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
@ -536,8 +532,8 @@ google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKa
|
||||
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
||||
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.57.2 h1:uw37EN34aMFFXB2QPW7Tq6tdTbind1GpRxw5aOX3a5k=
|
||||
google.golang.org/grpc v1.57.2/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
|
||||
google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc=
|
||||
google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
|
||||
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=
|
||||
@ -550,8 +546,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
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=
|
||||
|
||||
@ -17,10 +17,10 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/joy999/nacos-sdk-go/clients"
|
||||
"github.com/joy999/nacos-sdk-go/clients/naming_client"
|
||||
"github.com/joy999/nacos-sdk-go/common/constant"
|
||||
"github.com/joy999/nacos-sdk-go/vo"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/clients"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/vo"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -13,8 +13,8 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/joy999/nacos-sdk-go/model"
|
||||
"github.com/joy999/nacos-sdk-go/vo"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/model"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/vo"
|
||||
)
|
||||
|
||||
// Search searches and returns services with specified condition.
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/joy999/nacos-sdk-go/vo"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/vo"
|
||||
)
|
||||
|
||||
// Register registers `service` to Registry.
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/joy999/nacos-sdk-go/model"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/model"
|
||||
)
|
||||
|
||||
// NewServiceFromInstance new one service from instance
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/net/gsvc"
|
||||
"github.com/joy999/nacos-sdk-go/model"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/model"
|
||||
)
|
||||
|
||||
// Watcher used to mange service event such as update.
|
||||
|
||||
@ -18,7 +18,7 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"github.com/joy999/nacos-sdk-go/common/constant"
|
||||
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/polaris/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
github.com/polarismesh/polaris-go v1.5.5
|
||||
)
|
||||
|
||||
@ -52,7 +52,7 @@ require (
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
|
||||
google.golang.org/grpc v1.59.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@ -978,8 +978,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
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=
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/go-zookeeper/zk v1.0.3
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
golang.org/x/sync v0.4.0
|
||||
)
|
||||
|
||||
|
||||
@ -3,12 +3,12 @@ module github.com/gogf/gf/contrib/rpc/grpcx/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.7.4
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
go.opentelemetry.io/otel v1.14.0
|
||||
go.opentelemetry.io/otel/trace v1.14.0
|
||||
google.golang.org/grpc v1.57.2
|
||||
google.golang.org/protobuf v1.31.0
|
||||
google.golang.org/protobuf v1.33.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -61,8 +61,8 @@ google.golang.org/grpc v1.57.2 h1:uw37EN34aMFFXB2QPW7Tq6tdTbind1GpRxw5aOX3a5k=
|
||||
google.golang.org/grpc v1.57.2/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo=
|
||||
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.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
||||
@ -29,12 +29,10 @@ const (
|
||||
tracingInstrumentGrpcClient = "github.com/gogf/gf/contrib/rpc/grpcx/v2/krpc.GrpcClient"
|
||||
tracingInstrumentGrpcServer = "github.com/gogf/gf/contrib/rpc/grpcx/v2/krpc.GrpcServer"
|
||||
tracingEventGrpcRequest = "grpc.request"
|
||||
tracingEventGrpcRequestMessage = "grpc.request.message"
|
||||
tracingEventGrpcRequestBaggage = "grpc.request.baggage"
|
||||
tracingEventGrpcMetadataOutgoing = "grpc.metadata.outgoing"
|
||||
tracingEventGrpcMetadataIncoming = "grpc.metadata.incoming"
|
||||
tracingEventGrpcResponse = "grpc.response"
|
||||
tracingEventGrpcResponseMessage = "grpc.response.message"
|
||||
)
|
||||
|
||||
type metadataSupplier struct {
|
||||
|
||||
@ -19,7 +19,6 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/gogf/gf/contrib/rpc/grpcx/v2/internal/grpcctx"
|
||||
"github.com/gogf/gf/contrib/rpc/grpcx/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@ -59,25 +58,10 @@ func UnaryClientInterceptor(ctx context.Context, method string, req, reply inter
|
||||
span.AddEvent(tracingEventGrpcRequest, trace.WithAttributes(
|
||||
attribute.String(tracingEventGrpcRequestBaggage, gconv.String(gtrace.GetBaggageMap(ctx))),
|
||||
attribute.String(tracingEventGrpcMetadataOutgoing, gconv.String(grpcctx.Ctx{}.OutgoingMap(ctx))),
|
||||
attribute.String(
|
||||
tracingEventGrpcRequestMessage,
|
||||
utils.MarshalMessageToJsonStringForTracing(
|
||||
req, "Request", tracingMaxContentLogSize,
|
||||
),
|
||||
),
|
||||
))
|
||||
|
||||
err := invoker(ctx, method, req, reply, cc, callOpts...)
|
||||
|
||||
span.AddEvent(tracingEventGrpcResponse, trace.WithAttributes(
|
||||
attribute.String(
|
||||
tracingEventGrpcResponseMessage,
|
||||
utils.MarshalMessageToJsonStringForTracing(
|
||||
reply, "Response", tracingMaxContentLogSize,
|
||||
),
|
||||
),
|
||||
))
|
||||
|
||||
if err != nil {
|
||||
s, _ := status.FromError(err)
|
||||
span.SetStatus(codes.Error, s.Message())
|
||||
|
||||
@ -20,7 +20,6 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/gogf/gf/contrib/rpc/grpcx/v2/internal/grpcctx"
|
||||
"github.com/gogf/gf/contrib/rpc/grpcx/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@ -58,25 +57,10 @@ func UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.Una
|
||||
span.AddEvent(tracingEventGrpcRequest, trace.WithAttributes(
|
||||
attribute.String(tracingEventGrpcRequestBaggage, gconv.String(gtrace.GetBaggageMap(ctx))),
|
||||
attribute.String(tracingEventGrpcMetadataIncoming, gconv.String(grpcctx.Ctx{}.IncomingMap(ctx))),
|
||||
attribute.String(
|
||||
tracingEventGrpcRequestMessage,
|
||||
utils.MarshalMessageToJsonStringForTracing(
|
||||
req, "Request", tracingMaxContentLogSize,
|
||||
),
|
||||
),
|
||||
))
|
||||
|
||||
res, err := handler(ctx, req)
|
||||
|
||||
span.AddEvent(tracingEventGrpcResponse, trace.WithAttributes(
|
||||
attribute.String(
|
||||
tracingEventGrpcResponseMessage,
|
||||
utils.MarshalMessageToJsonStringForTracing(
|
||||
res, "Response", tracingMaxContentLogSize,
|
||||
),
|
||||
),
|
||||
))
|
||||
|
||||
if err != nil {
|
||||
s, _ := status.FromError(err)
|
||||
span.SetStatus(codes.Error, s.Message())
|
||||
|
||||
@ -2,7 +2,7 @@ module github.com/gogf/gf/contrib/sdk/httpclient/v2
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.7.2
|
||||
require github.com/gogf/gf/v2 v2.7.4
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.3.2 // indirect
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/jaeger/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.7.2
|
||||
github.com/gogf/gf/v2 v2.7.4
|
||||
go.opentelemetry.io/otel v1.14.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.14.0
|
||||
go.opentelemetry.io/otel/sdk v1.14.0
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user