mirror of
https://gitee.com/johng/gf
synced 2026-06-07 18:26:02 +08:00
Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fb739615b | |||
| ba39323d30 | |||
| 383937fe69 | |||
| f919f90bf5 | |||
| b4f6f06ab5 | |||
| 73fbca40ca | |||
| e8d3fcac6b | |||
| f87182d5b8 | |||
| 951f8921cd | |||
| d26b7c5437 | |||
| 9407fda197 | |||
| 905913f7be | |||
| 4b8eaac73f | |||
| ca242ff401 | |||
| 42e3c5f39a | |||
| 4f4d2c2f8e | |||
| 5a01798481 | |||
| 8af1eb693e | |||
| 335ccb32af | |||
| e1f2666499 | |||
| 22fcfdf755 | |||
| 1e21b61a19 | |||
| 6abd8bd864 | |||
| 4876ae0e2b | |||
| 63bdf41d40 | |||
| 984cca8b82 | |||
| 9f7ce42c74 | |||
| 16a43bcb6c | |||
| 85d95e3e27 | |||
| 4cce8557e6 | |||
| d60d7674d7 | |||
| 7f9467d1f8 | |||
| d08e3ef838 | |||
| 645c5ff5b5 | |||
| 7975e391f0 | |||
| 565790036e | |||
| 44819b135e | |||
| bb19877430 | |||
| fc02e06423 | |||
| dd8a5dcf32 | |||
| 33584506ab | |||
| ee2cf92479 | |||
| 0b6dd6fb13 | |||
| 993467bb3c | |||
| c7c9f0011a | |||
| 9aa872e705 | |||
| ea5d52cb2f | |||
| b1754f8254 | |||
| 83f08b3135 | |||
| d3d1f94e40 | |||
| fc8572e8dd | |||
| 85acd3d31d | |||
| 9694a68211 | |||
| 0be8b29e42 | |||
| 5580ac9475 | |||
| 84ed66018e | |||
| 4d7f9552fe |
38
.github/ISSUE_TEMPLATE.MD
vendored
38
.github/ISSUE_TEMPLATE.MD
vendored
@ -1,38 +0,0 @@
|
||||
<!-- Please answer these questions before submitting your issue. Thanks! -->
|
||||
|
||||
<!-- 为高效处理您的疑问,如果觉得是BUG类问题,请您务必提供可复现该问题的最小可运行代码!否则issue可能会被延期处理! -->
|
||||
<!-- 为高效处理您的疑问,如果觉得是BUG类问题,请您务必提供可复现该问题的最小可运行代码!否则issue可能会被延期处理! -->
|
||||
<!-- 为高效处理您的疑问,如果觉得是BUG类问题,请您务必提供可复现该问题的最小可运行代码!否则issue可能会被延期处理! -->
|
||||
<!-- 重要的事情说三遍! -->
|
||||
|
||||
### 1. What version of `Go` and system type/arch are you using?
|
||||
<!--
|
||||
Please paste the output of command `go version` from your terminal.
|
||||
What expect to see is like: `go 1.12, linux/amd64`
|
||||
-->
|
||||
|
||||
|
||||
### 2. What version of `GoFrame` are you using?
|
||||
<!-- You can find the GF version from your `go.mod`, or from the `version.go` in `GF` -->
|
||||
|
||||
|
||||
### 3. Can this issue be re-produced with the latest release?
|
||||
|
||||
|
||||
|
||||
### 4. What did you do?
|
||||
<!--
|
||||
If possible, provide a copy of shortest codes for reproducing the error.
|
||||
A complete runnable program is best.
|
||||
-->
|
||||
|
||||
|
||||
|
||||
### 5. What did you expect to see?
|
||||
|
||||
|
||||
|
||||
### 6. What did you see instead?
|
||||
|
||||
|
||||
|
||||
41
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
41
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- Please answer these questions before submitting your issue. Thanks! -->
|
||||
|
||||
<!-- 为高效处理 Bug,请您务必提供可复现该问题的最小可运行代码!否则 issue 可能会被延期处理! -->
|
||||
<!-- 为高效处理 Bug,请您务必提供可复现该问题的最小可运行代码!否则 issue 可能会被延期处理! -->
|
||||
<!-- 为高效处理 Bug,如请您务必提供可复现该问题的最小可运行代码!否则 issue 可能会被延期处理! -->
|
||||
<!-- 重要的事情说三遍! -->
|
||||
|
||||
**What version of `Go` and system type/arch are you using?**
|
||||
<!--
|
||||
Please paste the output of command `go version` from your terminal.
|
||||
What expects to see is like: `go 1.12, linux/amd64`
|
||||
-->
|
||||
|
||||
|
||||
**What version of `GoFrame` are you using?**
|
||||
<!-- You can find the GF version from your `go.mod`, or from the `version.go` in `GF` -->
|
||||
|
||||
|
||||
**Can this bug be re-produced with the latest release?**
|
||||
|
||||
|
||||
**What did you do?**
|
||||
<!--
|
||||
If possible, provide a copy of shortest codes for reproducing the error.
|
||||
A complete runnable program is best.
|
||||
-->
|
||||
|
||||
|
||||
**What did you expect to see?**
|
||||
|
||||
|
||||
**What did you see instead?**
|
||||
16
.github/ISSUE_TEMPLATE/enhancement-request.md
vendored
Normal file
16
.github/ISSUE_TEMPLATE/enhancement-request.md
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
name: Enhancement request
|
||||
about: Enhance an idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Package that You wish to enhance**
|
||||
|
||||
|
||||
**Enhancement description**
|
||||
|
||||
|
||||
**Additional**
|
||||
19
.github/ISSUE_TEMPLATE/feature-request.md
vendored
Normal file
19
.github/ISSUE_TEMPLATE/feature-request.md
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: feature
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
|
||||
|
||||
**Describe the solution you'd like**
|
||||
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
|
||||
|
||||
**Additional**
|
||||
11
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
11
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
name: Question
|
||||
about: I want to ask a question
|
||||
title: ''
|
||||
labels: question
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- 请优先仔细阅读文档 -->
|
||||
**What do you want to ask**
|
||||
6
.github/workflows/gitee-sync.yml
vendored
6
.github/workflows/gitee-sync.yml
vendored
@ -1,7 +1,7 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
@ -13,8 +13,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v4
|
||||
- name: Mirror Github to Gitee
|
||||
uses: Yikun/hub-mirror-action@v1.2
|
||||
- name: Mirror GitHub to Gitee
|
||||
uses: Yikun/hub-mirror-action@v1.3
|
||||
with:
|
||||
src: github/gogf
|
||||
dst: gitee/johng
|
||||
|
||||
2
.github/workflows/golangci-lint.yml
vendored
2
.github/workflows/golangci-lint.yml
vendored
@ -36,7 +36,7 @@ jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ '1.18','1.19','1.20','1.21' ]
|
||||
go-version: [ '1.18','1.19','1.20','1.21.4' ]
|
||||
name: golangci-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Parameter exception, please execute in the format of $0 [directory] [version number]"
|
||||
echo "PS:$0 ./ v2.4.0"
|
||||
@ -20,6 +19,13 @@ workdir=.
|
||||
newVersion=$2
|
||||
echo "Prepare to replace the GF library version numbers in all go.mod files in the ${workdir} directory with ${newVersion}"
|
||||
|
||||
# check find command support or not
|
||||
output=$(find "${workdir}" -name go.mod 2>&1)
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Error: please use bash or zsh to run!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ true ]]; then
|
||||
echo "package gf" > version.go
|
||||
echo "" >> version.go
|
||||
|
||||
11
README.MD
11
README.MD
@ -7,8 +7,17 @@
|
||||
[](https://github.com/gogf/gf/actions/workflows/ci-main.yml)
|
||||
[](https://goreportcard.com/report/github.com/gogf/gf/v2)
|
||||
[](https://codecov.io/gh/gogf/gf)
|
||||
[](https://github.com/gogf/gf)
|
||||
[](https://github.com/gogf/gf)
|
||||
[](https://github.com/gogf/gf)
|
||||
|
||||
[](https://github.com/gogf/gf/releases)
|
||||
[](https://github.com/gogf/gf/pulls)
|
||||
[](https://github.com/gogf/gf/pulls?q=is%3Apr+is%3Aclosed)
|
||||
[](https://github.com/gogf/gf/issues)
|
||||
[](https://github.com/gogf/gf/issues?q=is%3Aissue+is%3Aclosed)
|
||||

|
||||

|
||||
|
||||
</div>
|
||||
|
||||
`GoFrame` is a modular, powerful, high-performance and enterprise-class application development framework of Golang.
|
||||
|
||||
@ -7,20 +7,21 @@
|
||||
package gfcmd
|
||||
|
||||
import (
|
||||
_ "github.com/gogf/gf/cmd/gf/v2/internal/packed"
|
||||
"context"
|
||||
"runtime"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd"
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcfg"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd"
|
||||
_ "github.com/gogf/gf/cmd/gf/v2/internal/packed"
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -99,6 +100,9 @@ func GetCommand(ctx context.Context) (*Command, error) {
|
||||
|
||||
// zsh alias "git fetch" conflicts checks.
|
||||
func handleZshAlias() {
|
||||
if runtime.GOOS == "windows" {
|
||||
return
|
||||
}
|
||||
if home, err := gfile.Home(); err == nil {
|
||||
zshPath := gfile.Join(home, ".zshrc")
|
||||
if gfile.Exists(zshPath) {
|
||||
|
||||
@ -3,14 +3,14 @@ module github.com/gogf/gf/cmd/gf/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.5.6
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.6
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.6
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.6
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.6
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/minio/selfupdate v0.6.0
|
||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.6.2
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
golang.org/x/mod v0.9.0
|
||||
golang.org/x/tools v0.7.0
|
||||
@ -24,7 +24,7 @@ require (
|
||||
github.com/denisenkom/go-mssqldb v0.12.3 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/glebarez/go-sqlite v1.21.2 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
@ -37,7 +37,7 @@ require (
|
||||
github.com/lib/pq v1.10.9 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/paulmach/orb v0.7.1 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.14 // indirect
|
||||
|
||||
@ -23,8 +23,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
|
||||
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
@ -38,6 +38,8 @@ 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/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=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||
@ -67,14 +69,12 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/minio/selfupdate v0.6.0 h1:i76PgT0K5xO9+hjzKcacQtO7+MjJ4JKA8Ak8XQ9DDwU=
|
||||
github.com/minio/selfupdate v0.6.0/go.mod h1:bO02GTIPCMQFTEvE5h4DjYB58bCoZ35XLeBf0buTDdM=
|
||||
github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615/go.mod h1:Ad7oeElCZqA1Ufj0U9/liOF4BtVepxRcTvr2ey7zTvM=
|
||||
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
@ -126,7 +126,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
@ -159,7 +158,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -55,6 +55,7 @@ func (c cGF) Index(ctx context.Context, in cGFInput) (out *cGFOutput, err error)
|
||||
_, err = Version.Index(ctx, cVersionInput{})
|
||||
return
|
||||
}
|
||||
|
||||
answer := "n"
|
||||
// No argument or option, do installation checks.
|
||||
if data, isInstalled := service.Install.IsInstalled(); !isInstalled {
|
||||
@ -71,6 +72,7 @@ func (c cGF) Index(ctx context.Context, in cGFInput) (out *cGFOutput, err error)
|
||||
gcmd.Scan("press `Enter` to exit...")
|
||||
return
|
||||
}
|
||||
|
||||
// Print help content.
|
||||
gcmd.CommandFromCtx(ctx).Print()
|
||||
return
|
||||
|
||||
@ -44,8 +44,9 @@ type cBuild struct {
|
||||
}
|
||||
|
||||
const (
|
||||
cBuildBrief = `cross-building go project for lots of platforms`
|
||||
cBuildEg = `
|
||||
cBuildDefaultFile = "main.go"
|
||||
cBuildBrief = `cross-building go project for lots of platforms`
|
||||
cBuildEg = `
|
||||
gf build main.go
|
||||
gf build main.go --ps public,template
|
||||
gf build main.go --cgo
|
||||
@ -123,7 +124,7 @@ type cBuildInput struct {
|
||||
Arch string `short:"a" name:"arch" brief:"output binary architecture, multiple arch separated with ','"`
|
||||
System string `short:"s" name:"system" brief:"output binary system, multiple os separated with ','"`
|
||||
Output string `short:"o" name:"output" brief:"output binary path, used when building single binary file"`
|
||||
Path string `short:"p" name:"path" brief:"output binary directory path, default is './temp'" d:"./temp"`
|
||||
Path string `short:"p" name:"path" brief:"output binary directory path, default is '.'" d:"."`
|
||||
Extra string `short:"e" name:"extra" brief:"extra custom \"go build\" options"`
|
||||
Mod string `short:"m" name:"mod" brief:"like \"-mod\" option of \"go build\", use \"-m none\" to disable go module"`
|
||||
Cgo bool `short:"c" name:"cgo" brief:"enable or disable cgo feature, it's disabled in default" orphan:"true"`
|
||||
@ -152,12 +153,13 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
|
||||
|
||||
var (
|
||||
parser = gcmd.ParserFromCtx(ctx)
|
||||
file = parser.GetArg(2).String()
|
||||
file = in.File
|
||||
)
|
||||
if len(file) < 1 {
|
||||
if file == "" {
|
||||
file = parser.GetArg(2).String()
|
||||
// Check and use the main.go file.
|
||||
if gfile.Exists("main.go") {
|
||||
file = "main.go"
|
||||
if gfile.Exists(cBuildDefaultFile) {
|
||||
file = cBuildDefaultFile
|
||||
} else {
|
||||
mlog.Fatal("build file path is empty or main.go not found in current working directory")
|
||||
}
|
||||
@ -239,13 +241,7 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
|
||||
} else {
|
||||
genv.MustSet("CGO_ENABLED", "0")
|
||||
}
|
||||
var (
|
||||
cmd = ""
|
||||
ext = ""
|
||||
)
|
||||
for system, item := range platformMap {
|
||||
cmd = ""
|
||||
ext = ""
|
||||
if len(customSystems) > 0 && customSystems[0] != "all" && !gstr.InArray(customSystems, system) {
|
||||
continue
|
||||
}
|
||||
@ -258,57 +254,22 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
|
||||
// For example:
|
||||
// `gf build`
|
||||
// `gf build -o main.exe`
|
||||
if runtime.GOOS == "windows" {
|
||||
ext = ".exe"
|
||||
}
|
||||
var outputPath string
|
||||
if len(in.Output) > 0 {
|
||||
outputPath = "-o " + in.Output
|
||||
} else {
|
||||
outputPath = "-o " + in.Name + ext
|
||||
}
|
||||
cmd = fmt.Sprintf(
|
||||
`go build %s -ldflags "%s" %s %s`,
|
||||
outputPath, ldFlags, in.Extra, file,
|
||||
c.doBinaryBuild(
|
||||
ctx, file,
|
||||
in.Output, in.Path,
|
||||
runtime.GOOS, runtime.GOARCH, in.Name, ldFlags, in.Extra,
|
||||
in.ExitWhenError,
|
||||
true,
|
||||
)
|
||||
} else {
|
||||
// Cross-building, output the compiled binary to specified path.
|
||||
if system == "windows" {
|
||||
ext = ".exe"
|
||||
}
|
||||
genv.MustSet("GOOS", system)
|
||||
genv.MustSet("GOARCH", arch)
|
||||
|
||||
var outputPath string
|
||||
if len(in.Output) > 0 {
|
||||
outputPath = "-o " + in.Output
|
||||
} else {
|
||||
outputPath = fmt.Sprintf(
|
||||
"-o %s/%s/%s%s",
|
||||
in.Path, system+"_"+arch, in.Name, ext,
|
||||
)
|
||||
}
|
||||
cmd = fmt.Sprintf(
|
||||
`GOOS=%s GOARCH=%s go build %s -ldflags "%s" %s%s`,
|
||||
system, arch, outputPath, ldFlags, in.Extra, file,
|
||||
c.doBinaryBuild(
|
||||
ctx, file,
|
||||
in.Output, in.Path,
|
||||
system, arch, in.Name, ldFlags, in.Extra,
|
||||
in.ExitWhenError,
|
||||
false,
|
||||
)
|
||||
}
|
||||
mlog.Debug(cmd)
|
||||
// It's not necessary printing the complete command string.
|
||||
cmdShow, _ := gregex.ReplaceString(`\s+(-ldflags ".+?")\s+`, " ", cmd)
|
||||
mlog.Print(cmdShow)
|
||||
if result, err := gproc.ShellExec(ctx, cmd); err != nil {
|
||||
mlog.Printf(
|
||||
"failed to build, os:%s, arch:%s, error:\n%s\n\n%s\n",
|
||||
system, arch, gstr.Trim(result),
|
||||
`you may use command option "--debug" to enable debug info and check the details`,
|
||||
)
|
||||
if in.ExitWhenError {
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
mlog.Debug(gstr.Trim(result))
|
||||
}
|
||||
// single binary building.
|
||||
if len(customSystems) == 0 && len(customArches) == 0 {
|
||||
goto buildDone
|
||||
@ -321,6 +282,68 @@ buildDone:
|
||||
return
|
||||
}
|
||||
|
||||
func (c cBuild) doBinaryBuild(
|
||||
ctx context.Context,
|
||||
filePath string,
|
||||
outputPath, dirPath string,
|
||||
system, arch, name, ldFlags, extra string,
|
||||
exitWhenError bool,
|
||||
singleBuild bool,
|
||||
) {
|
||||
var (
|
||||
cmd string
|
||||
ext string
|
||||
)
|
||||
// Cross-building, output the compiled binary to specified path.
|
||||
if system == "windows" {
|
||||
ext = ".exe"
|
||||
}
|
||||
genv.MustSet("GOOS", system)
|
||||
genv.MustSet("GOARCH", arch)
|
||||
|
||||
if outputPath != "" {
|
||||
outputPath = "-o " + outputPath
|
||||
} else {
|
||||
if dirPath == "" {
|
||||
dirPath = "."
|
||||
} else {
|
||||
dirPath = gstr.TrimRight(dirPath, "/")
|
||||
}
|
||||
if singleBuild {
|
||||
outputPath = fmt.Sprintf(
|
||||
"-o %s/%s%s",
|
||||
dirPath, name, ext,
|
||||
)
|
||||
} else {
|
||||
outputPath = fmt.Sprintf(
|
||||
"-o %s/%s/%s%s",
|
||||
dirPath, system+"_"+arch, name, ext,
|
||||
)
|
||||
}
|
||||
}
|
||||
cmd = fmt.Sprintf(
|
||||
`go build %s -ldflags "%s" %s%s`,
|
||||
outputPath, ldFlags, extra, filePath,
|
||||
)
|
||||
mlog.Debug(fmt.Sprintf("build for GOOS=%s GOARCH=%s", system, arch))
|
||||
mlog.Debug(cmd)
|
||||
// It's not necessary printing the complete command string, filtering ldFlags.
|
||||
cmdShow, _ := gregex.ReplaceString(`\s+(-ldflags ".+?")\s+`, " ", cmd)
|
||||
mlog.Print(cmdShow)
|
||||
if result, err := gproc.ShellExec(ctx, cmd); err != nil {
|
||||
mlog.Printf(
|
||||
"failed to build, os:%s, arch:%s, error:\n%s\n\n%s\n",
|
||||
system, arch, gstr.Trim(result),
|
||||
`you may use command option "--debug" to enable debug info and check the details`,
|
||||
)
|
||||
if exitWhenError {
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
mlog.Debug(gstr.Trim(result))
|
||||
}
|
||||
}
|
||||
|
||||
// getBuildInVarStr retrieves and returns the custom build-in variables in configuration
|
||||
// file as json.
|
||||
func (c cBuild) getBuildInVarStr(ctx context.Context, in cBuildInput) string {
|
||||
|
||||
@ -82,11 +82,11 @@ func init() {
|
||||
type (
|
||||
cRunInput struct {
|
||||
g.Meta `name:"run"`
|
||||
File string `name:"FILE" arg:"true" brief:"{cRunFileBrief}" v:"required"`
|
||||
Path string `name:"path" short:"p" brief:"{cRunPathBrief}" d:"./"`
|
||||
Extra string `name:"extra" short:"e" brief:"{cRunExtraBrief}"`
|
||||
Args string `name:"args" short:"a" brief:"{cRunArgsBrief}"`
|
||||
WatchPaths string `name:"watchPaths" short:"w" brief:"{cRunWatchPathsBrief}"`
|
||||
File string `name:"FILE" arg:"true" brief:"{cRunFileBrief}" v:"required"`
|
||||
Path string `name:"path" short:"p" brief:"{cRunPathBrief}" d:"./"`
|
||||
Extra string `name:"extra" short:"e" brief:"{cRunExtraBrief}"`
|
||||
Args string `name:"args" short:"a" brief:"{cRunArgsBrief}"`
|
||||
WatchPaths []string `name:"watchPaths" short:"w" brief:"{cRunWatchPathsBrief}"`
|
||||
}
|
||||
cRunOutput struct{}
|
||||
)
|
||||
@ -97,12 +97,16 @@ func (c cRun) Index(ctx context.Context, in cRunInput) (out *cRunOutput, err err
|
||||
mlog.Fatalf(`command "go" not found in your environment, please install golang first to proceed this command`)
|
||||
}
|
||||
|
||||
if len(in.WatchPaths) == 1 {
|
||||
in.WatchPaths = strings.Split(in.WatchPaths[0], ",")
|
||||
}
|
||||
|
||||
app := &cRunApp{
|
||||
File: in.File,
|
||||
Path: in.Path,
|
||||
Options: in.Extra,
|
||||
Args: in.Args,
|
||||
WatchPaths: strings.Split(in.WatchPaths, ","),
|
||||
WatchPaths: in.WatchPaths,
|
||||
}
|
||||
dirty := gtype.NewBool()
|
||||
_, err = gfsnotify.Add(gfile.RealPath("."), func(event *gfsnotify.Event) {
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/minio/selfupdate"
|
||||
"github.com/gogf/selfupdate"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
|
||||
|
||||
@ -7,14 +7,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gbuild"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
|
||||
@ -25,6 +30,10 @@ var (
|
||||
Version = cVersion{}
|
||||
)
|
||||
|
||||
const (
|
||||
defaultIndent = "{{indent}}"
|
||||
)
|
||||
|
||||
type cVersion struct {
|
||||
g.Meta `name:"version" brief:"show version information of current binary"`
|
||||
}
|
||||
@ -36,34 +45,90 @@ type cVersionInput struct {
|
||||
type cVersionOutput struct{}
|
||||
|
||||
func (c cVersion) Index(ctx context.Context, in cVersionInput) (*cVersionOutput, error) {
|
||||
info := gbuild.Info()
|
||||
if info.Git == "" {
|
||||
info.Git = "none"
|
||||
}
|
||||
mlog.Printf(`GoFrame CLI Tool %s, https://goframe.org`, gf.VERSION)
|
||||
gfVersion, err := c.getGFVersionOfCurrentProject()
|
||||
if err != nil {
|
||||
gfVersion = err.Error()
|
||||
detailBuffer := &detailBuffer{}
|
||||
detailBuffer.WriteString(fmt.Sprintf("%s", gf.VERSION))
|
||||
|
||||
detailBuffer.appendLine(0, "Welcome to GoFrame!")
|
||||
|
||||
detailBuffer.appendLine(0, "Env Detail:")
|
||||
goVersion, ok := getGoVersion()
|
||||
if ok {
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("Go Version: %s", goVersion))
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("GF Version(go.mod): %s", getGoFrameVersion(2)))
|
||||
} else {
|
||||
gfVersion = gfVersion + " in current go.mod"
|
||||
}
|
||||
mlog.Printf(`GoFrame Version: %s`, gfVersion)
|
||||
mlog.Printf(`CLI Installed At: %s`, gfile.SelfPath())
|
||||
if info.GoFrame == "" {
|
||||
mlog.Print(`Current is a custom installed version, no installation information.`)
|
||||
return nil, nil
|
||||
v, err := c.getGFVersionOfCurrentProject()
|
||||
if err == nil {
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("GF Version(go.mod): %s", v))
|
||||
} else {
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("GF Version(go.mod): %s", err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
mlog.Print(gstr.Trim(fmt.Sprintf(`
|
||||
CLI Built Detail:
|
||||
Go Version: %s
|
||||
GF Version: %s
|
||||
Git Commit: %s
|
||||
Build Time: %s
|
||||
`, info.Golang, info.GoFrame, info.Git, info.Time)))
|
||||
detailBuffer.appendLine(0, "CLI Detail:")
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("Installed At: %s", gfile.SelfPath()))
|
||||
info := gbuild.Info()
|
||||
if info.GoFrame == "" {
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("Built Go Version: %s", runtime.Version()))
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("Built GF Version: %s", gf.VERSION))
|
||||
} else {
|
||||
if info.Git == "" {
|
||||
info.Git = "none"
|
||||
}
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("Built Go Version: %s", info.Golang))
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("Built GF Version: %s", info.GoFrame))
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("Git Commit: %s", info.Git))
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("Built Time: %s", info.Time))
|
||||
}
|
||||
|
||||
detailBuffer.appendLine(0, "Others Detail:")
|
||||
detailBuffer.appendLine(1, "Docs: https://goframe.org")
|
||||
detailBuffer.appendLine(1, fmt.Sprintf("Now : %s", time.Now().Format(time.RFC3339)))
|
||||
|
||||
mlog.Print(detailBuffer.replaceAllIndent(" "))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// detailBuffer is a buffer for detail information.
|
||||
type detailBuffer struct {
|
||||
bytes.Buffer
|
||||
}
|
||||
|
||||
// appendLine appends a line to the buffer with given indent level.
|
||||
func (d *detailBuffer) appendLine(indentLevel int, line string) {
|
||||
d.WriteString(fmt.Sprintf("\n%s%s", strings.Repeat(defaultIndent, indentLevel), line))
|
||||
}
|
||||
|
||||
// replaceAllIndent replaces the tab with given indent string and prints the buffer content.
|
||||
func (d *detailBuffer) replaceAllIndent(indentStr string) string {
|
||||
return strings.ReplaceAll(d.String(), defaultIndent, indentStr)
|
||||
}
|
||||
|
||||
// getGoFrameVersion returns the goframe version of current project using.
|
||||
func getGoFrameVersion(indentLevel int) (gfVersion string) {
|
||||
pkgInfo, err := gproc.ShellExec(context.Background(), `go list -f "{{if (not .Main)}}{{.Path}}@{{.Version}}{{end}}" -m all`)
|
||||
if err != nil {
|
||||
return "cannot find go.mod"
|
||||
}
|
||||
pkgList := gstr.Split(pkgInfo, "\n")
|
||||
for _, v := range pkgList {
|
||||
if strings.HasPrefix(v, "github.com/gogf/gf") {
|
||||
gfVersion += fmt.Sprintf("\n%s%s", strings.Repeat(defaultIndent, indentLevel), v)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// getGoVersion returns the go version
|
||||
func getGoVersion() (goVersion string, ok bool) {
|
||||
goVersion, err := gproc.ShellExec(context.Background(), "go version")
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
goVersion = gstr.TrimLeftStr(goVersion, "go version ")
|
||||
goVersion = gstr.TrimRightStr(goVersion, "\n")
|
||||
return goVersion, true
|
||||
}
|
||||
|
||||
// getGFVersionOfCurrentProject checks and returns the GoFrame version current project using.
|
||||
func (c cVersion) getGFVersionOfCurrentProject() (string, error) {
|
||||
goModPath := gfile.Join(gfile.Pwd(), "go.mod")
|
||||
|
||||
@ -6,6 +6,33 @@
|
||||
|
||||
package cmd
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
var ctx = context.Background()
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
var (
|
||||
ctx = context.Background()
|
||||
testDB gdb.DB
|
||||
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test?loc=Local&parseTime=true"
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
testDB, err = gdb.New(gdb.ConfigNode{
|
||||
Link: link,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func dropTableWithDb(db gdb.DB, table string) {
|
||||
dropTableStmt := fmt.Sprintf("DROP TABLE IF EXISTS `%s`", table)
|
||||
if _, err := db.Exec(ctx, dropTableStmt); err != nil {
|
||||
gtest.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
151
cmd/gf/internal/cmd/cmd_z_unit_build_test.go
Normal file
151
cmd/gf/internal/cmd/cmd_z_unit_build_test.go
Normal file
@ -0,0 +1,151 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
func Test_Build_Single(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `single`)
|
||||
pwd = gfile.Pwd()
|
||||
binaryName = `t.test`
|
||||
binaryPath = gtest.DataPath(`build`, `single`, binaryName)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPath), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
File: cBuildDefaultFile,
|
||||
Name: binaryName,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPath), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Build_Single_Output(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `single`)
|
||||
pwd = gfile.Pwd()
|
||||
binaryName = `tt`
|
||||
binaryDirPath = gtest.DataPath(`build`, `single`, `tt`)
|
||||
binaryPath = gtest.DataPath(`build`, `single`, `tt`, binaryName)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryDirPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPath), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
Output: "./tt/tt",
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPath), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Build_Single_Path(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `single`)
|
||||
pwd = gfile.Pwd()
|
||||
dirName = "ttt"
|
||||
binaryName = `main`
|
||||
binaryDirPath = gtest.DataPath(`build`, `single`, dirName)
|
||||
binaryPath = gtest.DataPath(`build`, `single`, dirName, binaryName)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryDirPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPath), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
Path: "ttt",
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPath), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Build_Single_VarMap(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `varmap`)
|
||||
pwd = gfile.Pwd()
|
||||
binaryName = `main`
|
||||
binaryPath = gtest.DataPath(`build`, `varmap`, binaryName)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPath), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
VarMap: map[string]interface{}{
|
||||
"a": "1",
|
||||
"b": "2",
|
||||
},
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPath), true)
|
||||
|
||||
result, err := gproc.ShellExec(ctx, binaryPath)
|
||||
t.AssertNil(err)
|
||||
t.Assert(gstr.Contains(result, `a: 1`), true)
|
||||
t.Assert(gstr.Contains(result, `b: 2`), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Build_Multiple(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `multiple`)
|
||||
pwd = gfile.Pwd()
|
||||
binaryDirPath = gtest.DataPath(`build`, `multiple`, `temp`)
|
||||
binaryPathLinux = gtest.DataPath(`build`, `multiple`, `temp`, `v1.1`, `linux_amd64`, `ttt`)
|
||||
binaryPathWindows = gtest.DataPath(`build`, `multiple`, `temp`, `v1.1`, `windows_amd64`, `ttt.exe`)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryDirPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPathLinux), false)
|
||||
t.Assert(gfile.Exists(binaryPathWindows), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
File: "multiple.go",
|
||||
Name: "ttt",
|
||||
Version: "v1.1",
|
||||
Arch: "amd64",
|
||||
System: "linux, windows",
|
||||
Path: "temp",
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPathLinux), true)
|
||||
t.Assert(gfile.Exists(binaryPathWindows), true)
|
||||
})
|
||||
}
|
||||
@ -7,13 +7,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genctrl"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Gen_Ctrl_Default(t *testing.T) {
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
@ -20,22 +19,11 @@ import (
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
)
|
||||
|
||||
func dropTableWithDb(db gdb.DB, table string) {
|
||||
dropTableStmt := fmt.Sprintf("DROP TABLE IF EXISTS `%s`", table)
|
||||
if _, err := db.Exec(ctx, dropTableStmt); err != nil {
|
||||
gtest.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Gen_Dao_Default(t *testing.T) {
|
||||
link := "mysql:root:12345678@tcp(127.0.0.1:3306)/test?loc=Local&parseTime=true"
|
||||
db, err := gdb.New(gdb.ConfigNode{
|
||||
Link: link,
|
||||
})
|
||||
gtest.AssertNil(err)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
db = testDB
|
||||
table = "table_user"
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`gendao`, `user.tpl.sql`),
|
||||
@ -123,14 +111,10 @@ func Test_Gen_Dao_Default(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Gen_Dao_TypeMapping(t *testing.T) {
|
||||
link := "mysql:root:12345678@tcp(127.0.0.1:3306)/test?loc=Local&parseTime=true"
|
||||
db, err := gdb.New(gdb.ConfigNode{
|
||||
Link: link,
|
||||
})
|
||||
gtest.AssertNil(err)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
db = testDB
|
||||
table = "table_user"
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`gendao`, `user.tpl.sql`),
|
||||
|
||||
70
cmd/gf/internal/cmd/cmd_z_unit_gen_pbentity_test.go
Normal file
70
cmd/gf/internal/cmd/cmd_z_unit_gen_pbentity_test.go
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
)
|
||||
|
||||
func Test_Gen_Pbentity_NameCase(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
err error
|
||||
db = testDB
|
||||
table = "table_user"
|
||||
sqlContent = fmt.Sprintf(
|
||||
gtest.DataContent(`genpbentity`, `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())
|
||||
err = gfile.Mkdir(path)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
root, err := gcmd.NewFromObject(GF)
|
||||
t.AssertNil(err)
|
||||
err = root.AddObject(
|
||||
Gen,
|
||||
)
|
||||
t.AssertNil(err)
|
||||
os.Args = []string{"gf", "gen", "pbentity", "-l", link, "-p", path, "-package=unittest", "-nameCase=SnakeScreaming"}
|
||||
|
||||
err = root.RunWithError(ctx)
|
||||
t.AssertNil(err)
|
||||
|
||||
files := []string{
|
||||
filepath.FromSlash(path + "/table_user.proto"),
|
||||
}
|
||||
|
||||
testPath := gtest.DataPath("genpbentity", "generated_user")
|
||||
expectFiles := []string{
|
||||
filepath.FromSlash(testPath + "/table_user.proto"),
|
||||
}
|
||||
// check files content
|
||||
for i := range files {
|
||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -7,13 +7,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genservice"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Gen_Service_Default(t *testing.T) {
|
||||
|
||||
@ -74,7 +74,7 @@ type (
|
||||
SdkStdVersion bool `short:"v" name:"sdkStdVersion" brief:"{CGenCtrlBriefSdkStdVersion}" orphan:"true"`
|
||||
SdkNoV1 bool `short:"n" name:"sdkNoV1" brief:"{CGenCtrlBriefSdkNoV1}" orphan:"true"`
|
||||
Clear bool `short:"c" name:"clear" brief:"{CGenCtrlBriefClear}" orphan:"true"`
|
||||
Merge bool `short:"m" name:"merge" brief:"{CGenCtrlControllerMerge}" orphan:"true"`
|
||||
Merge bool `short:"m" name:"merge" brief:"{CGenCtrlControllerMerge}" orphan:"true"`
|
||||
}
|
||||
CGenCtrlOutput struct{}
|
||||
)
|
||||
|
||||
@ -59,28 +59,29 @@ CONFIGURATION SUPPORT
|
||||
numeric:
|
||||
type: string
|
||||
`
|
||||
CGenDaoBriefPath = `directory path for generated files`
|
||||
CGenDaoBriefLink = `database configuration, the same as the ORM configuration of GoFrame`
|
||||
CGenDaoBriefTables = `generate models only for given tables, multiple table names separated with ','`
|
||||
CGenDaoBriefTablesEx = `generate models excluding given tables, multiple table names separated with ','`
|
||||
CGenDaoBriefPrefix = `add prefix for all table of specified link/database tables`
|
||||
CGenDaoBriefRemovePrefix = `remove specified prefix of the table, multiple prefix separated with ','`
|
||||
CGenDaoBriefStdTime = `use time.Time from stdlib instead of gtime.Time for generated time/date fields of tables`
|
||||
CGenDaoBriefWithTime = `add created time for auto produced go files`
|
||||
CGenDaoBriefGJsonSupport = `use gJsonSupport to use *gjson.Json instead of string for generated json fields of tables`
|
||||
CGenDaoBriefImportPrefix = `custom import prefix for generated go files`
|
||||
CGenDaoBriefDaoPath = `directory path for storing generated dao files under path`
|
||||
CGenDaoBriefDoPath = `directory path for storing generated do files under path`
|
||||
CGenDaoBriefEntityPath = `directory path for storing generated entity files under path`
|
||||
CGenDaoBriefOverwriteDao = `overwrite all dao files both inside/outside internal folder`
|
||||
CGenDaoBriefModelFile = `custom file name for storing generated model content`
|
||||
CGenDaoBriefModelFileForDao = `custom file name generating model for DAO operations like Where/Data. It's empty in default`
|
||||
CGenDaoBriefDescriptionTag = `add comment to description tag for each field`
|
||||
CGenDaoBriefNoJsonTag = `no json tag will be added for each field`
|
||||
CGenDaoBriefNoModelComment = `no model comment will be added for each field`
|
||||
CGenDaoBriefClear = `delete all generated go files that do not exist in database`
|
||||
CGenDaoBriefTypeMapping = `custom local type mapping for generated struct attributes relevant to fields of table`
|
||||
CGenDaoBriefGroup = `
|
||||
CGenDaoBriefPath = `directory path for generated files`
|
||||
CGenDaoBriefLink = `database configuration, the same as the ORM configuration of GoFrame`
|
||||
CGenDaoBriefTables = `generate models only for given tables, multiple table names separated with ','`
|
||||
CGenDaoBriefTablesEx = `generate models excluding given tables, multiple table names separated with ','`
|
||||
CGenDaoBriefPrefix = `add prefix for all table of specified link/database tables`
|
||||
CGenDaoBriefRemovePrefix = `remove specified prefix of the table, multiple prefix separated with ','`
|
||||
CGenDaoBriefRemoveFieldPrefix = `remove specified prefix of the field, multiple prefix separated with ','`
|
||||
CGenDaoBriefStdTime = `use time.Time from stdlib instead of gtime.Time for generated time/date fields of tables`
|
||||
CGenDaoBriefWithTime = `add created time for auto produced go files`
|
||||
CGenDaoBriefGJsonSupport = `use gJsonSupport to use *gjson.Json instead of string for generated json fields of tables`
|
||||
CGenDaoBriefImportPrefix = `custom import prefix for generated go files`
|
||||
CGenDaoBriefDaoPath = `directory path for storing generated dao files under path`
|
||||
CGenDaoBriefDoPath = `directory path for storing generated do files under path`
|
||||
CGenDaoBriefEntityPath = `directory path for storing generated entity files under path`
|
||||
CGenDaoBriefOverwriteDao = `overwrite all dao files both inside/outside internal folder`
|
||||
CGenDaoBriefModelFile = `custom file name for storing generated model content`
|
||||
CGenDaoBriefModelFileForDao = `custom file name generating model for DAO operations like Where/Data. It's empty in default`
|
||||
CGenDaoBriefDescriptionTag = `add comment to description tag for each field`
|
||||
CGenDaoBriefNoJsonTag = `no json tag will be added for each field`
|
||||
CGenDaoBriefNoModelComment = `no model comment will be added for each field`
|
||||
CGenDaoBriefClear = `delete all generated go files that do not exist in database`
|
||||
CGenDaoBriefTypeMapping = `custom local type mapping for generated struct attributes relevant to fields of table`
|
||||
CGenDaoBriefGroup = `
|
||||
specifying the configuration group name of database for generated ORM instance,
|
||||
it's not necessary and the default value is "default"
|
||||
`
|
||||
@ -145,6 +146,7 @@ func init() {
|
||||
`CGenDaoBriefTablesEx`: CGenDaoBriefTablesEx,
|
||||
`CGenDaoBriefPrefix`: CGenDaoBriefPrefix,
|
||||
`CGenDaoBriefRemovePrefix`: CGenDaoBriefRemovePrefix,
|
||||
`CGenDaoBriefRemoveFieldPrefix`: CGenDaoBriefRemoveFieldPrefix,
|
||||
`CGenDaoBriefStdTime`: CGenDaoBriefStdTime,
|
||||
`CGenDaoBriefWithTime`: CGenDaoBriefWithTime,
|
||||
`CGenDaoBriefDaoPath`: CGenDaoBriefDaoPath,
|
||||
@ -180,6 +182,7 @@ type (
|
||||
Group string `name:"group" short:"g" brief:"{CGenDaoBriefGroup}" d:"default"`
|
||||
Prefix string `name:"prefix" short:"f" brief:"{CGenDaoBriefPrefix}"`
|
||||
RemovePrefix string `name:"removePrefix" short:"r" brief:"{CGenDaoBriefRemovePrefix}"`
|
||||
RemoveFieldPrefix string `name:"removeFieldPrefix" short:"rf" brief:"{CGenDaoBriefRemoveFieldPrefix}"`
|
||||
JsonCase string `name:"jsonCase" short:"j" brief:"{CGenDaoBriefJsonCase}" d:"CamelLower"`
|
||||
ImportPrefix string `name:"importPrefix" short:"i" brief:"{CGenDaoBriefImportPrefix}"`
|
||||
DaoPath string `name:"daoPath" short:"d" brief:"{CGenDaoBriefDaoPath}" d:"dao"`
|
||||
|
||||
@ -138,6 +138,7 @@ type generateDaoInternalInput struct {
|
||||
|
||||
func generateDaoInternal(in generateDaoInternalInput) {
|
||||
path := filepath.FromSlash(gfile.Join(in.DirPathDaoInternal, in.FileName+".go"))
|
||||
removeFieldPrefixArray := gstr.SplitAndTrim(in.RemoveFieldPrefix, ",")
|
||||
modelContent := gstr.ReplaceByMap(
|
||||
getTemplateFromPathOrDefault(in.TplDaoInternalPath, consts.TemplateGenDaoInternalContent),
|
||||
g.MapStrStr{
|
||||
@ -146,8 +147,8 @@ func generateDaoInternal(in generateDaoInternalInput) {
|
||||
tplVarGroupName: in.Group,
|
||||
tplVarTableNameCamelCase: in.TableNameCamelCase,
|
||||
tplVarTableNameCamelLowerCase: in.TableNameCamelLowerCase,
|
||||
tplVarColumnDefine: gstr.Trim(generateColumnDefinitionForDao(in.FieldMap)),
|
||||
tplVarColumnNames: gstr.Trim(generateColumnNamesForDao(in.FieldMap)),
|
||||
tplVarColumnDefine: gstr.Trim(generateColumnDefinitionForDao(in.FieldMap, removeFieldPrefixArray)),
|
||||
tplVarColumnNames: gstr.Trim(generateColumnNamesForDao(in.FieldMap, removeFieldPrefixArray)),
|
||||
})
|
||||
modelContent = replaceDefaultVar(in.CGenDaoInternalInput, modelContent)
|
||||
if err := gfile.PutContents(path, strings.TrimSpace(modelContent)); err != nil {
|
||||
@ -160,16 +161,23 @@ func generateDaoInternal(in generateDaoInternalInput) {
|
||||
|
||||
// generateColumnNamesForDao generates and returns the column names assignment content of column struct
|
||||
// for specified table.
|
||||
func generateColumnNamesForDao(fieldMap map[string]*gdb.TableField) string {
|
||||
func generateColumnNamesForDao(fieldMap map[string]*gdb.TableField, removeFieldPrefixArray []string) string {
|
||||
var (
|
||||
buffer = bytes.NewBuffer(nil)
|
||||
array = make([][]string, len(fieldMap))
|
||||
names = sortFieldKeyForDao(fieldMap)
|
||||
)
|
||||
|
||||
for index, name := range names {
|
||||
field := fieldMap[name]
|
||||
|
||||
newFiledName := field.Name
|
||||
for _, v := range removeFieldPrefixArray {
|
||||
newFiledName = gstr.TrimLeftStr(newFiledName, v, 1)
|
||||
}
|
||||
|
||||
array[index] = []string{
|
||||
" #" + gstr.CaseCamel(field.Name) + ":",
|
||||
" #" + gstr.CaseCamel(newFiledName) + ":",
|
||||
fmt.Sprintf(` #"%s",`, field.Name),
|
||||
}
|
||||
}
|
||||
@ -189,12 +197,13 @@ func generateColumnNamesForDao(fieldMap map[string]*gdb.TableField) string {
|
||||
}
|
||||
|
||||
// generateColumnDefinitionForDao generates and returns the column names definition for specified table.
|
||||
func generateColumnDefinitionForDao(fieldMap map[string]*gdb.TableField) string {
|
||||
func generateColumnDefinitionForDao(fieldMap map[string]*gdb.TableField, removeFieldPrefixArray []string) string {
|
||||
var (
|
||||
buffer = bytes.NewBuffer(nil)
|
||||
array = make([][]string, len(fieldMap))
|
||||
names = sortFieldKeyForDao(fieldMap)
|
||||
)
|
||||
|
||||
for index, name := range names {
|
||||
var (
|
||||
field = fieldMap[name]
|
||||
@ -203,8 +212,12 @@ func generateColumnDefinitionForDao(fieldMap map[string]*gdb.TableField) string
|
||||
"\r", " ",
|
||||
}))
|
||||
)
|
||||
newFiledName := field.Name
|
||||
for _, v := range removeFieldPrefixArray {
|
||||
newFiledName = gstr.TrimLeftStr(newFiledName, v, 1)
|
||||
}
|
||||
array[index] = []string{
|
||||
" #" + gstr.CaseCamel(field.Name),
|
||||
" #" + gstr.CaseCamel(newFiledName),
|
||||
" # " + "string",
|
||||
" #" + fmt.Sprintf(`// %s`, comment),
|
||||
}
|
||||
|
||||
@ -126,8 +126,13 @@ func generateStructFieldDefinition(
|
||||
tagKey = "`"
|
||||
descriptionTag = gstr.Replace(formatComment(field.Comment), `"`, `\"`)
|
||||
)
|
||||
removeFieldPrefixArray := gstr.SplitAndTrim(in.RemoveFieldPrefix, ",")
|
||||
newFiledName := field.Name
|
||||
for _, v := range removeFieldPrefixArray {
|
||||
newFiledName = gstr.TrimLeftStr(newFiledName, v, 1)
|
||||
}
|
||||
attrLines = []string{
|
||||
" #" + gstr.CaseCamel(field.Name),
|
||||
" #" + gstr.CaseCamel(newFiledName),
|
||||
" #" + localTypeNameStr,
|
||||
}
|
||||
attrLines = append(attrLines, " #"+fmt.Sprintf(tagKey+`json:"%s"`, jsonTag))
|
||||
|
||||
@ -31,16 +31,17 @@ import (
|
||||
type (
|
||||
CGenPbEntity struct{}
|
||||
CGenPbEntityInput struct {
|
||||
g.Meta `name:"pbentity" config:"{CGenPbEntityConfig}" brief:"{CGenPbEntityBrief}" eg:"{CGenPbEntityEg}" ad:"{CGenPbEntityAd}"`
|
||||
Path string `name:"path" short:"p" brief:"{CGenPbEntityBriefPath}" d:"manifest/protobuf/pbentity"`
|
||||
Package string `name:"package" short:"k" brief:"{CGenPbEntityBriefPackage}"`
|
||||
Link string `name:"link" short:"l" brief:"{CGenPbEntityBriefLink}"`
|
||||
Tables string `name:"tables" short:"t" brief:"{CGenPbEntityBriefTables}"`
|
||||
Prefix string `name:"prefix" short:"f" brief:"{CGenPbEntityBriefPrefix}"`
|
||||
RemovePrefix string `name:"removePrefix" short:"r" brief:"{CGenPbEntityBriefRemovePrefix}"`
|
||||
NameCase string `name:"nameCase" short:"n" brief:"{CGenPbEntityBriefNameCase}" d:"Camel"`
|
||||
JsonCase string `name:"jsonCase" short:"j" brief:"{CGenPbEntityBriefJsonCase}" d:"CamelLower"`
|
||||
Option string `name:"option" short:"o" brief:"{CGenPbEntityBriefOption}"`
|
||||
g.Meta `name:"pbentity" config:"{CGenPbEntityConfig}" brief:"{CGenPbEntityBrief}" eg:"{CGenPbEntityEg}" ad:"{CGenPbEntityAd}"`
|
||||
Path string `name:"path" short:"p" brief:"{CGenPbEntityBriefPath}" d:"manifest/protobuf/pbentity"`
|
||||
Package string `name:"package" short:"k" brief:"{CGenPbEntityBriefPackage}"`
|
||||
Link string `name:"link" short:"l" brief:"{CGenPbEntityBriefLink}"`
|
||||
Tables string `name:"tables" short:"t" brief:"{CGenPbEntityBriefTables}"`
|
||||
Prefix string `name:"prefix" short:"f" brief:"{CGenPbEntityBriefPrefix}"`
|
||||
RemovePrefix string `name:"removePrefix" short:"r" brief:"{CGenPbEntityBriefRemovePrefix}"`
|
||||
RemoveFieldPrefix string `name:"removeFieldPrefix" short:"rf" brief:"{CGenPbEntityBriefRemoveFieldPrefix}"`
|
||||
NameCase string `name:"nameCase" short:"n" brief:"{CGenPbEntityBriefNameCase}" d:"Camel"`
|
||||
JsonCase string `name:"jsonCase" short:"j" brief:"{CGenPbEntityBriefJsonCase}" d:"none"`
|
||||
Option string `name:"option" short:"o" brief:"{CGenPbEntityBriefOption}"`
|
||||
}
|
||||
CGenPbEntityOutput struct{}
|
||||
|
||||
@ -87,14 +88,15 @@ CONFIGURATION SUPPORT
|
||||
option java_package = "protobuf/demos";
|
||||
option php_namespace = "protobuf/demos";
|
||||
`
|
||||
CGenPbEntityBriefPath = `directory path for generated files storing`
|
||||
CGenPbEntityBriefPackage = `package path for all entity proto files`
|
||||
CGenPbEntityBriefLink = `database configuration, the same as the ORM configuration of GoFrame`
|
||||
CGenPbEntityBriefTables = `generate models only for given tables, multiple table names separated with ','`
|
||||
CGenPbEntityBriefPrefix = `add specified prefix for all entity names and entity proto files`
|
||||
CGenPbEntityBriefRemovePrefix = `remove specified prefix of the table, multiple prefix separated with ','`
|
||||
CGenPbEntityBriefOption = `extra protobuf options`
|
||||
CGenPbEntityBriefGroup = `
|
||||
CGenPbEntityBriefPath = `directory path for generated files storing`
|
||||
CGenPbEntityBriefPackage = `package path for all entity proto files`
|
||||
CGenPbEntityBriefLink = `database configuration, the same as the ORM configuration of GoFrame`
|
||||
CGenPbEntityBriefTables = `generate models only for given tables, multiple table names separated with ','`
|
||||
CGenPbEntityBriefPrefix = `add specified prefix for all entity names and entity proto files`
|
||||
CGenPbEntityBriefRemovePrefix = `remove specified prefix of the table, multiple prefix separated with ','`
|
||||
CGenPbEntityBriefRemoveFieldPrefix = `remove specified prefix of the field, multiple prefix separated with ','`
|
||||
CGenPbEntityBriefOption = `extra protobuf options`
|
||||
CGenPbEntityBriefGroup = `
|
||||
specifying the configuration group name of database for generated ORM instance,
|
||||
it's not necessary and the default value is "default"
|
||||
`
|
||||
@ -120,20 +122,21 @@ set it to "none" to ignore json tag generating.
|
||||
|
||||
func init() {
|
||||
gtag.Sets(g.MapStrStr{
|
||||
`CGenPbEntityConfig`: CGenPbEntityConfig,
|
||||
`CGenPbEntityBrief`: CGenPbEntityBrief,
|
||||
`CGenPbEntityEg`: CGenPbEntityEg,
|
||||
`CGenPbEntityAd`: CGenPbEntityAd,
|
||||
`CGenPbEntityBriefPath`: CGenPbEntityBriefPath,
|
||||
`CGenPbEntityBriefPackage`: CGenPbEntityBriefPackage,
|
||||
`CGenPbEntityBriefLink`: CGenPbEntityBriefLink,
|
||||
`CGenPbEntityBriefTables`: CGenPbEntityBriefTables,
|
||||
`CGenPbEntityBriefPrefix`: CGenPbEntityBriefPrefix,
|
||||
`CGenPbEntityBriefRemovePrefix`: CGenPbEntityBriefRemovePrefix,
|
||||
`CGenPbEntityBriefGroup`: CGenPbEntityBriefGroup,
|
||||
`CGenPbEntityBriefNameCase`: CGenPbEntityBriefNameCase,
|
||||
`CGenPbEntityBriefJsonCase`: CGenPbEntityBriefJsonCase,
|
||||
`CGenPbEntityBriefOption`: CGenPbEntityBriefOption,
|
||||
`CGenPbEntityConfig`: CGenPbEntityConfig,
|
||||
`CGenPbEntityBrief`: CGenPbEntityBrief,
|
||||
`CGenPbEntityEg`: CGenPbEntityEg,
|
||||
`CGenPbEntityAd`: CGenPbEntityAd,
|
||||
`CGenPbEntityBriefPath`: CGenPbEntityBriefPath,
|
||||
`CGenPbEntityBriefPackage`: CGenPbEntityBriefPackage,
|
||||
`CGenPbEntityBriefLink`: CGenPbEntityBriefLink,
|
||||
`CGenPbEntityBriefTables`: CGenPbEntityBriefTables,
|
||||
`CGenPbEntityBriefPrefix`: CGenPbEntityBriefPrefix,
|
||||
`CGenPbEntityBriefRemovePrefix`: CGenPbEntityBriefRemovePrefix,
|
||||
`CGenPbEntityBriefRemoveFieldPrefix`: CGenPbEntityBriefRemoveFieldPrefix,
|
||||
`CGenPbEntityBriefGroup`: CGenPbEntityBriefGroup,
|
||||
`CGenPbEntityBriefNameCase`: CGenPbEntityBriefNameCase,
|
||||
`CGenPbEntityBriefJsonCase`: CGenPbEntityBriefJsonCase,
|
||||
`CGenPbEntityBriefOption`: CGenPbEntityBriefOption,
|
||||
})
|
||||
}
|
||||
|
||||
@ -339,6 +342,7 @@ func generateMessageFieldForPbEntity(index int, field *gdb.TableField, in CGenPb
|
||||
comment = gstr.Replace(comment, `\n`, " ")
|
||||
comment, _ = gregex.ReplaceString(`\s{2,}`, ` `, comment)
|
||||
if jsonTagName := formatCase(field.Name, in.JsonCase); jsonTagName != "" {
|
||||
jsonTagStr = fmt.Sprintf(`[json_name = "%s"]`, jsonTagName)
|
||||
// beautiful indent.
|
||||
if index < 10 {
|
||||
// 3 spaces
|
||||
@ -351,9 +355,16 @@ func generateMessageFieldForPbEntity(index int, field *gdb.TableField, in CGenPb
|
||||
jsonTagStr = " " + jsonTagStr
|
||||
}
|
||||
}
|
||||
|
||||
removeFieldPrefixArray := gstr.SplitAndTrim(in.RemoveFieldPrefix, ",")
|
||||
newFiledName := field.Name
|
||||
for _, v := range removeFieldPrefixArray {
|
||||
newFiledName = gstr.TrimLeftStr(newFiledName, v, 1)
|
||||
}
|
||||
|
||||
return []string{
|
||||
" #" + localTypeNameStr,
|
||||
" #" + formatCase(field.Name, in.NameCase),
|
||||
" #" + formatCase(newFiledName, in.NameCase),
|
||||
" #= " + gconv.String(index) + jsonTagStr + ";",
|
||||
" #" + fmt.Sprintf(`// %s`, comment),
|
||||
}
|
||||
@ -368,32 +379,10 @@ func getTplPbEntityContent(tplEntityPath string) string {
|
||||
|
||||
// formatCase call gstr.Case* function to convert the s to specified case.
|
||||
func formatCase(str, caseStr string) string {
|
||||
switch gstr.ToLower(caseStr) {
|
||||
case gstr.ToLower("Camel"):
|
||||
return gstr.CaseCamel(str)
|
||||
|
||||
case gstr.ToLower("CamelLower"):
|
||||
return gstr.CaseCamelLower(str)
|
||||
|
||||
case gstr.ToLower("Kebab"):
|
||||
return gstr.CaseKebab(str)
|
||||
|
||||
case gstr.ToLower("KebabScreaming"):
|
||||
return gstr.CaseKebabScreaming(str)
|
||||
|
||||
case gstr.ToLower("Snake"):
|
||||
return gstr.CaseSnake(str)
|
||||
|
||||
case gstr.ToLower("SnakeFirstUpper"):
|
||||
return gstr.CaseSnakeFirstUpper(str)
|
||||
|
||||
case gstr.ToLower("SnakeScreaming"):
|
||||
return gstr.CaseSnakeScreaming(str)
|
||||
|
||||
case "none":
|
||||
if caseStr == "none" {
|
||||
return ""
|
||||
}
|
||||
return str
|
||||
return gstr.CaseConvert(str, gstr.CaseTypeMatch(caseStr))
|
||||
}
|
||||
|
||||
func sortFieldKeyForPbEntity(fieldMap map[string]*gdb.TableField) []string {
|
||||
|
||||
@ -9,6 +9,7 @@ package genservice
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
@ -93,10 +94,10 @@ const (
|
||||
)
|
||||
|
||||
func (c CGenService) Service(ctx context.Context, in CGenServiceInput) (out *CGenServiceOutput, err error) {
|
||||
in.SrcFolder = gstr.TrimRight(in.SrcFolder, `\/`)
|
||||
in.SrcFolder = gstr.Replace(in.SrcFolder, "\\", "/")
|
||||
in.WatchFile = gstr.TrimRight(in.WatchFile, `\/`)
|
||||
in.WatchFile = gstr.Replace(in.WatchFile, "\\", "/")
|
||||
in.SrcFolder = filepath.ToSlash(in.SrcFolder)
|
||||
in.SrcFolder = gstr.TrimRight(in.SrcFolder, `/`)
|
||||
in.WatchFile = filepath.ToSlash(in.WatchFile)
|
||||
in.WatchFile = gstr.TrimRight(in.WatchFile, `/`)
|
||||
|
||||
// Watch file handling.
|
||||
if in.WatchFile != "" {
|
||||
@ -173,7 +174,7 @@ func (c CGenService) Service(ctx context.Context, in CGenServiceInput) (out *CGe
|
||||
// Parse single logic package folder.
|
||||
var (
|
||||
// StructName => FunctionDefinitions
|
||||
srcPkgInterfaceMap = make(map[string]*garray.StrArray)
|
||||
srcPkgInterfaceMap = gmap.NewListMap()
|
||||
srcImportedPackages = garray.NewSortedStrArray().SetUnique(true)
|
||||
importAliasToPathMap = gmap.NewStrStrMap() // for conflict imports check. alias => import path(with `"`)
|
||||
importPathToAliasMap = gmap.NewStrStrMap() // for conflict imports check. import path(with `"`) => alias
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"go/token"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
@ -99,10 +100,9 @@ func (c CGenService) calculateCodeCommented(in CGenServiceInput, fileContent str
|
||||
}
|
||||
|
||||
func (c CGenService) calculateInterfaceFunctions(
|
||||
in CGenServiceInput, fileContent string, srcPkgInterfaceMap map[string]*garray.StrArray,
|
||||
in CGenServiceInput, fileContent string, srcPkgInterfaceMap *gmap.ListMap,
|
||||
) (err error) {
|
||||
var (
|
||||
ok bool
|
||||
matches [][]string
|
||||
srcPkgInterfaceFuncArray *garray.StrArray
|
||||
)
|
||||
@ -142,9 +142,11 @@ func (c CGenService) calculateInterfaceFunctions(
|
||||
continue
|
||||
}
|
||||
structName = gstr.CaseCamel(structMatch[1])
|
||||
if srcPkgInterfaceFuncArray, ok = srcPkgInterfaceMap[structName]; !ok {
|
||||
srcPkgInterfaceMap[structName] = garray.NewStrArray()
|
||||
srcPkgInterfaceFuncArray = srcPkgInterfaceMap[structName]
|
||||
if !srcPkgInterfaceMap.Contains(structName) {
|
||||
srcPkgInterfaceFuncArray = garray.NewStrArray()
|
||||
srcPkgInterfaceMap.Set(structName, srcPkgInterfaceFuncArray)
|
||||
} else {
|
||||
srcPkgInterfaceFuncArray = srcPkgInterfaceMap.Get(structName).(*garray.StrArray)
|
||||
}
|
||||
srcPkgInterfaceFuncArray.Append(functionHead)
|
||||
}
|
||||
@ -165,8 +167,8 @@ func (c CGenService) calculateInterfaceFunctions(
|
||||
continue
|
||||
}
|
||||
structName = gstr.CaseCamel(structMatch[1])
|
||||
if srcPkgInterfaceFuncArray, ok = srcPkgInterfaceMap[structName]; !ok {
|
||||
srcPkgInterfaceMap[structName] = garray.NewStrArray()
|
||||
if !srcPkgInterfaceMap.Contains(structName) {
|
||||
srcPkgInterfaceMap.Set(structName, garray.NewStrArray())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
@ -23,7 +24,7 @@ import (
|
||||
type generateServiceFilesInput struct {
|
||||
CGenServiceInput
|
||||
DstFilePath string // Absolute file path for generated service go file.
|
||||
SrcStructFunctions map[string]*garray.StrArray
|
||||
SrcStructFunctions *gmap.ListMap
|
||||
SrcImportedPackages []string
|
||||
SrcPackageName string
|
||||
DstPackageName string
|
||||
@ -46,7 +47,8 @@ func (c CGenService) generateServiceFile(in generateServiceFilesInput) (ok bool,
|
||||
// Type definitions.
|
||||
generatedContent += "type("
|
||||
generatedContent += "\n"
|
||||
for structName, funcArray := range in.SrcStructFunctions {
|
||||
in.SrcStructFunctions.Iterator(func(key, value interface{}) bool {
|
||||
structName, funcArray := key.(string), value.(*garray.StrArray)
|
||||
allFuncArray.Append(funcArray.Slice()...)
|
||||
// Add comments to a method.
|
||||
for index, funcName := range funcArray.Slice() {
|
||||
@ -60,7 +62,8 @@ func (c CGenService) generateServiceFile(in generateServiceFilesInput) (ok bool,
|
||||
"{FuncDefinition}": funcArray.Join("\n\t"),
|
||||
}))
|
||||
generatedContent += "\n"
|
||||
}
|
||||
return true
|
||||
})
|
||||
generatedContent += ")"
|
||||
generatedContent += "\n"
|
||||
|
||||
@ -70,17 +73,19 @@ func (c CGenService) generateServiceFile(in generateServiceFilesInput) (ok bool,
|
||||
generatingInterfaceCheck string
|
||||
)
|
||||
// Variable definitions.
|
||||
for structName := range in.SrcStructFunctions {
|
||||
in.SrcStructFunctions.Iterator(func(key, value interface{}) bool {
|
||||
structName := key.(string)
|
||||
generatingInterfaceCheck = fmt.Sprintf(`[^\w\d]+%s.I%s[^\w\d]`, in.DstPackageName, structName)
|
||||
if gregex.IsMatchString(generatingInterfaceCheck, generatedContent) {
|
||||
continue
|
||||
return true
|
||||
}
|
||||
variableContent += gstr.Trim(gstr.ReplaceByMap(consts.TemplateGenServiceContentVariable, g.MapStrStr{
|
||||
"{StructName}": structName,
|
||||
"{InterfaceName}": "I" + structName,
|
||||
}))
|
||||
variableContent += "\n"
|
||||
}
|
||||
return true
|
||||
})
|
||||
if variableContent != "" {
|
||||
generatedContent += "var("
|
||||
generatedContent += "\n"
|
||||
@ -89,17 +94,19 @@ func (c CGenService) generateServiceFile(in generateServiceFilesInput) (ok bool,
|
||||
generatedContent += "\n"
|
||||
}
|
||||
// Variable register function definitions.
|
||||
for structName := range in.SrcStructFunctions {
|
||||
in.SrcStructFunctions.Iterator(func(key, value interface{}) bool {
|
||||
structName := key.(string)
|
||||
generatingInterfaceCheck = fmt.Sprintf(`[^\w\d]+%s.I%s[^\w\d]`, in.DstPackageName, structName)
|
||||
if gregex.IsMatchString(generatingInterfaceCheck, generatedContent) {
|
||||
continue
|
||||
return true
|
||||
}
|
||||
generatedContent += gstr.Trim(gstr.ReplaceByMap(consts.TemplateGenServiceContentRegister, g.MapStrStr{
|
||||
"{StructName}": structName,
|
||||
"{InterfaceName}": "I" + structName,
|
||||
}))
|
||||
generatedContent += "\n\n"
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
// Replace empty braces that have new line.
|
||||
generatedContent, _ = gregex.ReplaceString(`{[\s\t]+}`, `{}`, generatedContent)
|
||||
|
||||
5
cmd/gf/internal/cmd/testdata/build/multiple/multiple.go
vendored
Normal file
5
cmd/gf/internal/cmd/testdata/build/multiple/multiple.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
5
cmd/gf/internal/cmd/testdata/build/single/main.go
vendored
Normal file
5
cmd/gf/internal/cmd/testdata/build/single/main.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
12
cmd/gf/internal/cmd/testdata/build/varmap/go.mod
vendored
Normal file
12
cmd/gf/internal/cmd/testdata/build/varmap/go.mod
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
module github.com/gogf/gf/cmd/gf/cmd/gf/testdata/vardump/v2
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.6.1
|
||||
|
||||
require (
|
||||
go.opentelemetry.io/otel v1.14.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.14.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../../../../../
|
||||
27
cmd/gf/internal/cmd/testdata/build/varmap/go.sum
vendored
Normal file
27
cmd/gf/internal/cmd/testdata/build/varmap/go.sum
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
|
||||
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM=
|
||||
go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU=
|
||||
go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY=
|
||||
go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M=
|
||||
go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8=
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
13
cmd/gf/internal/cmd/testdata/build/varmap/main.go
vendored
Normal file
13
cmd/gf/internal/cmd/testdata/build/varmap/main.go
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gbuild"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for k, v := range gbuild.Data() {
|
||||
fmt.Printf("%s: %v\n", k, v)
|
||||
}
|
||||
}
|
||||
21
cmd/gf/internal/cmd/testdata/genpbentity/generated_user/table_user.proto
vendored
Normal file
21
cmd/gf/internal/cmd/testdata/genpbentity/generated_user/table_user.proto
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// ==========================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// ==========================================================================
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package unittest;
|
||||
|
||||
option go_package = "unittest";
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
message TableUser {
|
||||
uint32 ID = 1; // User ID
|
||||
string PASSPORT = 2; // User Passport
|
||||
string PASSWORD = 3; // User Password
|
||||
string NICKNAME = 4; // User Nickname
|
||||
string SCORE = 5; // Total score amount.
|
||||
google.protobuf.Timestamp CREATE_AT = 6; // Created Time
|
||||
google.protobuf.Timestamp UPDATE_AT = 7; // Updated Time
|
||||
}
|
||||
10
cmd/gf/internal/cmd/testdata/genpbentity/user.tpl.sql
vendored
Normal file
10
cmd/gf/internal/cmd/testdata/genpbentity/user.tpl.sql
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
CREATE TABLE `%s` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'User ID',
|
||||
`passport` varchar(45) NOT NULL COMMENT 'User Passport',
|
||||
`password` varchar(45) NOT NULL COMMENT 'User Password',
|
||||
`nickname` varchar(45) NOT NULL COMMENT 'User Nickname',
|
||||
`score` decimal(10,2) unsigned DEFAULT NULL COMMENT 'Total score amount.',
|
||||
`create_at` datetime DEFAULT NULL COMMENT 'Created Time',
|
||||
`update_at` datetime DEFAULT NULL COMMENT 'Updated Time',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
@ -8,6 +8,7 @@ package article
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/testdata/genservice/service"
|
||||
)
|
||||
|
||||
|
||||
@ -24,15 +24,19 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
logger.SetStack(false)
|
||||
if genv.Get(headerPrintEnvName).String() == "1" {
|
||||
logger.SetHeaderPrint(true)
|
||||
} else {
|
||||
logger.SetHeaderPrint(false)
|
||||
}
|
||||
|
||||
if gcmd.GetOpt("debug") != nil || gcmd.GetOpt("gf.debug") != nil {
|
||||
logger.SetHeaderPrint(true)
|
||||
logger.SetStackSkip(4)
|
||||
logger.SetFlags(logger.GetFlags() | glog.F_FILE_LONG)
|
||||
logger.SetDebug(true)
|
||||
} else {
|
||||
logger.SetStack(false)
|
||||
logger.SetDebug(false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ package utils
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/tools/imports"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
|
||||
|
||||
@ -173,7 +173,11 @@ func (a *IntArray) InsertBefore(index int, values ...int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
|
||||
return gerror.NewCodef(
|
||||
gcode.CodeInvalidParameter,
|
||||
"index %d out of array range %d",
|
||||
index, len(a.array),
|
||||
)
|
||||
}
|
||||
rear := append([]int{}, a.array[index:]...)
|
||||
a.array = append(a.array[0:index], values...)
|
||||
@ -186,7 +190,11 @@ func (a *IntArray) InsertAfter(index int, values ...int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
|
||||
return gerror.NewCodef(
|
||||
gcode.CodeInvalidParameter,
|
||||
"index %d out of array range %d",
|
||||
index, len(a.array),
|
||||
)
|
||||
}
|
||||
rear := append([]int{}, a.array[index+1:]...)
|
||||
a.array = append(a.array[0:index+1], values...)
|
||||
@ -583,7 +591,11 @@ func (a *IntArray) Fill(startIndex int, num int, value int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if startIndex < 0 || startIndex > len(a.array) {
|
||||
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", startIndex, len(a.array))
|
||||
return gerror.NewCodef(
|
||||
gcode.CodeInvalidParameter,
|
||||
"index %d out of array range %d",
|
||||
startIndex, len(a.array),
|
||||
)
|
||||
}
|
||||
for i := startIndex; i < startIndex+num; i++ {
|
||||
if i > len(a.array)-1 {
|
||||
|
||||
@ -75,7 +75,8 @@ func TestQueue_Close(t *testing.T) {
|
||||
q1 := gqueue.New()
|
||||
q1.Push(1)
|
||||
q1.Push(2)
|
||||
time.Sleep(time.Millisecond)
|
||||
// wait sync to channel
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
t.Assert(q1.Len(), 2)
|
||||
q1.Close()
|
||||
})
|
||||
@ -83,7 +84,8 @@ func TestQueue_Close(t *testing.T) {
|
||||
q1 := gqueue.New(2)
|
||||
q1.Push(1)
|
||||
q1.Push(2)
|
||||
time.Sleep(time.Millisecond)
|
||||
// wait sync to channel
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
t.Assert(q1.Len(), 2)
|
||||
q1.Close()
|
||||
})
|
||||
|
||||
@ -42,7 +42,7 @@ func ExampleIntSet_Add() {
|
||||
fmt.Println(intSet.Slice())
|
||||
fmt.Println(intSet.AddIfNotExist(1))
|
||||
|
||||
// Mya Output:
|
||||
// May Output:
|
||||
// [1 2 3]
|
||||
// false
|
||||
}
|
||||
@ -56,7 +56,7 @@ func ExampleIntSet_AddIfNotExist() {
|
||||
fmt.Println(intSet.Slice())
|
||||
fmt.Println(intSet.AddIfNotExist(1))
|
||||
|
||||
// Mya Output:
|
||||
// May Output:
|
||||
// [1 2 3]
|
||||
// false
|
||||
}
|
||||
|
||||
@ -42,13 +42,13 @@ func ExampleStrSet_Add() {
|
||||
fmt.Println(strSet.Slice())
|
||||
fmt.Println(strSet.AddIfNotExist("str"))
|
||||
|
||||
// Mya Output:
|
||||
// May Output:
|
||||
// [str str1 str2 str3]
|
||||
// false
|
||||
}
|
||||
|
||||
// AddIfNotExist checks whether item exists in the set,
|
||||
// it adds the item to set and returns true if it does not exists in the set,
|
||||
// it adds the item to set and returns true if it does not exist in the set,
|
||||
// or else it does nothing and returns false.
|
||||
func ExampleStrSet_AddIfNotExist() {
|
||||
strSet := gset.NewStrSetFrom([]string{"str1", "str2", "str3"}, true)
|
||||
@ -56,13 +56,13 @@ func ExampleStrSet_AddIfNotExist() {
|
||||
fmt.Println(strSet.Slice())
|
||||
fmt.Println(strSet.AddIfNotExist("str"))
|
||||
|
||||
// Mya Output:
|
||||
// May Output:
|
||||
// [str str1 str2 str3]
|
||||
// false
|
||||
}
|
||||
|
||||
// AddIfNotExistFunc checks whether item exists in the set,
|
||||
// it adds the item to set and returns true if it does not exists in the set and function `f` returns true,
|
||||
// it adds the item to set and returns true if it does not exist in the set and function `f` returns true,
|
||||
// or else it does nothing and returns false.
|
||||
// Note that, the function `f` is executed without writing lock.
|
||||
func ExampleStrSet_AddIfNotExistFunc() {
|
||||
@ -79,7 +79,7 @@ func ExampleStrSet_AddIfNotExistFunc() {
|
||||
}
|
||||
|
||||
// AddIfNotExistFunc checks whether item exists in the set,
|
||||
// it adds the item to set and returns true if it does not exists in the set and function `f` returns true,
|
||||
// it adds the item to set and returns true if it does not exist in the set and function `f` returns true,
|
||||
// or else it does nothing and returns false.
|
||||
// Note that, the function `f` is executed without writing lock.
|
||||
func ExampleStrSet_AddIfNotExistFuncLock() {
|
||||
|
||||
@ -8,24 +8,27 @@ package gvar
|
||||
|
||||
import "github.com/gogf/gf/v2/util/gconv"
|
||||
|
||||
// MapOption specifies the option for map converting.
|
||||
type MapOption = gconv.MapOption
|
||||
|
||||
// Map converts and returns `v` as map[string]interface{}.
|
||||
func (v *Var) Map(tags ...string) map[string]interface{} {
|
||||
return gconv.Map(v.Val(), tags...)
|
||||
func (v *Var) Map(option ...MapOption) map[string]interface{} {
|
||||
return gconv.Map(v.Val(), option...)
|
||||
}
|
||||
|
||||
// MapStrAny is like function Map, but implements the interface of MapStrAny.
|
||||
func (v *Var) MapStrAny() map[string]interface{} {
|
||||
return v.Map()
|
||||
func (v *Var) MapStrAny(option ...MapOption) map[string]interface{} {
|
||||
return v.Map(option...)
|
||||
}
|
||||
|
||||
// MapStrStr converts and returns `v` as map[string]string.
|
||||
func (v *Var) MapStrStr(tags ...string) map[string]string {
|
||||
return gconv.MapStrStr(v.Val(), tags...)
|
||||
func (v *Var) MapStrStr(option ...MapOption) map[string]string {
|
||||
return gconv.MapStrStr(v.Val(), option...)
|
||||
}
|
||||
|
||||
// MapStrVar converts and returns `v` as map[string]Var.
|
||||
func (v *Var) MapStrVar(tags ...string) map[string]*Var {
|
||||
m := v.Map(tags...)
|
||||
func (v *Var) MapStrVar(option ...MapOption) map[string]*Var {
|
||||
m := v.Map(option...)
|
||||
if len(m) > 0 {
|
||||
vMap := make(map[string]*Var, len(m))
|
||||
for k, v := range m {
|
||||
@ -37,16 +40,19 @@ func (v *Var) MapStrVar(tags ...string) map[string]*Var {
|
||||
}
|
||||
|
||||
// MapDeep converts and returns `v` as map[string]interface{} recursively.
|
||||
// Deprecated: used Map instead.
|
||||
func (v *Var) MapDeep(tags ...string) map[string]interface{} {
|
||||
return gconv.MapDeep(v.Val(), tags...)
|
||||
}
|
||||
|
||||
// MapStrStrDeep converts and returns `v` as map[string]string recursively.
|
||||
// Deprecated: used MapStrStr instead.
|
||||
func (v *Var) MapStrStrDeep(tags ...string) map[string]string {
|
||||
return gconv.MapStrStrDeep(v.Val(), tags...)
|
||||
}
|
||||
|
||||
// MapStrVarDeep converts and returns `v` as map[string]*Var recursively.
|
||||
// Deprecated: used MapStrVar instead.
|
||||
func (v *Var) MapStrVarDeep(tags ...string) map[string]*Var {
|
||||
m := v.MapDeep(tags...)
|
||||
if len(m) > 0 {
|
||||
@ -61,12 +67,12 @@ func (v *Var) MapStrVarDeep(tags ...string) map[string]*Var {
|
||||
|
||||
// Maps converts and returns `v` as map[string]string.
|
||||
// See gconv.Maps.
|
||||
func (v *Var) Maps(tags ...string) []map[string]interface{} {
|
||||
return gconv.Maps(v.Val(), tags...)
|
||||
func (v *Var) Maps(option ...MapOption) []map[string]interface{} {
|
||||
return gconv.Maps(v.Val(), option...)
|
||||
}
|
||||
|
||||
// MapsDeep converts `value` to []map[string]interface{} recursively.
|
||||
// See gconv.MapsDeep.
|
||||
// Deprecated: used Maps instead.
|
||||
func (v *Var) MapsDeep(tags ...string) []map[string]interface{} {
|
||||
return gconv.MapsDeep(v.Val(), tags...)
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/apolloconfig/agollo/v4 v4.3.1
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/consul/v2
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
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.19
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
k8s.io/api v0.27.4
|
||||
k8s.io/apimachinery v0.27.4
|
||||
k8s.io/client-go v0.27.4
|
||||
@ -15,7 +15,7 @@ require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.19.6 // indirect
|
||||
@ -35,7 +35,7 @@ require (
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
|
||||
@ -56,8 +56,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
@ -168,8 +168,8 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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=
|
||||
@ -330,7 +330,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/nacos/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/nacos-group/nacos-sdk-go v1.1.4
|
||||
)
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/polaris/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/polarismesh/polaris-go v1.5.5
|
||||
)
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.15
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/shopspring/decimal v1.3.1
|
||||
)
|
||||
@ -13,14 +13,14 @@ require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/paulmach/orb v0.7.1 // indirect
|
||||
|
||||
@ -10,8 +10,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||
@ -45,8 +45,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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=
|
||||
@ -111,7 +111,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -74,9 +74,16 @@ func (d *Driver) Open(config *gdb.ConfigNode) (db *sql.DB, err error) {
|
||||
}
|
||||
// Data Source Name of DM8:
|
||||
// dm://userName:password@ip:port/dbname
|
||||
// dm://userName:password@DW/dbname?DW=(192.168.1.1:5236,192.168.1.2:5236)
|
||||
var domain string
|
||||
if config.Port != "" {
|
||||
domain = fmt.Sprintf("%s:%s", config.Host, config.Port)
|
||||
} else {
|
||||
domain = config.Host
|
||||
}
|
||||
source = fmt.Sprintf(
|
||||
"dm://%s:%s@%s:%s/%s?charset=%s&schema=%s",
|
||||
config.User, config.Pass, config.Host, config.Port, config.Name, config.Charset, config.Name,
|
||||
"dm://%s:%s@%s/%s?charset=%s&schema=%s",
|
||||
config.User, config.Pass, domain, config.Name, config.Charset, config.Name,
|
||||
)
|
||||
// Demo of timezone setting:
|
||||
// &loc=Asia/Shanghai
|
||||
@ -210,7 +217,11 @@ func (d *Driver) DoFilter(ctx context.Context, link gdb.Link, sql string, args [
|
||||
// TODO The current approach is too rough. We should deal with the GROUP_CONCAT function and the parsing of the index field from within the select from match.
|
||||
// (GROUP_CONCAT DM does not approve; index cannot be used as a query column name, and security characters need to be added, such as "index")
|
||||
l, r := d.GetChars()
|
||||
newSql = gstr.ReplaceI(newSql, "INDEX", l+"INDEX"+r)
|
||||
if strings.Contains(newSql, "INDEX") || strings.Contains(newSql, "index") {
|
||||
if !(strings.Contains(newSql, "_INDEX") || strings.Contains(newSql, "_index")) {
|
||||
newSql = gstr.ReplaceI(newSql, "INDEX", l+"INDEX"+r)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO i tried to do but it never work:
|
||||
// array, err := gregex.MatchAllString(`SELECT (.*INDEX.*) FROM .*`, newSql)
|
||||
|
||||
@ -21,38 +21,44 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
db gdb.DB
|
||||
dblink gdb.DB
|
||||
dbErr gdb.DB
|
||||
ctx context.Context
|
||||
)
|
||||
|
||||
const (
|
||||
db gdb.DB
|
||||
dblink gdb.DB
|
||||
dbErr gdb.DB
|
||||
ctx context.Context
|
||||
TableSize = 10
|
||||
|
||||
// TableName = "inf_group"
|
||||
// TableNamePrefix = "t_"
|
||||
// TestSchema = "SYSDBADP"
|
||||
)
|
||||
|
||||
const (
|
||||
TestDbIP = "127.0.0.1"
|
||||
TestDbPort = "5236"
|
||||
TestDbUser = "SYSDBA"
|
||||
TestDbPass = "SYSDBA001"
|
||||
TestDbName = "SYSDBA"
|
||||
TestDbType = "dm"
|
||||
TestDBHost = "127.0.0.1"
|
||||
TestDBPort = "5236"
|
||||
TestDBUser = "SYSDBA"
|
||||
TestDBPass = "SYSDBA001"
|
||||
TestDBName = "SYSDBA"
|
||||
TestDBType = "dm"
|
||||
TestCharset = "utf8"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID int64 `orm:"id"`
|
||||
AccountName string `orm:"account_name"`
|
||||
PwdReset int64 `orm:"pwd_reset"`
|
||||
AttrIndex int64 `orm:"attr_index"`
|
||||
Enabled int64 `orm:"enabled"`
|
||||
Deleted int64 `orm:"deleted"`
|
||||
CreatedBy string `orm:"created_by"`
|
||||
CreatedTime time.Time `orm:"created_time"`
|
||||
UpdatedBy string `orm:"updated_by"`
|
||||
UpdatedTime time.Time `orm:"updated_time"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
node := gdb.ConfigNode{
|
||||
Host: TestDbIP,
|
||||
Port: TestDbPort,
|
||||
User: TestDbUser,
|
||||
Pass: TestDbPass,
|
||||
Name: TestDbName,
|
||||
Type: TestDbType,
|
||||
Host: TestDBHost,
|
||||
Port: TestDBPort,
|
||||
User: TestDBUser,
|
||||
Pass: TestDBPass,
|
||||
Name: TestDBName,
|
||||
Type: TestDBType,
|
||||
Role: "master",
|
||||
Charset: TestCharset,
|
||||
Weight: 1,
|
||||
@ -62,22 +68,23 @@ func init() {
|
||||
UpdatedAt: "updated_time",
|
||||
}
|
||||
|
||||
// todo
|
||||
nodeLink := gdb.ConfigNode{
|
||||
Type: TestDbType,
|
||||
Name: TestDbName,
|
||||
Type: TestDBType,
|
||||
Name: TestDBName,
|
||||
Link: fmt.Sprintf(
|
||||
"dm:%s:%s@tcp(%s:%s)/%s?charset=%s",
|
||||
TestDbUser, TestDbPass, TestDbIP, TestDbPort, TestDbName, TestCharset,
|
||||
TestDBUser, TestDBPass, TestDBHost, TestDBPort, TestDBName, TestCharset,
|
||||
),
|
||||
}
|
||||
|
||||
nodeErr := gdb.ConfigNode{
|
||||
Host: TestDbIP,
|
||||
Port: TestDbPort,
|
||||
User: TestDbUser,
|
||||
Host: TestDBHost,
|
||||
Port: TestDBPort,
|
||||
User: TestDBUser,
|
||||
Pass: "1234",
|
||||
Name: TestDbName,
|
||||
Type: TestDbType,
|
||||
Name: TestDBName,
|
||||
Type: TestDBType,
|
||||
Role: "master",
|
||||
Charset: TestCharset,
|
||||
Weight: 1,
|
||||
@ -107,6 +114,23 @@ func init() {
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
func dropTable(table string) {
|
||||
count, err := db.GetCount(
|
||||
ctx,
|
||||
"SELECT COUNT(*) FROM all_tables WHERE owner = ? And table_name= ?", TestDBName, strings.ToUpper(table),
|
||||
)
|
||||
if err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf("DROP TABLE %s", table)); err != nil {
|
||||
gtest.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func createTable(table ...string) (name string) {
|
||||
if len(table) > 0 {
|
||||
name = table[0]
|
||||
@ -124,6 +148,7 @@ func createTable(table ...string) (name string) {
|
||||
"PWD_RESET" TINYINT DEFAULT 0 NOT NULL,
|
||||
"ENABLED" INT DEFAULT 1 NOT NULL,
|
||||
"DELETED" INT DEFAULT 0 NOT NULL,
|
||||
"ATTR_INDEX" INT DEFAULT 0 ,
|
||||
"CREATED_BY" VARCHAR(32) DEFAULT '' NOT NULL,
|
||||
"CREATED_TIME" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP() NOT NULL,
|
||||
"UPDATED_BY" VARCHAR(32) DEFAULT '' NOT NULL,
|
||||
@ -136,18 +161,6 @@ NOT CLUSTER PRIMARY KEY("ID")) STORAGE(ON "MAIN", CLUSTERBTR) ;
|
||||
return
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int64 `orm:"id"`
|
||||
AccountName string `orm:"account_name"`
|
||||
PwdReset int64 `orm:"pwd_reset"`
|
||||
Enabled int64 `orm:"enabled"`
|
||||
Deleted int64 `orm:"deleted"`
|
||||
CreatedBy string `orm:"created_by"`
|
||||
CreatedTime time.Time `orm:"created_time"`
|
||||
UpdatedBy string `orm:"updated_by"`
|
||||
UpdatedTime time.Time `orm:"updated_time"`
|
||||
}
|
||||
|
||||
func createInitTable(table ...string) (name string) {
|
||||
name = createTable(table...)
|
||||
array := garray.New(true)
|
||||
@ -156,10 +169,11 @@ func createInitTable(table ...string) (name string) {
|
||||
"id": i,
|
||||
"account_name": fmt.Sprintf(`name_%d`, i),
|
||||
"pwd_reset": 0,
|
||||
"attr_index": i,
|
||||
"create_time": gtime.Now().String(),
|
||||
})
|
||||
}
|
||||
result, err := db.Schema(TestDbName).Insert(context.Background(), name, array.Slice())
|
||||
result, err := db.Schema(TestDBName).Insert(context.Background(), name, array.Slice())
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
n, e := result.RowsAffected()
|
||||
@ -168,19 +182,34 @@ func createInitTable(table ...string) (name string) {
|
||||
return
|
||||
}
|
||||
|
||||
func dropTable(table string) {
|
||||
count, err := db.GetCount(
|
||||
ctx,
|
||||
"SELECT COUNT(*) FROM USER_TABLES WHERE TABLE_NAME = ?", strings.ToUpper(table),
|
||||
)
|
||||
if err != nil {
|
||||
gtest.Fatal(err)
|
||||
func createTableFalse(table ...string) (name string, err error) {
|
||||
if len(table) > 0 {
|
||||
name = table[0]
|
||||
} else {
|
||||
name = fmt.Sprintf("random_%d", gtime.Timestamp())
|
||||
}
|
||||
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf("DROP TABLE %s", table)); err != nil {
|
||||
gtest.Fatal(err)
|
||||
dropTable(name)
|
||||
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf(`
|
||||
CREATE TABLE "%s"
|
||||
(
|
||||
"ID" BIGINT NOT NULL,
|
||||
"ACCOUNT_NAME" VARCHAR(128) DEFAULT '' NOT NULL,
|
||||
"PWD_RESET" TINYINT DEFAULT 0 NOT NULL,
|
||||
"ENABLED" INT DEFAULT 1 NOT NULL,
|
||||
"DELETED" INT DEFAULT 0 NOT NULL,
|
||||
"INDEX" INT DEFAULT 0 ,
|
||||
"ATTR_INDEX" INT DEFAULT 0 ,
|
||||
"CREATED_BY" VARCHAR(32) DEFAULT '' NOT NULL,
|
||||
"CREATED_TIME" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP() NOT NULL,
|
||||
"UPDATED_BY" VARCHAR(32) DEFAULT '' NOT NULL,
|
||||
"UPDATED_TIME" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP() NOT NULL,
|
||||
NOT CLUSTER PRIMARY KEY("ID")) STORAGE(ON "MAIN", CLUSTERBTR) ;
|
||||
`, name)); err != nil {
|
||||
// gtest.Fatal(err)
|
||||
return name, fmt.Errorf("createTableFalse")
|
||||
}
|
||||
|
||||
return name, nil
|
||||
}
|
||||
|
||||
@ -27,13 +27,11 @@ func Test_DB_Ping(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestTables(t *testing.T) {
|
||||
tables := []string{"A_tables", "A_tables2"}
|
||||
for _, v := range tables {
|
||||
createInitTable(v)
|
||||
}
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
tables := []string{"A_tables", "A_tables2"}
|
||||
|
||||
for _, v := range tables {
|
||||
createInitTable(v)
|
||||
// createTable(v)
|
||||
}
|
||||
result, err := db.Tables(ctx)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
@ -63,13 +61,31 @@ func TestTables(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTableFields(t *testing.T) {
|
||||
// The test scenario index of this test case (exact matching field) is a keyword in the Dameng database and cannot exist as a field name.
|
||||
// If the data structure previously migrated from mysql has an index (completely matching field), it will also be allowed.
|
||||
// However, when processing the index (completely matching field), the adapter will automatically add security character
|
||||
// In principle, such problems will not occur if you directly use Dameng database initialization instead of migrating the data structure from mysql.
|
||||
// If so, the adapter has also taken care of it.
|
||||
func TestTablesFalse(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
tables := []string{"A_tables", "A_tables2"}
|
||||
for _, v := range tables {
|
||||
_, err := createTableFalse(v)
|
||||
gtest.Assert(err, fmt.Errorf("createTableFalse"))
|
||||
// createTable(v)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestTableFields(t *testing.T) {
|
||||
tables := "A_tables"
|
||||
createInitTable(tables)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
tables := "A_tables"
|
||||
var expect = map[string][]interface{}{
|
||||
"ID": {"BIGINT", false},
|
||||
"ACCOUNT_NAME": {"VARCHAR", false},
|
||||
"PWD_RESET": {"TINYINT", false},
|
||||
"ATTR_INDEX": {"INT", true},
|
||||
"DELETED": {"INT", false},
|
||||
"CREATED_TIME": {"TIMESTAMP", false},
|
||||
}
|
||||
@ -98,8 +114,9 @@ func TestTableFields(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_DB_Query(t *testing.T) {
|
||||
tableName := "A_tables"
|
||||
createInitTable(tableName)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
tableName := "A_tables"
|
||||
// createTable(tableName)
|
||||
_, err := db.Query(ctx, fmt.Sprintf("SELECT * from %s", tableName))
|
||||
t.AssertNil(err)
|
||||
@ -121,16 +138,18 @@ func Test_DB_Query(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModelSave(t *testing.T) {
|
||||
table := "A_tables"
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
// createTable("A_tables")
|
||||
data := []User{
|
||||
{
|
||||
ID: 100,
|
||||
AccountName: "user_100",
|
||||
AttrIndex: 100,
|
||||
CreatedTime: time.Now(),
|
||||
},
|
||||
}
|
||||
_, err := db.Model("A_tables").Data(data).Save()
|
||||
_, err := db.Model(table).Data(data).Save()
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
data2 := []User{
|
||||
@ -139,7 +158,7 @@ func TestModelSave(t *testing.T) {
|
||||
AccountName: "user_101",
|
||||
},
|
||||
}
|
||||
_, err = db.Model("A_tables").Data(&data2).Save()
|
||||
_, err = db.Model(table).Data(&data2).Save()
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
data3 := []User{
|
||||
@ -149,7 +168,7 @@ func TestModelSave(t *testing.T) {
|
||||
PwdReset: 10,
|
||||
},
|
||||
}
|
||||
_, err = db.Model("A_tables").Save(data3)
|
||||
_, err = db.Model(table).Save(data3)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
data4 := []User{
|
||||
@ -159,63 +178,68 @@ func TestModelSave(t *testing.T) {
|
||||
CreatedTime: time.Now(),
|
||||
},
|
||||
}
|
||||
_, err = db.Model("A_tables").Save(&data4)
|
||||
_, err = db.Model(table).Save(&data4)
|
||||
gtest.Assert(err, nil)
|
||||
|
||||
// TODO:: Should be Supported 'Replace' Operation
|
||||
// _, err = db.Schema(TestDbName).Replace(ctx, "DoInsert", data, 10)
|
||||
// _, err = db.Schema(TestDBName).Replace(ctx, "DoInsert", data, 10)
|
||||
// gtest.Assert(err, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestModelInsert(t *testing.T) {
|
||||
// g.Model.insert not lost default not null coloumn
|
||||
table := "A_tables"
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
// createTable("A_tables")
|
||||
i := 200
|
||||
data := User{
|
||||
ID: int64(i),
|
||||
AccountName: fmt.Sprintf(`A%dtwo`, i),
|
||||
PwdReset: 0,
|
||||
AttrIndex: 99,
|
||||
// CreatedTime: time.Now(),
|
||||
UpdatedTime: time.Now(),
|
||||
}
|
||||
// _, err := db.Schema(TestDbName).Model("A_tables").Data(data).Insert()
|
||||
_, err := db.Model("A_tables").Insert(&data)
|
||||
// _, err := db.Schema(TestDBName).Model(table).Data(data).Insert()
|
||||
_, err := db.Model(table).Insert(&data)
|
||||
gtest.Assert(err, nil)
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
// createTable("A_tables")
|
||||
i := 201
|
||||
data := User{
|
||||
ID: int64(i),
|
||||
AccountName: fmt.Sprintf(`A%dtwoONE`, i),
|
||||
PwdReset: 1,
|
||||
CreatedTime: time.Now(),
|
||||
AttrIndex: 98,
|
||||
// UpdatedTime: time.Now(),
|
||||
}
|
||||
// _, err := db.Schema(TestDbName).Model("A_tables").Data(data).Insert()
|
||||
_, err := db.Model("A_tables").Data(&data).Insert()
|
||||
// _, err := db.Schema(TestDBName).Model(table).Data(data).Insert()
|
||||
_, err := db.Model(table).Data(&data).Insert()
|
||||
gtest.Assert(err, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestDBInsert(t *testing.T) {
|
||||
table := "A_tables"
|
||||
createInitTable("A_tables")
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
// createTable("A_tables")
|
||||
i := 300
|
||||
data := g.Map{
|
||||
"ID": i,
|
||||
"ACCOUNT_NAME": fmt.Sprintf(`A%dthress`, i),
|
||||
"PWD_RESET": 3,
|
||||
"ATTR_INDEX": 98,
|
||||
}
|
||||
_, err := db.Insert(ctx, "A_tables", &data)
|
||||
_, err := db.Insert(ctx, table, &data)
|
||||
gtest.Assert(err, nil)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_Exec(t *testing.T) {
|
||||
createInitTable("A_tables")
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
_, err := db.Exec(ctx, "SELECT ? from dual", 1)
|
||||
t.AssertNil(err)
|
||||
@ -226,18 +250,18 @@ func Test_DB_Exec(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_DB_Insert(t *testing.T) {
|
||||
// table := createTable()
|
||||
// defer dropTable(table)
|
||||
table := "A_tables"
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
// normal map
|
||||
_, err := db.Insert(ctx, "A_tables", g.Map{
|
||||
_, err := db.Insert(ctx, table, g.Map{
|
||||
"ID": 1000,
|
||||
"ACCOUNT_NAME": "map1",
|
||||
"CREATED_TIME": gtime.Now(),
|
||||
})
|
||||
t.AssertNil(err)
|
||||
|
||||
result, err := db.Insert(ctx, "A_tables", g.Map{
|
||||
result, err := db.Insert(ctx, table, g.Map{
|
||||
"ID": "2000",
|
||||
"ACCOUNT_NAME": "map2",
|
||||
"CREATED_TIME": gtime.Now(),
|
||||
@ -246,7 +270,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
result, err = db.Insert(ctx, "A_tables", g.Map{
|
||||
result, err = db.Insert(ctx, table, g.Map{
|
||||
"ID": 3000,
|
||||
"ACCOUNT_NAME": "map3",
|
||||
// "CREATED_TIME": gtime.Now(),
|
||||
@ -256,7 +280,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
t.Assert(n, 1)
|
||||
|
||||
// struct
|
||||
result, err = db.Insert(ctx, "A_tables", User{
|
||||
result, err = db.Insert(ctx, table, User{
|
||||
ID: 4000,
|
||||
AccountName: "struct_4",
|
||||
// CreatedTime: timeStr,
|
||||
@ -266,7 +290,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
n, _ = result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
ones, err := db.Model("A_tables").Where("ID", 4000).All()
|
||||
ones, err := db.Model(table).Where("ID", 4000).All()
|
||||
t.AssertNil(err)
|
||||
t.Assert(ones[0]["ID"].Int(), 4000)
|
||||
t.Assert(ones[0]["ACCOUNT_NAME"].String(), "struct_4")
|
||||
@ -276,7 +300,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
|
||||
// *struct
|
||||
timeStr := time.Now()
|
||||
result, err = db.Insert(ctx, "A_tables", &User{
|
||||
result, err = db.Insert(ctx, table, &User{
|
||||
ID: 5000,
|
||||
AccountName: "struct_5",
|
||||
CreatedTime: timeStr,
|
||||
@ -286,13 +310,13 @@ func Test_DB_Insert(t *testing.T) {
|
||||
n, _ = result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
one, err := db.Model("A_tables").Where("ID", 5000).One()
|
||||
one, err := db.Model(table).Where("ID", 5000).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one["ID"].Int(), 5000)
|
||||
t.Assert(one["ACCOUNT_NAME"].String(), "struct_5")
|
||||
|
||||
// batch with Insert
|
||||
r, err := db.Insert(ctx, "A_tables", g.Slice{
|
||||
r, err := db.Insert(ctx, table, g.Slice{
|
||||
g.Map{
|
||||
"ID": 6000,
|
||||
"ACCOUNT_NAME": "t6000",
|
||||
@ -306,7 +330,7 @@ func Test_DB_Insert(t *testing.T) {
|
||||
n, _ = r.RowsAffected()
|
||||
t.Assert(n, 2)
|
||||
|
||||
one, err = db.Model("A_tables").Where("ID", 6000).One()
|
||||
one, err = db.Model(table).Where("ID", 6000).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one["ID"].Int(), 6000)
|
||||
t.Assert(one["ACCOUNT_NAME"].String(), "t6000")
|
||||
@ -314,8 +338,9 @@ func Test_DB_Insert(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_DB_BatchInsert(t *testing.T) {
|
||||
table := "A_tables"
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
table := "A_tables"
|
||||
r, err := db.Insert(ctx, table, g.List{
|
||||
{
|
||||
"ID": 400,
|
||||
@ -334,9 +359,6 @@ func Test_DB_BatchInsert(t *testing.T) {
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
table := "A_tables"
|
||||
// table := createTable()
|
||||
// defer dropTable(table)
|
||||
// []interface{}
|
||||
r, err := db.Insert(ctx, table, g.Slice{
|
||||
g.Map{
|
||||
@ -357,9 +379,6 @@ func Test_DB_BatchInsert(t *testing.T) {
|
||||
|
||||
// batch insert map
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
table := "A_tables"
|
||||
// table := createTable()
|
||||
// defer dropTable(table)
|
||||
result, err := db.Insert(ctx, table, g.Map{
|
||||
"ID": 600,
|
||||
"ACCOUNT_NAME": "600_batch_600",
|
||||
@ -373,10 +392,9 @@ func Test_DB_BatchInsert(t *testing.T) {
|
||||
|
||||
func Test_DB_BatchInsert_Struct(t *testing.T) {
|
||||
// batch insert struct
|
||||
table := "A_tables"
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
table := "A_tables"
|
||||
// table := createTable()
|
||||
// defer dropTable(table)
|
||||
user := &User{
|
||||
ID: 700,
|
||||
AccountName: "BatchInsert_Struct_700",
|
||||
@ -391,26 +409,25 @@ func Test_DB_BatchInsert_Struct(t *testing.T) {
|
||||
|
||||
func Test_DB_Update(t *testing.T) {
|
||||
table := "A_tables"
|
||||
// table := createInitTable()
|
||||
createInitTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Update(ctx, table, "pwd_reset=7", "id=700")
|
||||
result, err := db.Update(ctx, table, "pwd_reset=7", "id=7")
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
|
||||
one, err := db.Model(table).Where("ID", 700).One()
|
||||
one, err := db.Model(table).Where("ID", 7).One()
|
||||
t.AssertNil(err)
|
||||
t.Assert(one["ID"].Int(), 700)
|
||||
t.Assert(one["ACCOUNT_NAME"].String(), "BatchInsert_Struct_700")
|
||||
t.Assert(one["ID"].Int(), 7)
|
||||
t.Assert(one["ACCOUNT_NAME"].String(), "name_7")
|
||||
t.Assert(one["PWD_RESET"].String(), "7")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetAll(t *testing.T) {
|
||||
table := "A_tables"
|
||||
// table := createInitTable()
|
||||
// defer dropTable(table)
|
||||
createInitTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.GetAll(ctx, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 1)
|
||||
@ -459,41 +476,38 @@ func Test_DB_GetAll(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_DB_GetOne(t *testing.T) {
|
||||
// table := createInitTable()
|
||||
table := "A_tables"
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
record, err := db.GetOne(ctx, fmt.Sprintf("SELECT * FROM %s WHERE account_name=?", table), "struct_4")
|
||||
record, err := db.GetOne(ctx, fmt.Sprintf("SELECT * FROM %s WHERE account_name=?", table), "name_4")
|
||||
t.AssertNil(err)
|
||||
t.Assert(record["ACCOUNT_NAME"].String(), "struct_4")
|
||||
t.Assert(record["ACCOUNT_NAME"].String(), "name_4")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetValue(t *testing.T) {
|
||||
table := "A_tables"
|
||||
// table := createInitTable()
|
||||
// defer dropTable(table)
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
value, err := db.GetValue(ctx, fmt.Sprintf("SELECT id FROM %s WHERE account_name=?", table), "map2")
|
||||
value, err := db.GetValue(ctx, fmt.Sprintf("SELECT id FROM %s WHERE account_name=?", table), "name_2")
|
||||
t.AssertNil(err)
|
||||
t.Assert(value.Int(), 2000)
|
||||
t.Assert(value.Int(), 2)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetCount(t *testing.T) {
|
||||
table := "A_tables"
|
||||
// table := createInitTable()
|
||||
// defer dropTable(table)
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
count, err := db.GetCount(ctx, fmt.Sprintf("SELECT * FROM %s", table))
|
||||
t.AssertNil(err)
|
||||
t.Assert(count, 28)
|
||||
t.Assert(count, 10)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetStruct(t *testing.T) {
|
||||
table := "A_tables"
|
||||
// table := createInitTable()
|
||||
// defer dropTable(table)
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
user := new(User)
|
||||
err := db.GetScan(ctx, user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3)
|
||||
@ -502,33 +516,31 @@ func Test_DB_GetStruct(t *testing.T) {
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
user := new(User)
|
||||
err := db.GetScan(ctx, user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 200)
|
||||
err := db.GetScan(ctx, user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 2)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.AccountName, "A200two")
|
||||
t.Assert(user.AccountName, "name_2")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetStructs(t *testing.T) {
|
||||
table := "A_tables"
|
||||
// table := createInitTable()
|
||||
// defer dropTable(table)
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var users []User
|
||||
err := db.GetScan(ctx, &users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 4000)
|
||||
err := db.GetScan(ctx, &users, fmt.Sprintf("SELECT * FROM %s WHERE id>?", table), 4)
|
||||
t.AssertNil(err)
|
||||
t.Assert(users[0].ID, 5000)
|
||||
t.Assert(users[1].ID, 6000)
|
||||
t.Assert(users[2].ID, 6001)
|
||||
t.Assert(users[0].AccountName, "struct_5")
|
||||
t.Assert(users[1].AccountName, "t6000")
|
||||
t.Assert(users[2].AccountName, "t6001")
|
||||
t.Assert(users[0].ID, 5)
|
||||
t.Assert(users[1].ID, 6)
|
||||
t.Assert(users[2].ID, 7)
|
||||
t.Assert(users[0].AccountName, "name_5")
|
||||
t.Assert(users[1].AccountName, "name_6")
|
||||
t.Assert(users[2].AccountName, "name_7")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_GetScan(t *testing.T) {
|
||||
table := "A_tables"
|
||||
// table := createInitTable()
|
||||
// defer dropTable(table)
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
user := new(User)
|
||||
err := db.GetScan(ctx, user, fmt.Sprintf("SELECT * FROM %s WHERE id=?", table), 3)
|
||||
@ -555,17 +567,17 @@ func Test_DB_GetScan(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_DB_Delete(t *testing.T) {
|
||||
// table := createInitTable()
|
||||
// defer dropTable(table)
|
||||
table := "A_tables"
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Delete(ctx, "A_tables", "id=32")
|
||||
result, err := db.Delete(ctx, table, "id=32")
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 0)
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.Model("A_tables").Where("id", 33).Delete()
|
||||
result, err := db.Model(table).Where("id", 33).Delete()
|
||||
t.AssertNil(err)
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 0)
|
||||
@ -574,8 +586,7 @@ func Test_DB_Delete(t *testing.T) {
|
||||
|
||||
func Test_Empty_Slice_Argument(t *testing.T) {
|
||||
table := "A_tables"
|
||||
// table := createInitTable()
|
||||
// defer dropTable(table)
|
||||
createInitTable(table)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := db.GetAll(ctx, fmt.Sprintf(`select * from %s where id in(?)`, table), g.Slice{})
|
||||
t.AssertNil(err)
|
||||
|
||||
@ -6,14 +6,14 @@ replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
require (
|
||||
gitee.com/chunanyong/dm v1.8.12
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
@ -21,7 +21,7 @@ require (
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
gitee.com/chunanyong/dm v1.8.10 h1:9S1CKUggWHIea/GI7nr7S/DNMaxIilNFgfzdzKDx2+I=
|
||||
gitee.com/chunanyong/dm v1.8.10/go.mod h1:EPRJnuPFgbyOFgJ0TRYCTGzhq+ZT4wdyaj/GW/LLcNg=
|
||||
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/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
|
||||
@ -7,8 +7,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
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=
|
||||
@ -26,8 +26,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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=
|
||||
@ -47,7 +47,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -4,14 +4,14 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/denisenkom/go-mssqldb v0.12.3
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
|
||||
@ -20,7 +20,7 @@ require (
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
|
||||
@ -13,8 +13,8 @@ github.com/denisenkom/go-mssqldb v0.12.3/go.mod h1:k0mtMFOnU+AihqFxPMiF05rtiDror
|
||||
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
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=
|
||||
@ -34,8 +34,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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=
|
||||
@ -73,7 +73,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -9,10 +9,11 @@ package mssql_test
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
@ -1906,12 +1907,14 @@ func Test_Model_HasTable(t *testing.T) {
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable(table)
|
||||
t.Assert(result, true)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable("table12321")
|
||||
t.Assert(result, false)
|
||||
t.AssertNil(err)
|
||||
@ -2548,3 +2551,40 @@ func Test_Model_WherePrefixLike(t *testing.T) {
|
||||
t.Assert(r[0]["ID"], "3")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_AllAndCount(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, total, err := db.Model(table).Order("id").Limit(0, 3).AllAndCount(false)
|
||||
t.Assert(err, nil)
|
||||
|
||||
t.Assert(len(result), 3)
|
||||
t.Assert(total, TableSize)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_ScanAndCount(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
Id int
|
||||
Passport string
|
||||
Password string
|
||||
NickName string
|
||||
CreateTime gtime.Time
|
||||
}
|
||||
|
||||
users := make([]User, 0)
|
||||
total := 0
|
||||
|
||||
err := db.Model(table).Order("id").Limit(0, 3).ScanAndCount(&users, &total, false)
|
||||
t.Assert(err, nil)
|
||||
|
||||
t.Assert(len(users), 3)
|
||||
t.Assert(total, TableSize)
|
||||
})
|
||||
}
|
||||
|
||||
@ -4,21 +4,21 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
|
||||
@ -5,8 +5,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
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=
|
||||
@ -24,8 +24,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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=
|
||||
@ -45,7 +45,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -55,7 +55,6 @@ func init() {
|
||||
nodeInvalid := gdb.ConfigNode{
|
||||
Link: fmt.Sprintf("mysql:root:%s@tcp(127.0.0.1:3307)/?loc=Local&parseTime=true", TestDbPass),
|
||||
}
|
||||
|
||||
gdb.AddConfigNode("test", nodeDefault)
|
||||
gdb.AddConfigNode("prefix", nodePrefix)
|
||||
gdb.AddConfigNode("nodeinvalid", nodeInvalid)
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
package mysql_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
@ -881,3 +882,120 @@ func Test_Issue3086(t *testing.T) {
|
||||
t.Assert(n, 2)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3204
|
||||
func Test_Issue3204(t *testing.T) {
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
|
||||
// where
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
g.Meta `orm:"do:true"`
|
||||
Id interface{} `orm:"id,omitempty"`
|
||||
Passport interface{} `orm:"passport,omitempty"`
|
||||
Password interface{} `orm:"password,omitempty"`
|
||||
Nickname interface{} `orm:"nickname,omitempty"`
|
||||
CreateTime interface{} `orm:"create_time,omitempty"`
|
||||
}
|
||||
where := User{
|
||||
Id: 2,
|
||||
Passport: "",
|
||||
}
|
||||
all, err := db.Model(table).Where(where).All()
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(all), 1)
|
||||
t.Assert(all[0]["id"], 2)
|
||||
})
|
||||
// data
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
g.Meta `orm:"do:true"`
|
||||
Id interface{} `orm:"id,omitempty"`
|
||||
Passport interface{} `orm:"passport,omitempty"`
|
||||
Password interface{} `orm:"password,omitempty"`
|
||||
Nickname interface{} `orm:"nickname,omitempty"`
|
||||
CreateTime interface{} `orm:"create_time,omitempty"`
|
||||
}
|
||||
var (
|
||||
err error
|
||||
sqlArray []string
|
||||
insertId int64
|
||||
data = User{
|
||||
Id: 20,
|
||||
Passport: "passport_20",
|
||||
Password: "",
|
||||
}
|
||||
)
|
||||
sqlArray, err = gdb.CatchSQL(ctx, func(ctx context.Context) error {
|
||||
insertId, err = db.Ctx(ctx).Model(table).Data(data).InsertAndGetId()
|
||||
return err
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(insertId, 20)
|
||||
t.Assert(
|
||||
gstr.Contains(sqlArray[len(sqlArray)-1], "(`id`,`passport`) VALUES(20,'passport_20')"),
|
||||
true,
|
||||
)
|
||||
})
|
||||
// update data
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type User struct {
|
||||
g.Meta `orm:"do:true"`
|
||||
Id interface{} `orm:"id,omitempty"`
|
||||
Passport interface{} `orm:"passport,omitempty"`
|
||||
Password interface{} `orm:"password,omitempty"`
|
||||
Nickname interface{} `orm:"nickname,omitempty"`
|
||||
CreateTime interface{} `orm:"create_time,omitempty"`
|
||||
}
|
||||
var (
|
||||
err error
|
||||
sqlArray []string
|
||||
data = User{
|
||||
Passport: "passport_1",
|
||||
Password: "",
|
||||
Nickname: "",
|
||||
}
|
||||
)
|
||||
sqlArray, err = gdb.CatchSQL(ctx, func(ctx context.Context) error {
|
||||
_, err = db.Ctx(ctx).Model(table).Data(data).WherePri(1).Update()
|
||||
return err
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(
|
||||
gstr.Contains(sqlArray[len(sqlArray)-1], "SET `passport`='passport_1' WHERE `id`=1"),
|
||||
true,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogf/gf/issues/3218
|
||||
func Test_Issue3218(t *testing.T) {
|
||||
table := "issue3218_sys_config"
|
||||
array := gstr.SplitAndTrim(gtest.DataContent(`issue3218.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) {
|
||||
type SysConfigInfo struct {
|
||||
Name string `json:"name"`
|
||||
Value map[string]string `json:"value"`
|
||||
}
|
||||
var configData *SysConfigInfo
|
||||
err := db.Model(table).Scan(&configData)
|
||||
t.AssertNil(err)
|
||||
t.Assert(configData, &SysConfigInfo{
|
||||
Name: "site",
|
||||
Value: map[string]string{
|
||||
"fixed_page": "",
|
||||
"site_name": "22",
|
||||
"version": "22",
|
||||
"banned_ip": "22",
|
||||
"filings": "2222",
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@ -3097,12 +3097,14 @@ func Test_Model_HasTable(t *testing.T) {
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable(table)
|
||||
t.Assert(result, true)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable("table12321")
|
||||
t.Assert(result, false)
|
||||
t.AssertNil(err)
|
||||
@ -4706,3 +4708,44 @@ func Test_Scan_Nil_Result_Error(t *testing.T) {
|
||||
t.Assert(err, sql.ErrNoRows)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_FixGdbJoin(t *testing.T) {
|
||||
array := gstr.SplitAndTrim(gtest.DataContent(`fix_gdb_join.sql`), ";")
|
||||
for _, v := range array {
|
||||
if _, err := db.Exec(ctx, v); err != nil {
|
||||
gtest.Error(err)
|
||||
}
|
||||
}
|
||||
defer dropTable(`common_resource`)
|
||||
defer dropTable(`managed_resource`)
|
||||
defer dropTable(`rules_template`)
|
||||
defer dropTable(`resource_mark`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
sqlSlice, err := gdb.CatchSQL(ctx, func(ctx context.Context) error {
|
||||
orm := db.Model(`managed_resource`).Ctx(ctx).
|
||||
LeftJoinOnField(`common_resource`, `resource_id`).
|
||||
LeftJoinOnFields(`resource_mark`, `resource_mark_id`, `=`, `id`).
|
||||
LeftJoinOnFields(`rules_template`, `rule_template_id`, `=`, `template_id`).
|
||||
FieldsPrefix(
|
||||
`managed_resource`,
|
||||
"resource_id", "user", "status", "status_message", "safe_publication", "rule_template_id",
|
||||
"created_at", "comments", "expired_at", "resource_mark_id", "instance_id", "resource_name",
|
||||
"pay_mode").
|
||||
FieldsPrefix(`resource_mark`, "mark_name", "color").
|
||||
FieldsPrefix(`rules_template`, "name").
|
||||
FieldsPrefix(`common_resource`, `src_instance_id`, "database_kind", "source_type", "ip", "port")
|
||||
all, err := orm.OrderAsc("src_instance_id").All()
|
||||
t.Assert(len(all), 4)
|
||||
t.Assert(all[0]["pay_mode"], 1)
|
||||
t.Assert(all[0]["src_instance_id"], 2)
|
||||
t.Assert(all[3]["instance_id"], "dmcins-jxy0x75m")
|
||||
t.Assert(all[3]["src_instance_id"], "vdb-6b6m3u1u")
|
||||
t.Assert(all[3]["resource_mark_id"], "11")
|
||||
return err
|
||||
})
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gtest.DataContent(`fix_gdb_join_expect.sql`), sqlSlice[len(sqlSlice)-1])
|
||||
})
|
||||
}
|
||||
|
||||
151
contrib/drivers/mysql/testdata/fix_gdb_join.sql
vendored
Normal file
151
contrib/drivers/mysql/testdata/fix_gdb_join.sql
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
|
||||
|
||||
DROP TABLE IF EXISTS `common_resource`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `common_resource` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`app_id` bigint(20) NOT NULL,
|
||||
`resource_id` varchar(64) NOT NULL,
|
||||
`src_instance_id` varchar(64) DEFAULT NULL,
|
||||
`region` varchar(36) DEFAULT NULL,
|
||||
`zone` varchar(36) DEFAULT NULL,
|
||||
`database_kind` varchar(20) NOT NULL,
|
||||
`source_type` varchar(64) NOT NULL,
|
||||
`ip` varchar(64) DEFAULT NULL,
|
||||
`port` int(10) DEFAULT NULL,
|
||||
`vpc_id` varchar(20) DEFAULT NULL,
|
||||
`subnet_id` varchar(20) DEFAULT NULL,
|
||||
`proxy_ip` varchar(64) DEFAULT NULL,
|
||||
`proxy_port` int(10) DEFAULT NULL,
|
||||
`proxy_id` bigint(20) DEFAULT NULL,
|
||||
`proxy_snat_ip` varchar(64) DEFAULT NULL,
|
||||
`lease_at` timestamp NULL DEFAULT NULL,
|
||||
`uin` varchar(32) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_resource` (`app_id`,`src_instance_id`,`vpc_id`,`subnet_id`,`ip`,`port`),
|
||||
KEY `resource_id` (`resource_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COMMENT='资源公共信息表';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `common_resource`
|
||||
--
|
||||
|
||||
LOCK TABLES `common_resource` WRITE;
|
||||
/*!40000 ALTER TABLE `common_resource` DISABLE KEYS */;
|
||||
INSERT INTO `common_resource` VALUES (1,1,'2','2','2','3','1','1','1',1,'1','1','1',1,1,'1',NULL,''),(3,2,'3','3','3','3','3','3','3',3,'3','3','3',3,3,'3',NULL,''),(18,1303697168,'dmc-rgnh9qre','vdb-6b6m3u1u','ap-guangzhou','','vdb','cloud','10.0.1.16',80,'vpc-m3dchft7','subnet-9as3a3z2','9.27.72.189',11131,228476,'169.254.128.5, ','2023-11-08 08:13:04',''),(20,1303697168,'dmc-4grzi4jg','tdsqlshard-313spncx','ap-guangzhou','','tdsql','cloud','10.255.0.27',3306,'vpc-407k0e8x','subnet-qhkkk3bo','30.86.239.200',24087,0,'',NULL,'');
|
||||
/*!40000 ALTER TABLE `common_resource` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `managed_resource`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `managed_resource`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `managed_resource` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`instance_id` varchar(64) NOT NULL,
|
||||
`resource_id` varchar(64) NOT NULL,
|
||||
`resource_name` varchar(64) DEFAULT NULL,
|
||||
`status` varchar(36) NOT NULL DEFAULT 'valid',
|
||||
`status_message` varchar(64) DEFAULT NULL,
|
||||
`user` varchar(64) NOT NULL,
|
||||
`password` varchar(1024) NOT NULL,
|
||||
`pay_mode` tinyint(1) DEFAULT '0',
|
||||
`safe_publication` bit(1) DEFAULT b'0',
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`expired_at` timestamp NULL DEFAULT NULL,
|
||||
`deleted` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`resource_mark_id` int(11) DEFAULT NULL,
|
||||
`comments` varchar(64) DEFAULT NULL,
|
||||
`rule_template_id` varchar(64) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `resource_id` (`resource_id`),
|
||||
KEY `instance_id` (`instance_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COMMENT='管控实例表';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `managed_resource`
|
||||
--
|
||||
|
||||
LOCK TABLES `managed_resource` WRITE;
|
||||
/*!40000 ALTER TABLE `managed_resource` DISABLE KEYS */;
|
||||
INSERT INTO `managed_resource` VALUES (1,'2','3','1','1','1','1','1',1,_binary '','2023-11-06 12:14:21','2023-11-06 12:14:21',NULL,1,1,'1',''),(2,'3','2','1','1','1','1','1',1,_binary '\0','2023-11-06 12:15:07','2023-11-06 12:15:07',NULL,1,2,'1',''),(5,'dmcins-jxy0x75m','dmc-rgnh9qre','erichmao-vdb-test','invalid','The Ip field is required','root','2e39af3dd1d447e2b1437b40c62c35995fa22b370c7455ff7815dace3a6e8891ccadcfc893fe1342a4102d742bd7a3e603cd0ac1fcdc072d7c0b5be5836ec87306981b629f9b59aedf0316e9504ab172fa1c95756d5b260114e4feaa0b19223fb61cb268cc4818307ed193dbab830cf556b91cde182686eb70f70ea77f69eff66230dec2ce92bd3352cad31abf47597a5cc6a0d638381dc3bae7aa1b142730790a6d4cefdef1bd460061c966ad5008c2b5fc971b7f4d7dddffa5b1456c45e2917763dd8fffb1fa7fc4783feca95dafc9a9f4edf21b0579f76b0a3154f087e3b9a7fc49af8ff92b12e7b03caa865e72e777dd9d35a11910df0d55ead90e47d5f8',1,_binary '','2023-11-08 08:13:20','2023-11-09 05:31:07',NULL,0,11,NULL,'12345'),(6,'dmcins-erxms6ya','dmc-4grzi4jg','erichmao-vdb-test','invalid','The Ip field is required','leotaowang','641d846cf75bc7944202251d97dca8335f7f149dd4fd911ca5b87c71ef1dc5d0a66c4e5021ef7ad53136cda2fb2567d34e3dd1a7666e3f64ebf532eb2a55d84952aac86b4211f563f7b9da7dd0f88ec288d6680d3513cea0c1b7ad7babb474717f77ebbc9d63bb458adaf982887da9e63df957ffda572c1c3ed187471b99fdc640b45fed76a6d50dc1090eee79b4d94d056c4d43416133481f55bd040759398680104a84d801e6475dcfe919a00859908296747430b728a00c8d54256ae220235a138e0bbf08fe8b6fc8589971436b55bff966154721a91adbdc9c2b6f50ef5849ed77e5b028116abac51584b8d401cd3a88d18df127006358ed33fc3fa6f480',1,_binary '','2023-11-08 22:15:17','2023-11-09 05:31:07',NULL,0,11,NULL,'12345');
|
||||
/*!40000 ALTER TABLE `managed_resource` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `rules_template`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `rules_template`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `rules_template` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
`app_id` bigint(20) DEFAULT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`database_kind` varchar(64) DEFAULT NULL,
|
||||
`is_default` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`win_rules` varchar(2048) DEFAULT NULL,
|
||||
`inception_rules` varchar(2048) DEFAULT NULL,
|
||||
`auto_exec_rules` varchar(2048) DEFAULT NULL,
|
||||
`order_check_step` varchar(2048) DEFAULT NULL,
|
||||
`template_id` varchar(64) NOT NULL DEFAULT '',
|
||||
`version` int(11) NOT NULL DEFAULT '1',
|
||||
`deleted` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`create_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`is_system` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`uin` varchar(64) DEFAULT NULL,
|
||||
`subAccountUin` varchar(64) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uniq_template_id` (`template_id`),
|
||||
UNIQUE KEY `uniq_name` (`name`,`app_id`,`deleted`,`uin`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `rules_template`
|
||||
--
|
||||
|
||||
LOCK TABLES `rules_template` WRITE;
|
||||
/*!40000 ALTER TABLE `rules_template` DISABLE KEYS */;
|
||||
/*!40000 ALTER TABLE `rules_template` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
--
|
||||
-- Table structure for table `resource_mark`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `resource_mark`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!50503 SET character_set_client = utf8mb4 */;
|
||||
CREATE TABLE `resource_mark` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`app_id` bigint(20) NOT NULL,
|
||||
`mark_name` varchar(64) NOT NULL,
|
||||
`color` varchar(11) NOT NULL,
|
||||
`creator` varchar(32) NOT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `app_id_name` (`app_id`,`mark_name`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COMMENT='标签信息表';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Dumping data for table `resource_mark`
|
||||
--
|
||||
|
||||
LOCK TABLES `resource_mark` WRITE;
|
||||
/*!40000 ALTER TABLE `resource_mark` DISABLE KEYS */;
|
||||
INSERT INTO `resource_mark` VALUES (10,1,'test','red','1','2023-11-06 02:45:46','2023-11-06 02:45:46');
|
||||
/*!40000 ALTER TABLE `resource_mark` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
1
contrib/drivers/mysql/testdata/fix_gdb_join_expect.sql
vendored
Normal file
1
contrib/drivers/mysql/testdata/fix_gdb_join_expect.sql
vendored
Normal file
@ -0,0 +1 @@
|
||||
SELECT managed_resource.resource_id,managed_resource.user,managed_resource.status,managed_resource.status_message,managed_resource.safe_publication,managed_resource.rule_template_id,managed_resource.created_at,managed_resource.comments,managed_resource.expired_at,managed_resource.resource_mark_id,managed_resource.instance_id,managed_resource.resource_name,managed_resource.pay_mode,resource_mark.mark_name,resource_mark.color,rules_template.name,common_resource.src_instance_id,common_resource.database_kind,common_resource.source_type,common_resource.ip,common_resource.port FROM `managed_resource` LEFT JOIN `common_resource` ON (`managed_resource`.`resource_id`=`common_resource`.`resource_id`) LEFT JOIN `resource_mark` ON (`managed_resource`.`resource_mark_id` = `resource_mark`.`id`) LEFT JOIN `rules_template` ON (`managed_resource`.`rule_template_id` = `rules_template`.`template_id`) ORDER BY `src_instance_id` ASC
|
||||
14
contrib/drivers/mysql/testdata/issue3218.sql
vendored
Normal file
14
contrib/drivers/mysql/testdata/issue3218.sql
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
CREATE TABLE `issue3218_sys_config` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '配置名称',
|
||||
`value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '配置值',
|
||||
`created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
|
||||
`updated_at` timestamp NULL DEFAULT NULL COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `name`(`name`(191)) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_config
|
||||
-- ----------------------------
|
||||
INSERT INTO `issue3218_sys_config` VALUES (49, 'site', '{\"banned_ip\":\"22\",\"filings\":\"2222\",\"fixed_page\":\"\",\"site_name\":\"22\",\"version\":\"22\"}', '2023-12-19 14:08:25', '2023-12-19 14:08:25');
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/oracle/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/sijms/go-ora/v2 v2.7.10
|
||||
)
|
||||
|
||||
@ -11,14 +11,14 @@ require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
|
||||
@ -5,8 +5,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
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=
|
||||
@ -22,8 +22,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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=
|
||||
@ -45,7 +45,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -950,12 +950,14 @@ func Test_Model_HasTable(t *testing.T) {
|
||||
defer dropTable(table)
|
||||
// db.SetDebug(true)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable(strings.ToUpper(table))
|
||||
t.Assert(result, true)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable("table12321")
|
||||
t.Assert(result, false)
|
||||
t.AssertNil(err)
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/pgsql/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/lib/pq v1.10.9
|
||||
)
|
||||
|
||||
@ -11,14 +11,14 @@ require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
|
||||
@ -5,8 +5,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
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=
|
||||
@ -24,8 +24,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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=
|
||||
@ -45,7 +45,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
@ -237,6 +238,12 @@ func (d *Driver) Tables(ctx context.Context, schema ...string) (tables []string,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
useRelpartbound := ""
|
||||
if gstr.CompareVersion(d.version(ctx, link), "10") >= 0 {
|
||||
useRelpartbound = "AND c.relpartbound IS NULL"
|
||||
}
|
||||
|
||||
var query = fmt.Sprintf(`
|
||||
SELECT
|
||||
c.relname
|
||||
@ -247,10 +254,11 @@ INNER JOIN pg_namespace n ON
|
||||
WHERE
|
||||
n.nspname = '%s'
|
||||
AND c.relkind IN ('r', 'p')
|
||||
AND c.relpartbound IS NULL
|
||||
%s
|
||||
ORDER BY
|
||||
c.relname`,
|
||||
usedSchema,
|
||||
useRelpartbound,
|
||||
)
|
||||
|
||||
query, _ = gregex.ReplaceString(`[\n\r\s]+`, " ", gstr.Trim(query))
|
||||
@ -266,6 +274,23 @@ ORDER BY
|
||||
return
|
||||
}
|
||||
|
||||
// version checks and returns the database version.
|
||||
func (d *Driver) version(ctx context.Context, link gdb.Link) string {
|
||||
result, err := d.DoSelect(ctx, link, "SELECT version();")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if len(result) > 0 {
|
||||
if v, ok := result[0]["version"]; ok {
|
||||
matches := regexp.MustCompile(`PostgreSQL (\d+\.\d+)`).FindStringSubmatch(v.String())
|
||||
if len(matches) >= 2 {
|
||||
return matches[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// TableFields retrieves and returns the fields' information of specified table of current schema.
|
||||
func (d *Driver) TableFields(ctx context.Context, table string, schema ...string) (fields map[string]*gdb.TableField, err error) {
|
||||
var (
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/glebarez/go-sqlite v1.21.2
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
@ -12,7 +12,7 @@ require (
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
@ -20,7 +20,7 @@ require (
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
|
||||
@ -7,8 +7,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
|
||||
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
@ -29,8 +29,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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=
|
||||
@ -53,7 +53,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -2807,12 +2807,14 @@ func Test_Model_HasTable(t *testing.T) {
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable(table)
|
||||
t.Assert(result, true)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable("table12321")
|
||||
t.Assert(result, false)
|
||||
t.AssertNil(err)
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/sqlitecgo/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/mattn/go-sqlite3 v1.14.17
|
||||
)
|
||||
|
||||
@ -11,14 +11,14 @@ require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 // indirect
|
||||
github.com/magiconair/properties v1.8.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/rivo/uniseg v0.4.4 // indirect
|
||||
|
||||
@ -5,8 +5,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
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=
|
||||
@ -22,8 +22,8 @@ github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPK
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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/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=
|
||||
@ -45,7 +45,6 @@ go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+go
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
||||
@ -2835,12 +2835,14 @@ func Test_Model_HasTable(t *testing.T) {
|
||||
defer dropTable(table)
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable(table)
|
||||
t.Assert(result, true)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.AssertNil(db.GetCore().ClearCacheAll(ctx))
|
||||
result, err := db.GetCore().HasTable("table12321")
|
||||
t.Assert(result, false)
|
||||
t.AssertNil(err)
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/nosql/redis/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/redis/go-redis/v9 v9.2.1
|
||||
go.opentelemetry.io/otel v1.14.0
|
||||
go.opentelemetry.io/otel/trace v1.14.0
|
||||
|
||||
@ -8,20 +8,19 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/database/gredis"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
// Redis is an implement of Adapter using go-redis.
|
||||
type Redis struct {
|
||||
gredis.AdapterOperation
|
||||
|
||||
client redis.UniversalClient
|
||||
config *gredis.Config
|
||||
}
|
||||
@ -75,40 +74,12 @@ func New(config *gredis.Config) *Redis {
|
||||
client = redis.NewClient(opts.Simple())
|
||||
}
|
||||
|
||||
return &Redis{
|
||||
r := &Redis{
|
||||
client: client,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
// Do send a command to the server and returns the received reply.
|
||||
// It uses json.Marshal for struct/slice/map type values before committing them to redis.
|
||||
func (r *Redis) Do(ctx context.Context, command string, args ...interface{}) (*gvar.Var, error) {
|
||||
conn, err := r.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = conn.Close(ctx)
|
||||
}()
|
||||
return conn.Do(ctx, command, args...)
|
||||
}
|
||||
|
||||
// Close closes the redis connection pool, which will release all connections reserved by this pool.
|
||||
// It is commonly not necessary to call Close manually.
|
||||
func (r *Redis) Close(ctx context.Context) (err error) {
|
||||
if err = r.client.Close(); err != nil {
|
||||
err = gerror.Wrap(err, `Redis Client Close failed`)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Conn retrieves and returns a connection object for continuous operations.
|
||||
// Note that you should call Close function manually if you do not use this connection any further.
|
||||
func (r *Redis) Conn(ctx context.Context) (gredis.Conn, error) {
|
||||
return &Conn{
|
||||
redis: r,
|
||||
}, nil
|
||||
r.AdapterOperation = r
|
||||
return r
|
||||
}
|
||||
|
||||
func fillWithDefaultConfiguration(config *gredis.Config) {
|
||||
|
||||
@ -18,13 +18,13 @@ import (
|
||||
|
||||
// GroupGeneric provides generic functions of redis.
|
||||
type GroupGeneric struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupGeneric creates and returns GroupGeneric.
|
||||
func (r *Redis) GroupGeneric() gredis.IGroupGeneric {
|
||||
return GroupGeneric{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ func (r GroupGeneric) Copy(ctx context.Context, source, destination string, opti
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "Copy", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "Copy", mustMergeOptionToArgs(
|
||||
[]interface{}{source, destination}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -59,7 +59,7 @@ func (r GroupGeneric) Copy(ctx context.Context, source, destination string, opti
|
||||
//
|
||||
// https://redis.io/commands/exists/
|
||||
func (r GroupGeneric) Exists(ctx context.Context, keys ...string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Exists", gconv.Interfaces(keys)...)
|
||||
v, err := r.Operation.Do(ctx, "Exists", gconv.Interfaces(keys)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func (r GroupGeneric) Exists(ctx context.Context, keys ...string) (int64, error)
|
||||
//
|
||||
// https://redis.io/commands/type/
|
||||
func (r GroupGeneric) Type(ctx context.Context, key string) (string, error) {
|
||||
v, err := r.redis.Do(ctx, "Type", key)
|
||||
v, err := r.Operation.Do(ctx, "Type", key)
|
||||
return v.String(), err
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ func (r GroupGeneric) Type(ctx context.Context, key string) (string, error) {
|
||||
//
|
||||
// https://redis.io/commands/unlink/
|
||||
func (r GroupGeneric) Unlink(ctx context.Context, keys ...string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Unlink", gconv.Interfaces(keys)...)
|
||||
v, err := r.Operation.Do(ctx, "Unlink", gconv.Interfaces(keys)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ func (r GroupGeneric) Unlink(ctx context.Context, keys ...string) (int64, error)
|
||||
//
|
||||
// https://redis.io/commands/rename/
|
||||
func (r GroupGeneric) Rename(ctx context.Context, key, newKey string) error {
|
||||
_, err := r.redis.Do(ctx, "Rename", key, newKey)
|
||||
_, err := r.Operation.Do(ctx, "Rename", key, newKey)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ func (r GroupGeneric) Rename(ctx context.Context, key, newKey string) error {
|
||||
//
|
||||
// https://redis.io/commands/renamenx/
|
||||
func (r GroupGeneric) RenameNX(ctx context.Context, key, newKey string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "RenameNX", key, newKey)
|
||||
v, err := r.Operation.Do(ctx, "RenameNX", key, newKey)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ func (r GroupGeneric) RenameNX(ctx context.Context, key, newKey string) (int64,
|
||||
//
|
||||
// https://redis.io/commands/move/
|
||||
func (r GroupGeneric) Move(ctx context.Context, key string, db int) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Move", key, db)
|
||||
v, err := r.Operation.Do(ctx, "Move", key, db)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ func (r GroupGeneric) Move(ctx context.Context, key string, db int) (int64, erro
|
||||
//
|
||||
// https://redis.io/commands/del/
|
||||
func (r GroupGeneric) Del(ctx context.Context, keys ...string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Del", gconv.Interfaces(keys)...)
|
||||
v, err := r.Operation.Do(ctx, "Del", gconv.Interfaces(keys)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ func (r GroupGeneric) Del(ctx context.Context, keys ...string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/randomkey/
|
||||
func (r GroupGeneric) RandomKey(ctx context.Context) (string, error) {
|
||||
v, err := r.redis.Do(ctx, "RandomKey")
|
||||
v, err := r.Operation.Do(ctx, "RandomKey")
|
||||
return v.String(), err
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func (r GroupGeneric) RandomKey(ctx context.Context) (string, error) {
|
||||
//
|
||||
// https://redis.io/commands/dbsize/
|
||||
func (r GroupGeneric) DBSize(ctx context.Context) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "DBSize")
|
||||
v, err := r.Operation.Do(ctx, "DBSize")
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ func (r GroupGeneric) DBSize(ctx context.Context) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/keys/
|
||||
func (r GroupGeneric) Keys(ctx context.Context, pattern string) ([]string, error) {
|
||||
v, err := r.redis.Do(ctx, "Keys", pattern)
|
||||
v, err := r.Operation.Do(ctx, "Keys", pattern)
|
||||
return v.Strings(), err
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ func (r GroupGeneric) Keys(ctx context.Context, pattern string) ([]string, error
|
||||
//
|
||||
// https://redis.io/commands/flushdb/
|
||||
func (r GroupGeneric) FlushDB(ctx context.Context, option ...gredis.FlushOp) error {
|
||||
_, err := r.redis.Do(ctx, "FlushDB", gconv.Interfaces(option)...)
|
||||
_, err := r.Operation.Do(ctx, "FlushDB", gconv.Interfaces(option)...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ func (r GroupGeneric) FlushDB(ctx context.Context, option ...gredis.FlushOp) err
|
||||
//
|
||||
// https://redis.io/commands/flushall/
|
||||
func (r GroupGeneric) FlushAll(ctx context.Context, option ...gredis.FlushOp) error {
|
||||
_, err := r.redis.Do(ctx, "FlushAll", gconv.Interfaces(option)...)
|
||||
_, err := r.Operation.Do(ctx, "FlushAll", gconv.Interfaces(option)...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ func (r GroupGeneric) Expire(ctx context.Context, key string, seconds int64, opt
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "Expire", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "Expire", mustMergeOptionToArgs(
|
||||
[]interface{}{key, seconds}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -229,7 +229,7 @@ func (r GroupGeneric) ExpireAt(ctx context.Context, key string, time time.Time,
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "ExpireAt", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "ExpireAt", mustMergeOptionToArgs(
|
||||
[]interface{}{key, gtime.New(time).Timestamp()}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -243,7 +243,7 @@ func (r GroupGeneric) ExpireAt(ctx context.Context, key string, time time.Time,
|
||||
//
|
||||
// https://redis.io/commands/expiretime/
|
||||
func (r GroupGeneric) ExpireTime(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "ExpireTime", key)
|
||||
return r.Operation.Do(ctx, "ExpireTime", key)
|
||||
}
|
||||
|
||||
// TTL returns the remaining time to live of a key that has a timeout.
|
||||
@ -263,7 +263,7 @@ func (r GroupGeneric) ExpireTime(ctx context.Context, key string) (*gvar.Var, er
|
||||
//
|
||||
// https://redis.io/commands/ttl/
|
||||
func (r GroupGeneric) TTL(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "TTL", key)
|
||||
v, err := r.Operation.Do(ctx, "TTL", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ func (r GroupGeneric) TTL(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/persist/
|
||||
func (r GroupGeneric) Persist(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Persist", key)
|
||||
v, err := r.Operation.Do(ctx, "Persist", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ func (r GroupGeneric) PExpire(ctx context.Context, key string, milliseconds int6
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "PExpire", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "PExpire", mustMergeOptionToArgs(
|
||||
[]interface{}{key, milliseconds}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -308,7 +308,7 @@ func (r GroupGeneric) PExpireAt(ctx context.Context, key string, time time.Time,
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "PExpireAt", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "PExpireAt", mustMergeOptionToArgs(
|
||||
[]interface{}{key, gtime.New(time).TimestampMilli()}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -322,7 +322,7 @@ func (r GroupGeneric) PExpireAt(ctx context.Context, key string, time time.Time,
|
||||
//
|
||||
// https://redis.io/commands/pexpiretime/
|
||||
func (r GroupGeneric) PExpireTime(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "PExpireTime", key)
|
||||
return r.Operation.Do(ctx, "PExpireTime", key)
|
||||
}
|
||||
|
||||
// PTTL like TTL this command returns the remaining time to live of a key that has an expired set,
|
||||
@ -336,6 +336,6 @@ func (r GroupGeneric) PExpireTime(ctx context.Context, key string) (*gvar.Var, e
|
||||
//
|
||||
// https://redis.io/commands/pttl/
|
||||
func (r GroupGeneric) PTTL(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "PTTL", key)
|
||||
v, err := r.Operation.Do(ctx, "PTTL", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupHash is the redis group object for hash operations.
|
||||
type GroupHash struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupHash creates and returns a redis group object for hash operations.
|
||||
func (r *Redis) GroupHash() gredis.IGroupHash {
|
||||
return GroupHash{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ func (r GroupHash) HSet(ctx context.Context, key string, fields map[string]inter
|
||||
for k, v := range fields {
|
||||
s = append(s, k, v)
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "HSet", s...)
|
||||
v, err := r.Operation.Do(ctx, "HSet", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ func (r GroupHash) HSet(ctx context.Context, key string, fields map[string]inter
|
||||
//
|
||||
// https://redis.io/commands/hsetnx/
|
||||
func (r GroupHash) HSetNX(ctx context.Context, key, field string, value interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HSetNX", key, field, value)
|
||||
v, err := r.Operation.Do(ctx, "HSetNX", key, field, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ func (r GroupHash) HSetNX(ctx context.Context, key, field string, value interfac
|
||||
//
|
||||
// https://redis.io/commands/hget/
|
||||
func (r GroupHash) HGet(ctx context.Context, key, field string) (*gvar.Var, error) {
|
||||
v, err := r.redis.Do(ctx, "HGet", key, field)
|
||||
v, err := r.Operation.Do(ctx, "HGet", key, field)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ func (r GroupHash) HGet(ctx context.Context, key, field string) (*gvar.Var, erro
|
||||
//
|
||||
// https://redis.io/commands/hstrlen/
|
||||
func (r GroupHash) HStrLen(ctx context.Context, key, field string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HSTRLEN", key, field)
|
||||
v, err := r.Operation.Do(ctx, "HSTRLEN", key, field)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ func (r GroupHash) HStrLen(ctx context.Context, key, field string) (int64, error
|
||||
//
|
||||
// https://redis.io/commands/hexists/
|
||||
func (r GroupHash) HExists(ctx context.Context, key, field string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HExists", key, field)
|
||||
v, err := r.Operation.Do(ctx, "HExists", key, field)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ func (r GroupHash) HExists(ctx context.Context, key, field string) (int64, error
|
||||
//
|
||||
// https://redis.io/commands/hdel/
|
||||
func (r GroupHash) HDel(ctx context.Context, key string, fields ...string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HDel", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
|
||||
v, err := r.Operation.Do(ctx, "HDel", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ func (r GroupHash) HDel(ctx context.Context, key string, fields ...string) (int6
|
||||
//
|
||||
// https://redis.io/commands/hlen/
|
||||
func (r GroupHash) HLen(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HLen", key)
|
||||
v, err := r.Operation.Do(ctx, "HLen", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ func (r GroupHash) HLen(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/hincrby/
|
||||
func (r GroupHash) HIncrBy(ctx context.Context, key, field string, increment int64) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HIncrBy", key, field, increment)
|
||||
v, err := r.Operation.Do(ctx, "HIncrBy", key, field, increment)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ func (r GroupHash) HIncrBy(ctx context.Context, key, field string, increment int
|
||||
//
|
||||
// https://redis.io/commands/hincrbyfloat/
|
||||
func (r GroupHash) HIncrByFloat(ctx context.Context, key, field string, increment float64) (float64, error) {
|
||||
v, err := r.redis.Do(ctx, "HIncrByFloat", key, field, increment)
|
||||
v, err := r.Operation.Do(ctx, "HIncrByFloat", key, field, increment)
|
||||
return v.Float64(), err
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ func (r GroupHash) HMSet(ctx context.Context, key string, fields map[string]inte
|
||||
for k, v := range fields {
|
||||
s = append(s, k, v)
|
||||
}
|
||||
_, err := r.redis.Do(ctx, "HMSet", s...)
|
||||
_, err := r.Operation.Do(ctx, "HMSet", s...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ func (r GroupHash) HMSet(ctx context.Context, key string, fields map[string]inte
|
||||
//
|
||||
// https://redis.io/commands/hmget/
|
||||
func (r GroupHash) HMGet(ctx context.Context, key string, fields ...string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "HMGet", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
|
||||
v, err := r.Operation.Do(ctx, "HMGet", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ func (r GroupHash) HMGet(ctx context.Context, key string, fields ...string) (gva
|
||||
//
|
||||
// https://redis.io/commands/hkeys/
|
||||
func (r GroupHash) HKeys(ctx context.Context, key string) ([]string, error) {
|
||||
v, err := r.redis.Do(ctx, "HKeys", key)
|
||||
v, err := r.Operation.Do(ctx, "HKeys", key)
|
||||
return v.Strings(), err
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ func (r GroupHash) HKeys(ctx context.Context, key string) ([]string, error) {
|
||||
//
|
||||
// https://redis.io/commands/hvals/
|
||||
func (r GroupHash) HVals(ctx context.Context, key string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "HVals", key)
|
||||
v, err := r.Operation.Do(ctx, "HVals", key)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -189,6 +189,6 @@ func (r GroupHash) HVals(ctx context.Context, key string) (gvar.Vars, error) {
|
||||
//
|
||||
// https://redis.io/commands/hgetall/
|
||||
func (r GroupHash) HGetAll(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
v, err := r.redis.Do(ctx, "HGetAll", key)
|
||||
v, err := r.Operation.Do(ctx, "HGetAll", key)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupList is the redis group list object.
|
||||
type GroupList struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupList creates and returns a redis group object for list operations.
|
||||
func (r *Redis) GroupList() gredis.IGroupList {
|
||||
return GroupList{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ func (r *Redis) GroupList() gredis.IGroupList {
|
||||
//
|
||||
// https://redis.io/commands/lpush/
|
||||
func (r GroupList) LPush(ctx context.Context, key string, values ...interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LPush", append([]interface{}{key}, values...)...)
|
||||
v, err := r.Operation.Do(ctx, "LPush", append([]interface{}{key}, values...)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ func (r GroupList) LPush(ctx context.Context, key string, values ...interface{})
|
||||
//
|
||||
// https://redis.io/commands/lpushx
|
||||
func (r GroupList) LPushX(ctx context.Context, key string, element interface{}, elements ...interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LPushX", append([]interface{}{key, element}, elements...)...)
|
||||
v, err := r.Operation.Do(ctx, "LPushX", append([]interface{}{key, element}, elements...)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ func (r GroupList) LPushX(ctx context.Context, key string, element interface{},
|
||||
//
|
||||
// https://redis.io/commands/rpush
|
||||
func (r GroupList) RPush(ctx context.Context, key string, values ...interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "RPush", append([]interface{}{key}, values...)...)
|
||||
v, err := r.Operation.Do(ctx, "RPush", append([]interface{}{key}, values...)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ func (r GroupList) RPush(ctx context.Context, key string, values ...interface{})
|
||||
//
|
||||
// https://redis.io/commands/rpushx
|
||||
func (r GroupList) RPushX(ctx context.Context, key string, value interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "RPushX", key, value)
|
||||
v, err := r.Operation.Do(ctx, "RPushX", key, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -103,9 +103,9 @@ func (r GroupList) RPushX(ctx context.Context, key string, value interface{}) (i
|
||||
// https://redis.io/commands/lpop
|
||||
func (r GroupList) LPop(ctx context.Context, key string, count ...int) (*gvar.Var, error) {
|
||||
if len(count) > 0 {
|
||||
return r.redis.Do(ctx, "LPop", key, count[0])
|
||||
return r.Operation.Do(ctx, "LPop", key, count[0])
|
||||
}
|
||||
return r.redis.Do(ctx, "LPop", key)
|
||||
return r.Operation.Do(ctx, "LPop", key)
|
||||
}
|
||||
|
||||
// RPop remove and returns the last element of the list stored at key.
|
||||
@ -126,9 +126,9 @@ func (r GroupList) LPop(ctx context.Context, key string, count ...int) (*gvar.Va
|
||||
// https://redis.io/commands/rpop
|
||||
func (r GroupList) RPop(ctx context.Context, key string, count ...int) (*gvar.Var, error) {
|
||||
if len(count) > 0 {
|
||||
return r.redis.Do(ctx, "RPop", key, count[0])
|
||||
return r.Operation.Do(ctx, "RPop", key, count[0])
|
||||
}
|
||||
return r.redis.Do(ctx, "RPop", key)
|
||||
return r.Operation.Do(ctx, "RPop", key)
|
||||
}
|
||||
|
||||
// LRem removes the first count occurrences of elements equal to value from the list stored at key.
|
||||
@ -137,7 +137,7 @@ func (r GroupList) RPop(ctx context.Context, key string, count ...int) (*gvar.Va
|
||||
//
|
||||
// https://redis.io/commands/lrem/
|
||||
func (r GroupList) LRem(ctx context.Context, key string, count int64, value interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LRem", key, count, value)
|
||||
v, err := r.Operation.Do(ctx, "LRem", key, count, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ func (r GroupList) LRem(ctx context.Context, key string, count int64, value inte
|
||||
//
|
||||
// https://redis.io/commands/llen
|
||||
func (r GroupList) LLen(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LLen", key)
|
||||
v, err := r.Operation.Do(ctx, "LLen", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ func (r GroupList) LLen(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/lindex
|
||||
func (r GroupList) LIndex(ctx context.Context, key string, index int64) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "LIndex", key, index)
|
||||
return r.Operation.Do(ctx, "LIndex", key, index)
|
||||
}
|
||||
|
||||
// LInsert inserts element in the list stored at key either before or after the reference value pivot.
|
||||
@ -174,7 +174,7 @@ func (r GroupList) LIndex(ctx context.Context, key string, index int64) (*gvar.V
|
||||
//
|
||||
// https://redis.io/commands/linsert/
|
||||
func (r GroupList) LInsert(ctx context.Context, key string, op gredis.LInsertOp, pivot, value interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LInsert", key, string(op), pivot, value)
|
||||
v, err := r.Operation.Do(ctx, "LInsert", key, string(op), pivot, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ func (r GroupList) LInsert(ctx context.Context, key string, op gredis.LInsertOp,
|
||||
//
|
||||
// https://redis.io/commands/lset/
|
||||
func (r GroupList) LSet(ctx context.Context, key string, index int64, value interface{}) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "LSet", key, index, value)
|
||||
return r.Operation.Do(ctx, "LSet", key, index, value)
|
||||
}
|
||||
|
||||
// LRange returns the specified elements of the list stored at key.
|
||||
@ -196,7 +196,7 @@ func (r GroupList) LSet(ctx context.Context, key string, index int64, value inte
|
||||
//
|
||||
// https://redis.io/commands/lrange/
|
||||
func (r GroupList) LRange(ctx context.Context, key string, start, stop int64) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "LRange", key, start, stop)
|
||||
v, err := r.Operation.Do(ctx, "LRange", key, start, stop)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ func (r GroupList) LRange(ctx context.Context, key string, start, stop int64) (g
|
||||
//
|
||||
// https://redis.io/commands/ltrim/
|
||||
func (r GroupList) LTrim(ctx context.Context, key string, start, stop int64) error {
|
||||
_, err := r.redis.Do(ctx, "LTrim", key, start, stop)
|
||||
_, err := r.Operation.Do(ctx, "LTrim", key, start, stop)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ func (r GroupList) LTrim(ctx context.Context, key string, start, stop int64) err
|
||||
//
|
||||
// https://redis.io/commands/blpop/
|
||||
func (r GroupList) BLPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "BLPop", append(gconv.Interfaces(keys), timeout)...)
|
||||
v, err := r.Operation.Do(ctx, "BLPop", append(gconv.Interfaces(keys), timeout)...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ func (r GroupList) BLPop(ctx context.Context, timeout int64, keys ...string) (gv
|
||||
//
|
||||
// https://redis.io/commands/brpop/
|
||||
func (r GroupList) BRPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "BRPop", append(gconv.Interfaces(keys), timeout)...)
|
||||
v, err := r.Operation.Do(ctx, "BRPop", append(gconv.Interfaces(keys), timeout)...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ func (r GroupList) BRPop(ctx context.Context, timeout int64, keys ...string) (gv
|
||||
//
|
||||
// https://redis.io/commands/rpoplpush/
|
||||
func (r GroupList) RPopLPush(ctx context.Context, source, destination string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "RPopLPush", source, destination)
|
||||
return r.Operation.Do(ctx, "RPopLPush", source, destination)
|
||||
}
|
||||
|
||||
// BRPopLPush is the blocking variant of RPopLPush.
|
||||
@ -259,5 +259,5 @@ func (r GroupList) RPopLPush(ctx context.Context, source, destination string) (*
|
||||
//
|
||||
// https://redis.io/commands/brpoplpush/
|
||||
func (r GroupList) BRPopLPush(ctx context.Context, source, destination string, timeout int64) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "BRPopLPush", source, destination, timeout)
|
||||
return r.Operation.Do(ctx, "BRPopLPush", source, destination, timeout)
|
||||
}
|
||||
|
||||
@ -14,13 +14,13 @@ import (
|
||||
|
||||
// GroupPubSub provides pub/sub functions for redis.
|
||||
type GroupPubSub struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupPubSub creates and returns GroupPubSub.
|
||||
func (r *Redis) GroupPubSub() gredis.IGroupPubSub {
|
||||
return GroupPubSub{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ func (r *Redis) GroupPubSub() gredis.IGroupPubSub {
|
||||
//
|
||||
// https://redis.io/commands/publish/
|
||||
func (r GroupPubSub) Publish(ctx context.Context, channel string, message interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Publish", channel, message)
|
||||
v, err := r.Operation.Do(ctx, "Publish", channel, message)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ func (r GroupPubSub) Publish(ctx context.Context, channel string, message interf
|
||||
func (r GroupPubSub) Subscribe(
|
||||
ctx context.Context, channel string, channels ...string,
|
||||
) (gredis.Conn, []*gredis.Subscription, error) {
|
||||
conn, err := r.redis.Conn(ctx)
|
||||
conn, err := r.Operation.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -70,7 +70,7 @@ func (r GroupPubSub) Subscribe(
|
||||
func (r GroupPubSub) PSubscribe(
|
||||
ctx context.Context, pattern string, patterns ...string,
|
||||
) (gredis.Conn, []*gredis.Subscription, error) {
|
||||
conn, err := r.redis.Conn(ctx)
|
||||
conn, err := r.Operation.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupScript provides script functions for redis.
|
||||
type GroupScript struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupScript creates and returns GroupScript.
|
||||
func (r *Redis) GroupScript() gredis.IGroupScript {
|
||||
return GroupScript{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ func (r GroupScript) Eval(ctx context.Context, script string, numKeys int64, key
|
||||
var s = []interface{}{script, numKeys}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
s = append(s, args...)
|
||||
v, err := r.redis.Do(ctx, "Eval", s...)
|
||||
v, err := r.Operation.Do(ctx, "Eval", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ func (r GroupScript) EvalSha(ctx context.Context, sha1 string, numKeys int64, ke
|
||||
var s = []interface{}{sha1, numKeys}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
s = append(s, args...)
|
||||
v, err := r.redis.Do(ctx, "EvalSha", s...)
|
||||
v, err := r.Operation.Do(ctx, "EvalSha", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ func (r GroupScript) EvalSha(ctx context.Context, sha1 string, numKeys int64, ke
|
||||
//
|
||||
// https://redis.io/commands/script-load/
|
||||
func (r GroupScript) ScriptLoad(ctx context.Context, script string) (string, error) {
|
||||
v, err := r.redis.Do(ctx, "Script", "Load", script)
|
||||
v, err := r.Operation.Do(ctx, "Script", "Load", script)
|
||||
return v.String(), err
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ func (r GroupScript) ScriptExists(ctx context.Context, sha1 string, sha1s ...str
|
||||
)
|
||||
s = append(s, "Exists")
|
||||
s = append(s, sha1Array...)
|
||||
result, err := r.redis.Do(ctx, "Script", s...)
|
||||
result, err := r.Operation.Do(ctx, "Script", s...)
|
||||
var (
|
||||
m = make(map[string]bool)
|
||||
resultArray = result.Vars()
|
||||
@ -99,7 +99,7 @@ func (r GroupScript) ScriptFlush(ctx context.Context, option ...gredis.ScriptFlu
|
||||
s = append(s, mustMergeOptionToArgs(
|
||||
[]interface{}{}, usedOption,
|
||||
)...)
|
||||
_, err := r.redis.Do(ctx, "Script", s...)
|
||||
_, err := r.Operation.Do(ctx, "Script", s...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -108,6 +108,6 @@ func (r GroupScript) ScriptFlush(ctx context.Context, option ...gredis.ScriptFlu
|
||||
//
|
||||
// https://redis.io/commands/script-kill/
|
||||
func (r GroupScript) ScriptKill(ctx context.Context) error {
|
||||
_, err := r.redis.Do(ctx, "Script", "Kill")
|
||||
_, err := r.Operation.Do(ctx, "Script", "Kill")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupSet provides set functions for redis.
|
||||
type GroupSet struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupSet creates and returns GroupSet.
|
||||
func (r *Redis) GroupSet() gredis.IGroupSet {
|
||||
return GroupSet{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ func (r GroupSet) SAdd(ctx context.Context, key string, member interface{}, memb
|
||||
var s = []interface{}{key}
|
||||
s = append(s, member)
|
||||
s = append(s, members...)
|
||||
v, err := r.redis.Do(ctx, "SAdd", s...)
|
||||
v, err := r.Operation.Do(ctx, "SAdd", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ func (r GroupSet) SAdd(ctx context.Context, key string, member interface{}, memb
|
||||
//
|
||||
// https://redis.io/commands/sismember/
|
||||
func (r GroupSet) SIsMember(ctx context.Context, key string, member interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "SIsMember", key, member)
|
||||
v, err := r.Operation.Do(ctx, "SIsMember", key, member)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ func (r GroupSet) SIsMember(ctx context.Context, key string, member interface{})
|
||||
func (r GroupSet) SPop(ctx context.Context, key string, count ...int) (*gvar.Var, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(count)...)
|
||||
v, err := r.redis.Do(ctx, "SPop", s...)
|
||||
v, err := r.Operation.Do(ctx, "SPop", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func (r GroupSet) SPop(ctx context.Context, key string, count ...int) (*gvar.Var
|
||||
func (r GroupSet) SRandMember(ctx context.Context, key string, count ...int) (*gvar.Var, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(count)...)
|
||||
v, err := r.redis.Do(ctx, "SRandMember", s...)
|
||||
v, err := r.Operation.Do(ctx, "SRandMember", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ func (r GroupSet) SRem(ctx context.Context, key string, member interface{}, memb
|
||||
var s = []interface{}{key}
|
||||
s = append(s, member)
|
||||
s = append(s, members...)
|
||||
v, err := r.redis.Do(ctx, "SRem", s...)
|
||||
v, err := r.Operation.Do(ctx, "SRem", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ func (r GroupSet) SRem(ctx context.Context, key string, member interface{}, memb
|
||||
//
|
||||
// https://redis.io/commands/smove/
|
||||
func (r GroupSet) SMove(ctx context.Context, source, destination string, member interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "SMove", source, destination, member)
|
||||
v, err := r.Operation.Do(ctx, "SMove", source, destination, member)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ func (r GroupSet) SMove(ctx context.Context, source, destination string, member
|
||||
//
|
||||
// https://redis.io/commands/scard/
|
||||
func (r GroupSet) SCard(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "SCard", key)
|
||||
v, err := r.Operation.Do(ctx, "SCard", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ func (r GroupSet) SCard(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/smembers/
|
||||
func (r GroupSet) SMembers(ctx context.Context, key string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "SMembers", key)
|
||||
v, err := r.Operation.Do(ctx, "SMembers", key)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ func (r GroupSet) SMembers(ctx context.Context, key string) (gvar.Vars, error) {
|
||||
func (r GroupSet) SMIsMember(ctx context.Context, key, member interface{}, members ...interface{}) ([]int, error) {
|
||||
var s = []interface{}{key, member}
|
||||
s = append(s, members...)
|
||||
v, err := r.redis.Do(ctx, "SMIsMember", s...)
|
||||
v, err := r.Operation.Do(ctx, "SMIsMember", s...)
|
||||
return v.Ints(), err
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ func (r GroupSet) SMIsMember(ctx context.Context, key, member interface{}, membe
|
||||
func (r GroupSet) SInter(ctx context.Context, key string, keys ...string) (gvar.Vars, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SInter", s...)
|
||||
v, err := r.Operation.Do(ctx, "SInter", s...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ func (r GroupSet) SInter(ctx context.Context, key string, keys ...string) (gvar.
|
||||
func (r GroupSet) SInterStore(ctx context.Context, destination string, key string, keys ...string) (int64, error) {
|
||||
var s = []interface{}{destination, key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SInterStore", s...)
|
||||
v, err := r.Operation.Do(ctx, "SInterStore", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ func (r GroupSet) SInterStore(ctx context.Context, destination string, key strin
|
||||
func (r GroupSet) SUnion(ctx context.Context, key string, keys ...string) (gvar.Vars, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SUnion", s...)
|
||||
v, err := r.Operation.Do(ctx, "SUnion", s...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ func (r GroupSet) SUnion(ctx context.Context, key string, keys ...string) (gvar.
|
||||
func (r GroupSet) SUnionStore(ctx context.Context, destination, key string, keys ...string) (int64, error) {
|
||||
var s = []interface{}{destination, key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SUnionStore", s...)
|
||||
v, err := r.Operation.Do(ctx, "SUnionStore", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ func (r GroupSet) SUnionStore(ctx context.Context, destination, key string, keys
|
||||
func (r GroupSet) SDiff(ctx context.Context, key string, keys ...string) (gvar.Vars, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SDiff", s...)
|
||||
v, err := r.Operation.Do(ctx, "SDiff", s...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -247,6 +247,6 @@ func (r GroupSet) SDiff(ctx context.Context, key string, keys ...string) (gvar.V
|
||||
func (r GroupSet) SDiffStore(ctx context.Context, destination string, key string, keys ...string) (int64, error) {
|
||||
var s = []interface{}{destination, key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SDiffStore", s...)
|
||||
v, err := r.Operation.Do(ctx, "SDiffStore", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -15,13 +15,13 @@ import (
|
||||
|
||||
// GroupSortedSet provides sorted set functions for redis.
|
||||
type GroupSortedSet struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupSortedSet creates and returns GroupSortedSet.
|
||||
func (r *Redis) GroupSortedSet() gredis.IGroupSortedSet {
|
||||
return GroupSortedSet{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ func (r GroupSortedSet) ZAdd(
|
||||
for _, item := range members {
|
||||
s = append(s, item.Score, item.Member)
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "ZAdd", s...)
|
||||
v, err := r.Operation.Do(ctx, "ZAdd", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ func (r GroupSortedSet) ZAdd(
|
||||
//
|
||||
// https://redis.io/commands/zscore/
|
||||
func (r GroupSortedSet) ZScore(ctx context.Context, key string, member interface{}) (float64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZScore", key, member)
|
||||
v, err := r.Operation.Do(ctx, "ZScore", key, member)
|
||||
return v.Float64(), err
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ func (r GroupSortedSet) ZScore(ctx context.Context, key string, member interface
|
||||
//
|
||||
// https://redis.io/commands/zincrby/
|
||||
func (r GroupSortedSet) ZIncrBy(ctx context.Context, key string, increment float64, member interface{}) (float64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZIncrBy", key, increment, member)
|
||||
v, err := r.Operation.Do(ctx, "ZIncrBy", key, increment, member)
|
||||
return v.Float64(), err
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ func (r GroupSortedSet) ZIncrBy(ctx context.Context, key string, increment float
|
||||
//
|
||||
// https://redis.io/commands/zcard/
|
||||
func (r GroupSortedSet) ZCard(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZCard", key)
|
||||
v, err := r.Operation.Do(ctx, "ZCard", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ func (r GroupSortedSet) ZCard(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/zcount/
|
||||
func (r GroupSortedSet) ZCount(ctx context.Context, key string, min, max string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZCount", key, min, max)
|
||||
v, err := r.Operation.Do(ctx, "ZCount", key, min, max)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ func (r GroupSortedSet) ZRange(ctx context.Context, key string, start, stop int6
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "ZRange", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "ZRange", mustMergeOptionToArgs(
|
||||
[]interface{}{key, start, stop}, usedOption,
|
||||
)...)
|
||||
return v.Vars(), err
|
||||
@ -144,7 +144,7 @@ func (r GroupSortedSet) ZRevRange(ctx context.Context, key string, start, stop i
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
return r.redis.Do(ctx, "ZRevRange", mustMergeOptionToArgs(
|
||||
return r.Operation.Do(ctx, "ZRevRange", mustMergeOptionToArgs(
|
||||
[]interface{}{key, start, stop}, usedOption,
|
||||
)...)
|
||||
}
|
||||
@ -160,7 +160,7 @@ func (r GroupSortedSet) ZRevRange(ctx context.Context, key string, start, stop i
|
||||
//
|
||||
// https://redis.io/commands/zrank/
|
||||
func (r GroupSortedSet) ZRank(ctx context.Context, key string, member interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRank", key, member)
|
||||
v, err := r.Operation.Do(ctx, "ZRank", key, member)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ func (r GroupSortedSet) ZRank(ctx context.Context, key string, member interface{
|
||||
//
|
||||
// https://redis.io/commands/zrevrank/
|
||||
func (r GroupSortedSet) ZRevRank(ctx context.Context, key string, member interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRevRank", key, member)
|
||||
v, err := r.Operation.Do(ctx, "ZRevRank", key, member)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ func (r GroupSortedSet) ZRem(ctx context.Context, key string, member interface{}
|
||||
var s = []interface{}{key}
|
||||
s = append(s, member)
|
||||
s = append(s, members...)
|
||||
v, err := r.redis.Do(ctx, "ZRem", s...)
|
||||
v, err := r.Operation.Do(ctx, "ZRem", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ func (r GroupSortedSet) ZRem(ctx context.Context, key string, member interface{}
|
||||
//
|
||||
// https://redis.io/commands/zremrangebyrank/
|
||||
func (r GroupSortedSet) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRemRangeByRank", key, start, stop)
|
||||
v, err := r.Operation.Do(ctx, "ZRemRangeByRank", key, start, stop)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ func (r GroupSortedSet) ZRemRangeByRank(ctx context.Context, key string, start,
|
||||
//
|
||||
// https://redis.io/commands/zremrangebyscore/
|
||||
func (r GroupSortedSet) ZRemRangeByScore(ctx context.Context, key string, min, max string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRemRangeByScore", key, min, max)
|
||||
v, err := r.Operation.Do(ctx, "ZRemRangeByScore", key, min, max)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ func (r GroupSortedSet) ZRemRangeByScore(ctx context.Context, key string, min, m
|
||||
//
|
||||
// https://redis.io/commands/zremrangebylex/
|
||||
func (r GroupSortedSet) ZRemRangeByLex(ctx context.Context, key string, min, max string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRemRangeByLex", key, min, max)
|
||||
v, err := r.Operation.Do(ctx, "ZRemRangeByLex", key, min, max)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -249,6 +249,6 @@ func (r GroupSortedSet) ZRemRangeByLex(ctx context.Context, key string, min, max
|
||||
//
|
||||
// https://redis.io/commands/zlexcount/
|
||||
func (r GroupSortedSet) ZLexCount(ctx context.Context, key, min, max string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZLexCount", key, min, max)
|
||||
v, err := r.Operation.Do(ctx, "ZLexCount", key, min, max)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupString is the function group manager for string operations.
|
||||
type GroupString struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupString is the redis group object for string operations.
|
||||
func (r *Redis) GroupString() gredis.IGroupString {
|
||||
return GroupString{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ func (r GroupString) Set(ctx context.Context, key string, value interface{}, opt
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
return r.redis.Do(ctx, "Set", mustMergeOptionToArgs(
|
||||
return r.Operation.Do(ctx, "Set", mustMergeOptionToArgs(
|
||||
[]interface{}{key, value}, usedOption,
|
||||
)...)
|
||||
}
|
||||
@ -52,7 +52,7 @@ func (r GroupString) Set(ctx context.Context, key string, value interface{}, opt
|
||||
//
|
||||
// https://redis.io/commands/setnx/
|
||||
func (r GroupString) SetNX(ctx context.Context, key string, value interface{}) (bool, error) {
|
||||
v, err := r.redis.Do(ctx, "SetNX", key, value)
|
||||
v, err := r.Operation.Do(ctx, "SetNX", key, value)
|
||||
return v.Bool(), err
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func (r GroupString) SetNX(ctx context.Context, key string, value interface{}) (
|
||||
//
|
||||
// https://redis.io/commands/setex/
|
||||
func (r GroupString) SetEX(ctx context.Context, key string, value interface{}, ttlInSeconds int64) error {
|
||||
_, err := r.redis.Do(ctx, "SetEX", key, ttlInSeconds, value)
|
||||
_, err := r.Operation.Do(ctx, "SetEX", key, ttlInSeconds, value)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ func (r GroupString) SetEX(ctx context.Context, key string, value interface{}, t
|
||||
//
|
||||
// https://redis.io/commands/get/
|
||||
func (r GroupString) Get(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "Get", key)
|
||||
return r.Operation.Do(ctx, "Get", key)
|
||||
}
|
||||
|
||||
// GetDel gets the value of key and delete the key.
|
||||
@ -88,7 +88,7 @@ func (r GroupString) Get(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
//
|
||||
// https://redis.io/commands/getdel/
|
||||
func (r GroupString) GetDel(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "GetDel", key)
|
||||
return r.Operation.Do(ctx, "GetDel", key)
|
||||
}
|
||||
|
||||
// GetEX is similar to GET, but is a write command with additional options.
|
||||
@ -99,7 +99,7 @@ func (r GroupString) GetEX(ctx context.Context, key string, option ...gredis.Get
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
return r.redis.Do(ctx, "GetEX", mustMergeOptionToArgs(
|
||||
return r.Operation.Do(ctx, "GetEX", mustMergeOptionToArgs(
|
||||
[]interface{}{key}, usedOption,
|
||||
)...)
|
||||
}
|
||||
@ -110,7 +110,7 @@ func (r GroupString) GetEX(ctx context.Context, key string, option ...gredis.Get
|
||||
//
|
||||
// https://redis.io/commands/getset/
|
||||
func (r GroupString) GetSet(ctx context.Context, key string, value interface{}) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "GetSet", key, value)
|
||||
return r.Operation.Do(ctx, "GetSet", key, value)
|
||||
}
|
||||
|
||||
// StrLen returns the length of the string value stored at key.
|
||||
@ -120,7 +120,7 @@ func (r GroupString) GetSet(ctx context.Context, key string, value interface{})
|
||||
//
|
||||
// https://redis.io/commands/strlen/
|
||||
func (r GroupString) StrLen(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "StrLen", key)
|
||||
v, err := r.Operation.Do(ctx, "StrLen", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ func (r GroupString) StrLen(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/append/
|
||||
func (r GroupString) Append(ctx context.Context, key string, value string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Append", key, value)
|
||||
v, err := r.Operation.Do(ctx, "Append", key, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ func (r GroupString) Append(ctx context.Context, key string, value string) (int6
|
||||
//
|
||||
// https://redis.io/commands/setrange/
|
||||
func (r GroupString) SetRange(ctx context.Context, key string, offset int64, value string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "SetRange", key, offset, value)
|
||||
v, err := r.Operation.Do(ctx, "SetRange", key, offset, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func (r GroupString) SetRange(ctx context.Context, key string, offset int64, val
|
||||
//
|
||||
// https://redis.io/commands/getrange/
|
||||
func (r GroupString) GetRange(ctx context.Context, key string, start, end int64) (string, error) {
|
||||
v, err := r.redis.Do(ctx, "GetRange", key, start, end)
|
||||
v, err := r.Operation.Do(ctx, "GetRange", key, start, end)
|
||||
return v.String(), err
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ func (r GroupString) GetRange(ctx context.Context, key string, start, end int64)
|
||||
//
|
||||
// https://redis.io/commands/incr/
|
||||
func (r GroupString) Incr(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Incr", key)
|
||||
v, err := r.Operation.Do(ctx, "Incr", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ func (r GroupString) Incr(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/incrby/
|
||||
func (r GroupString) IncrBy(ctx context.Context, key string, increment int64) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "IncrBy", key, increment)
|
||||
v, err := r.Operation.Do(ctx, "IncrBy", key, increment)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ func (r GroupString) IncrBy(ctx context.Context, key string, increment int64) (i
|
||||
//
|
||||
// https://redis.io/commands/incrbyfloat/
|
||||
func (r GroupString) IncrByFloat(ctx context.Context, key string, increment float64) (float64, error) {
|
||||
v, err := r.redis.Do(ctx, "IncrByFloat", key, increment)
|
||||
v, err := r.Operation.Do(ctx, "IncrByFloat", key, increment)
|
||||
return v.Float64(), err
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ func (r GroupString) IncrByFloat(ctx context.Context, key string, increment floa
|
||||
//
|
||||
// https://redis.io/commands/decr/
|
||||
func (r GroupString) Decr(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Decr", key)
|
||||
v, err := r.Operation.Do(ctx, "Decr", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ func (r GroupString) Decr(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/decrby/
|
||||
func (r GroupString) DecrBy(ctx context.Context, key string, decrement int64) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "DecrBy", key, decrement)
|
||||
v, err := r.Operation.Do(ctx, "DecrBy", key, decrement)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -219,7 +219,7 @@ func (r GroupString) MSet(ctx context.Context, keyValueMap map[string]interface{
|
||||
for k, v := range keyValueMap {
|
||||
args = append(args, k, v)
|
||||
}
|
||||
_, err := r.redis.Do(ctx, "MSet", args...)
|
||||
_, err := r.Operation.Do(ctx, "MSet", args...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ func (r GroupString) MSetNX(ctx context.Context, keyValueMap map[string]interfac
|
||||
for k, v := range keyValueMap {
|
||||
args = append(args, k, v)
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "MSetNX", args...)
|
||||
v, err := r.Operation.Do(ctx, "MSetNX", args...)
|
||||
return v.Bool(), err
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ func (r GroupString) MSetNX(ctx context.Context, keyValueMap map[string]interfac
|
||||
// https://redis.io/commands/mget/
|
||||
func (r GroupString) MGet(ctx context.Context, keys ...string) (map[string]*gvar.Var, error) {
|
||||
var result = make(map[string]*gvar.Var)
|
||||
v, err := r.redis.Do(ctx, "MGet", gconv.Interfaces(keys)...)
|
||||
v, err := r.Operation.Do(ctx, "MGet", gconv.Interfaces(keys)...)
|
||||
if err == nil {
|
||||
values := v.Vars()
|
||||
for i, key := range keys {
|
||||
|
||||
45
contrib/nosql/redis/redis_operation.go
Normal file
45
contrib/nosql/redis/redis_operation.go
Normal file
@ -0,0 +1,45 @@
|
||||
// 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 redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/database/gredis"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
// Do send a command to the server and returns the received reply.
|
||||
// It uses json.Marshal for struct/slice/map type values before committing them to redis.
|
||||
func (r *Redis) Do(ctx context.Context, command string, args ...interface{}) (*gvar.Var, error) {
|
||||
conn, err := r.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = conn.Close(ctx)
|
||||
}()
|
||||
return conn.Do(ctx, command, args...)
|
||||
}
|
||||
|
||||
// Close closes the redis connection pool, which will release all connections reserved by this pool.
|
||||
// It is commonly not necessary to call Close manually.
|
||||
func (r *Redis) Close(ctx context.Context) (err error) {
|
||||
if err = r.client.Close(); err != nil {
|
||||
err = gerror.Wrap(err, `Operation Client Close failed`)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Conn retrieves and returns a connection object for continuous operations.
|
||||
// Note that you should call Close function manually if you do not use this connection any further.
|
||||
func (r *Redis) Conn(ctx context.Context) (gredis.Conn, error) {
|
||||
return &Conn{
|
||||
redis: r,
|
||||
}, nil
|
||||
}
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/etcd/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
go.etcd.io/etcd/client/v3 v3.5.7
|
||||
)
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ module github.com/gogf/gf/contrib/registry/file/v2
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.5.6
|
||||
require github.com/gogf/gf/v2 v2.6.2
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
|
||||
@ -3,13 +3,18 @@ module github.com/gogf/gf/contrib/registry/nacos/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/joy999/nacos-sdk-go v0.0.0-20231120071639-10a34b3e7288
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 // indirect
|
||||
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
|
||||
github.com/alibabacloud-go/tea v1.1.17 // indirect
|
||||
github.com/alibabacloud-go/tea-utils v1.4.4 // indirect
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800 // indirect
|
||||
github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2 // indirect
|
||||
github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/buger/jsonparser v1.1.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
@ -44,6 +49,7 @@ require (
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.21.0 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
|
||||
@ -40,8 +40,19 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704 h1:PpfENOj/vPfhhy9N2OFRjpue0hjM5XqAp2thFmkXXIk=
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1704/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU=
|
||||
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 h1:NqugFkGxx1TXSh/pBcU00Y6bljgDPaFdh5MUSeJ7e50=
|
||||
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY=
|
||||
github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg=
|
||||
github.com/alibabacloud-go/tea v1.1.17 h1:05R5DnaJXe9sCNIe8KUgWHC/z6w/VZIwczgUwzRnul8=
|
||||
github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A=
|
||||
github.com/alibabacloud-go/tea-utils v1.4.4 h1:lxCDvNCdTo9FaXKKq45+4vGETQUKNOW/qKTcX9Sk53o=
|
||||
github.com/alibabacloud-go/tea-utils v1.4.4/go.mod h1:KNcT0oXlZZxOXINnZBs6YvgOd5aYp9U67G+E3R8fcQw=
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800 h1:ie/8RxBOfKZWcrbYSJi2Z8uX8TcOlSMwPlEJh83OeOw=
|
||||
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1800/go.mod h1:RcDobYh8k5VP6TNybz9m++gL3ijVI5wueVr0EM10VsU=
|
||||
github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2 h1:rWkH6D2XlXb/Y+tNAQROxBzp3a0p92ni+pXcaHBe/WI=
|
||||
github.com/aliyun/alibabacloud-dkms-gcs-go-sdk v0.2.2/go.mod h1:GDtq+Kw+v0fO+j5BrrWiUHbBq7L+hfpzpPfXKOZMFE0=
|
||||
github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7 h1:olLiPI2iM8Hqq6vKnSxpM3awCrm9/BeOgHpzQkOYnI4=
|
||||
github.com/aliyun/alibabacloud-dkms-transfer-go-sdk v0.1.7/go.mod h1:oDg1j4kFxnhgftaiLJABkGeSvuEvSF5Lo6UmRAMruX4=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
@ -155,8 +166,8 @@ 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-20231008093845-7f2f84bc6faa h1:FPzhsWW/aZQKw9tWOTvLc8lpKLGnPVBMaF0B+DIvKlc=
|
||||
github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa/go.mod h1:vks3UUh7Hp+e5qbvDySGnvVCD0RYqjyDy/RpVMSf3xc=
|
||||
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=
|
||||
@ -241,6 +252,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
@ -270,7 +282,10 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/polaris/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/polarismesh/polaris-go v1.5.5
|
||||
)
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/go-zookeeper/zk v1.0.3
|
||||
github.com/gogf/gf/v2 v2.5.6
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
golang.org/x/sync v0.4.0
|
||||
)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user