mirror of
https://gitee.com/johng/gf
synced 2026-06-23 08:29:25 +08:00
Compare commits
107 Commits
feat/examp
...
v2.9.4
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b7b4c8581 | |||
| b8844f3d40 | |||
| 3e2176d799 | |||
| 2f9225057f | |||
| 7b373446dc | |||
| 0f6d47c7a8 | |||
| f24729206b | |||
| 7e9715ab1d | |||
| f565a347c4 | |||
| f172e61585 | |||
| 22d873f6bd | |||
| b60b04e27a | |||
| d2bc5d812b | |||
| 0648fd688e | |||
| d0cfcce85b | |||
| 2518d490c3 | |||
| edc96a8c16 | |||
| 22427a08ad | |||
| 41a5484620 | |||
| 325ee45a55 | |||
| 627aa5d27f | |||
| 47db44843e | |||
| a39498f74f | |||
| 80b866e11c | |||
| 2a77d3203e | |||
| 3c451bef82 | |||
| 5073f25691 | |||
| 40e97f1325 | |||
| 502d158bc0 | |||
| f08897a114 | |||
| b6181e4bde | |||
| f8cdeae2d7 | |||
| bea060af4c | |||
| 94cc233325 | |||
| 71743e6903 | |||
| f9ec3b19f7 | |||
| ee24da4e72 | |||
| 26f20787ba | |||
| 1371b3bad5 | |||
| 1da73451b9 | |||
| 94b623e126 | |||
| 4262aa254d | |||
| 8cff64915b | |||
| bec98e8de0 | |||
| a6dbf4b7eb | |||
| 0c2f60468b | |||
| 656ae070da | |||
| 2d5fcd73cb | |||
| 82043856f4 | |||
| 7ffdff37e4 | |||
| 24083b865d | |||
| 8cb64c9f88 | |||
| 5fa656d1cc | |||
| 09ec90746a | |||
| c0d1e44526 | |||
| b323862b4c | |||
| 3d9cdb8997 | |||
| 7180d895ea | |||
| afb1595fbe | |||
| 6637add9ca | |||
| bc862cf97b | |||
| 9033ca087b | |||
| b985fd978c | |||
| 88c4471500 | |||
| b73e2047db | |||
| 1534abdb05 | |||
| fee38b4531 | |||
| 69e3362d0d | |||
| 9a61a6970f | |||
| abf77fac50 | |||
| 07696fc779 | |||
| bc1e1019c5 | |||
| bb696bb281 | |||
| 029f324c5c | |||
| f8331bad6e | |||
| bcda48bf82 | |||
| a8a055f122 | |||
| dfe088f5cd | |||
| f4074cd815 | |||
| 4a65e7a629 | |||
| ac653d3dee | |||
| 2d3ab4f9fb | |||
| bda42d18ee | |||
| 63cb3285f8 | |||
| 2fa03556ef | |||
| 01593ad8b6 | |||
| 42d8845d35 | |||
| 1ef1c442d3 | |||
| 7d3b055d3e | |||
| a3b3c656d9 | |||
| 0eb229a887 | |||
| 20b1987828 | |||
| e12768207e | |||
| f9c7eae23b | |||
| 1f8845291a | |||
| 6bd15b0796 | |||
| 99f0fb14a1 | |||
| e0f734851e | |||
| 3f24b4da2e | |||
| fc9093a1aa | |||
| f66e09717c | |||
| 89e5285d95 | |||
| e6bee78be4 | |||
| 96e833db6e | |||
| 2c1fcec88c | |||
| a5c8b966e2 | |||
| 233295be07 |
20
.github/PULL_REQUEST_TEMPLATE.MD
vendored
20
.github/PULL_REQUEST_TEMPLATE.MD
vendored
@ -1,16 +1,16 @@
|
|||||||
**Please ensure you adhere to every item in this list.**
|
**Please ensure you adhere to every item in this list.**
|
||||||
+ The PR title is formatted as follows: `<type>[optional scope]: <description>` For example, `fix(os/gtime): fix time zone issue`
|
+ The PR title is formatted as follows: `<type>[optional scope]: <description>` For example, `fix(os/gtime): fix time zone issue`
|
||||||
+ `<type>` is mandatory and can be one of `fix`, `feat`, `build`, `ci`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`
|
+ `<type>` is mandatory and can be one of `fix`, `feat`, `build`, `ci`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`
|
||||||
+ fix: Used when a bug has been fixed.
|
+ `fix`: Used when a bug has been fixed.
|
||||||
+ feat: Used when a new feature has been added.
|
+ `feat`: Used when a new feature has been added.
|
||||||
+ build: Used for modifications to the project build system, such as changes to dependencies, external interfaces, or upgrading Node version.
|
+ `build`: Used for modifications to the project build system, such as changes to dependencies, external interfaces, or upgrading Node version.
|
||||||
+ ci: Used for modifications to continuous integration processes, such as changes to Travis, Jenkins workflow configurations.
|
+ `ci`: Used for modifications to continuous integration processes, such as changes to Travis, Jenkins workflow configurations.
|
||||||
+ docs: Used for modifications to documentation, such as changes to README files, API documentation, etc.
|
+ `docs`: Used for modifications to documentation, such as changes to README files, API documentation, etc.
|
||||||
+ style: Used for changes to code style, such as adjustments to indentation, spaces, blank lines, etc.
|
+ `style`: Used for changes to code style, such as adjustments to indentation, spaces, blank lines, etc.
|
||||||
+ refactor: Used for code refactoring, such as changes to code structure, variable names, function names, without altering functionality.
|
+ `refactor`: Used for code refactoring, such as changes to code structure, variable names, function names, without altering functionality.
|
||||||
+ perf: Used for performance optimization, such as improving code performance, reducing memory usage, etc.
|
+ `perf`: Used for performance optimization, such as improving code performance, reducing memory usage, etc.
|
||||||
+ test: Used for modifications to test cases, such as adding, deleting, or modifying test cases for code.
|
+ `test`: Used for modifications to test cases, such as adding, deleting, or modifying test cases for code.
|
||||||
+ chore: Used for modifications to non-business-related code, such as changes to build processes or tool configurations.
|
+ `chore`: Used for modifications to non-business-related code, such as changes to build processes or tool configurations.
|
||||||
+ After `<type>`, specify the affected package name or scope in parentheses, for example, `(os/gtime)`.
|
+ After `<type>`, specify the affected package name or scope in parentheses, for example, `(os/gtime)`.
|
||||||
+ The part after the colon uses the verb tense + phrase that completes the blank in
|
+ The part after the colon uses the verb tense + phrase that completes the blank in
|
||||||
+ Lowercase verb after the colon
|
+ Lowercase verb after the colon
|
||||||
|
|||||||
46
.github/workflows/ci-main.yml
vendored
46
.github/workflows/ci-main.yml
vendored
@ -29,7 +29,7 @@ concurrency:
|
|||||||
env:
|
env:
|
||||||
TZ: "Asia/Shanghai"
|
TZ: "Asia/Shanghai"
|
||||||
# for unit testing cases of some components that only execute on the latest go version.
|
# for unit testing cases of some components that only execute on the latest go version.
|
||||||
LATEST_GO_VERSION: "1.23"
|
LATEST_GO_VERSION: "1.25"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
code-test:
|
code-test:
|
||||||
@ -38,19 +38,18 @@ jobs:
|
|||||||
# 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
# 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
||||||
# When adding new go version to the list, make sure:
|
# When adding new go version to the list, make sure:
|
||||||
# 1. Update the `LATEST_GO_VERSION` env variable.
|
# 1. Update the `LATEST_GO_VERSION` env variable.
|
||||||
# 2. Update the `Report Coverage` action.
|
|
||||||
# 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
# 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
||||||
go-version: [ "1.20", "1.21", "1.22", "1.23" ]
|
go-version: [ "1.23", "1.24", "1.25" ]
|
||||||
goarch: [ "386", "amd64" ]
|
goarch: [ "386", "amd64" ]
|
||||||
|
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
# Service containers to run with `code-test`
|
# Service containers to run with `code-test`
|
||||||
services:
|
services:
|
||||||
# Etcd service.
|
# Etcd service.
|
||||||
# docker run -d --name etcd -p 2379:2379 -e ALLOW_NONE_AUTHENTICATION=yes bitnami/etcd:3.4.24
|
# docker run -d --name etcd -p 2379:2379 -e ALLOW_NONE_AUTHENTICATION=yes bitnamilegacy/etcd:3.4.24
|
||||||
etcd:
|
etcd:
|
||||||
image: bitnami/etcd:3.4.24
|
image: bitnamilegacy/etcd:3.4.24
|
||||||
env:
|
env:
|
||||||
ALLOW_NONE_AUTHENTICATION: yes
|
ALLOW_NONE_AUTHENTICATION: yes
|
||||||
ports:
|
ports:
|
||||||
@ -83,8 +82,13 @@ jobs:
|
|||||||
- 3306:3306
|
- 3306:3306
|
||||||
|
|
||||||
# MariaDb backend server.
|
# MariaDb backend server.
|
||||||
|
# docker run -d --name mariadb \
|
||||||
|
# -p 3307:3306 \
|
||||||
|
# -e MYSQL_DATABASE=test \
|
||||||
|
# -e MYSQL_ROOT_PASSWORD=12345678 \
|
||||||
|
# mariadb:11.4
|
||||||
mariadb:
|
mariadb:
|
||||||
image: mariadb:10.4
|
image: mariadb:11.4
|
||||||
env:
|
env:
|
||||||
MARIADB_DATABASE: test
|
MARIADB_DATABASE: test
|
||||||
MARIADB_ROOT_PASSWORD: 12345678
|
MARIADB_ROOT_PASSWORD: 12345678
|
||||||
@ -141,9 +145,9 @@ jobs:
|
|||||||
# ClickHouse backend server.
|
# ClickHouse backend server.
|
||||||
# docker run -d --name clickhouse \
|
# docker run -d --name clickhouse \
|
||||||
# -p 9000:9000 -p 8123:8123 -p 9001:9001 \
|
# -p 9000:9000 -p 8123:8123 -p 9001:9001 \
|
||||||
# loads/clickhouse-server:22.1.3.7
|
# clickhouse/clickhouse-server:24.11.1.2557-alpine
|
||||||
clickhouse-server:
|
clickhouse-server:
|
||||||
image: loads/clickhouse-server:22.1.3.7
|
image: clickhouse/clickhouse-server:24.11.1.2557-alpine
|
||||||
ports:
|
ports:
|
||||||
- 9000:9000
|
- 9000:9000
|
||||||
- 8123:8123
|
- 8123:8123
|
||||||
@ -152,13 +156,9 @@ jobs:
|
|||||||
# Polaris backend server.
|
# Polaris backend server.
|
||||||
# docker run -d --name polaris \
|
# docker run -d --name polaris \
|
||||||
# -p 8090:8090 -p 8091:8091 -p 8093:8093 -p 9090:9090 -p 9091:9091 \
|
# -p 8090:8090 -p 8091:8091 -p 8093:8093 -p 9090:9090 -p 9091:9091 \
|
||||||
# loads/polaris-server-standalone:1.11.2
|
# polarismesh/polaris-standalone:v1.17.2
|
||||||
#
|
|
||||||
# docker run -d --name polaris \
|
|
||||||
# -p 8090:8090 -p 8091:8091 -p 8093:8093 -p 9090:9090 -p 9091:9091 \
|
|
||||||
# loads/polaris-standalone:v1.16.3
|
|
||||||
polaris:
|
polaris:
|
||||||
image: loads/polaris-standalone:v1.17.2
|
image: polarismesh/polaris-standalone:v1.17.2
|
||||||
ports:
|
ports:
|
||||||
- 8090:8090
|
- 8090:8090
|
||||||
- 8091:8091
|
- 8091:8091
|
||||||
@ -205,7 +205,7 @@ jobs:
|
|||||||
timezoneLinux: "Asia/Shanghai"
|
timezoneLinux: "Asia/Shanghai"
|
||||||
|
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Start Apollo Containers
|
- name: Start Apollo Containers
|
||||||
run: docker compose -f ".github/workflows/apollo/docker-compose.yml" up -d --build
|
run: docker compose -f ".github/workflows/apollo/docker-compose.yml" up -d --build
|
||||||
@ -226,9 +226,9 @@ jobs:
|
|||||||
cache-dependency-path: '**/go.sum'
|
cache-dependency-path: '**/go.sum'
|
||||||
|
|
||||||
- name: Install Protoc
|
- name: Install Protoc
|
||||||
uses: arduino/setup-protoc@v2
|
uses: arduino/setup-protoc@v3
|
||||||
with:
|
with:
|
||||||
version: "29.x"
|
version: "31.x"
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Install the protocol compiler plugins for Go
|
- name: Install the protocol compiler plugins for Go
|
||||||
@ -238,15 +238,15 @@ jobs:
|
|||||||
export PATH="$PATH:$(go env GOPATH)/bin"
|
export PATH="$PATH:$(go env GOPATH)/bin"
|
||||||
|
|
||||||
- name: Before Script
|
- name: Before Script
|
||||||
run: bash .github/workflows/before_script.sh
|
run: bash .github/workflows/scripts/before_script.sh
|
||||||
|
|
||||||
- name: Build & Test
|
- name: Build & Test
|
||||||
if: ${{ (github.event_name == 'push' && github.ref != 'refs/heads/master') || github.event_name == 'pull_request' }}
|
if: ${{ (github.event_name == 'push' && github.ref != 'refs/heads/master') || github.event_name == 'pull_request' }}
|
||||||
run: bash .github/workflows/ci-main.sh
|
run: bash .github/workflows/scripts/ci-main.sh
|
||||||
|
|
||||||
- name: Build & Test & Coverage
|
- name: Build & Test & Coverage
|
||||||
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
||||||
run: bash .github/workflows/ci-main.sh coverage
|
run: bash .github/workflows/scripts/ci-main.sh coverage
|
||||||
|
|
||||||
- name: Stop Redis Cluster Containers
|
- name: Stop Redis Cluster Containers
|
||||||
run: docker compose -f ".github/workflows/redis/docker-compose.yml" down
|
run: docker compose -f ".github/workflows/redis/docker-compose.yml" down
|
||||||
@ -262,8 +262,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Report Coverage
|
- name: Report Coverage
|
||||||
uses: codecov/codecov-action@v4
|
uses: codecov/codecov-action@v4
|
||||||
# Only report coverage on the latest go version and amd64 arch
|
# Only report coverage on the latest go version
|
||||||
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.go-version == '1.23' && matrix.goarch == 'amd64' }}
|
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && matrix.go-version == env.LATEST_GO_VERSION }}
|
||||||
with:
|
with:
|
||||||
flags: go-${{ matrix.go-version }}-${{ matrix.goarch }}
|
flags: go-${{ matrix.go-version }}-${{ matrix.goarch }}
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|||||||
27
.github/workflows/ci-sub.sh
vendored
27
.github/workflows/ci-sub.sh
vendored
@ -1,27 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
coverage=$1
|
|
||||||
|
|
||||||
# find all path that contains go.mod.
|
|
||||||
for file in `find . -name go.mod`; do
|
|
||||||
dirpath=$(dirname $file)
|
|
||||||
echo $dirpath
|
|
||||||
|
|
||||||
# package kuhecm needs golang >= v1.19
|
|
||||||
if [ "kubecm" = $(basename $dirpath) ]; then
|
|
||||||
if ! go version|grep -qE "go1.[2-9][0-9]"; then
|
|
||||||
echo "ignore kubecm as go version: $(go version)"
|
|
||||||
continue 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
continue 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd $dirpath
|
|
||||||
|
|
||||||
go mod tidy
|
|
||||||
go build ./...
|
|
||||||
go test ./... -race || exit 1
|
|
||||||
|
|
||||||
cd -
|
|
||||||
done
|
|
||||||
10
.github/workflows/ci-sub.yml
vendored
10
.github/workflows/ci-sub.yml
vendored
@ -30,7 +30,7 @@ concurrency:
|
|||||||
env:
|
env:
|
||||||
TZ: "Asia/Shanghai"
|
TZ: "Asia/Shanghai"
|
||||||
# for unit testing cases of some components that only execute on the latest go version.
|
# for unit testing cases of some components that only execute on the latest go version.
|
||||||
LATEST_GO_VERSION: "1.23"
|
LATEST_GO_VERSION: "1.25"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
code-test:
|
code-test:
|
||||||
@ -40,7 +40,7 @@ jobs:
|
|||||||
# When adding new go version to the list, make sure:
|
# When adding new go version to the list, make sure:
|
||||||
# 1. Update the `LATEST_GO_VERSION` env variable.
|
# 1. Update the `LATEST_GO_VERSION` env variable.
|
||||||
# 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
# 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
|
||||||
go-version: [ "1.20", "1.21", "1.22", "1.23" ]
|
go-version: [ "1.23", "1.24", "1.25" ]
|
||||||
goarch: [ "386", "amd64" ]
|
goarch: [ "386", "amd64" ]
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -52,7 +52,7 @@ jobs:
|
|||||||
timezoneLinux: "Asia/Shanghai"
|
timezoneLinux: "Asia/Shanghai"
|
||||||
|
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Start Minikube
|
- name: Start Minikube
|
||||||
uses: medyagh/setup-minikube@master
|
uses: medyagh/setup-minikube@master
|
||||||
@ -64,9 +64,9 @@ jobs:
|
|||||||
cache-dependency-path: '**/go.sum'
|
cache-dependency-path: '**/go.sum'
|
||||||
|
|
||||||
- name: Before Script
|
- name: Before Script
|
||||||
run: bash .github/workflows/before_script.sh
|
run: bash .github/workflows/scripts/before_script.sh
|
||||||
|
|
||||||
- name: Build & Test
|
- name: Build & Test
|
||||||
run: bash .github/workflows/ci-sub.sh
|
run: bash .github/workflows/scripts/ci-sub.sh
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
100
.github/workflows/codeql.yml
vendored
Normal file
100
.github/workflows/codeql.yml
vendored
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL Advanced"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "master", "develop" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "master", "develop" ]
|
||||||
|
schedule:
|
||||||
|
- cron: '0 21 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze (${{ matrix.language }})
|
||||||
|
# Runner size impacts CodeQL analysis time. To learn more, please see:
|
||||||
|
# - https://gh.io/recommended-hardware-resources-for-running-codeql
|
||||||
|
# - https://gh.io/supported-runners-and-hardware-resources
|
||||||
|
# - https://gh.io/using-larger-runners (GitHub.com only)
|
||||||
|
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
|
||||||
|
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
|
||||||
|
permissions:
|
||||||
|
# required for all workflows
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
# required to fetch internal or private CodeQL packs
|
||||||
|
packages: read
|
||||||
|
|
||||||
|
# only required for workflows in private repositories
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- language: actions
|
||||||
|
build-mode: none
|
||||||
|
- language: go
|
||||||
|
build-mode: autobuild
|
||||||
|
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
|
||||||
|
# Use `c-cpp` to analyze code written in C, C++ or both
|
||||||
|
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
|
||||||
|
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
|
||||||
|
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
|
||||||
|
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
|
||||||
|
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
|
||||||
|
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# Add any setup steps before running the `github/codeql-action/init` action.
|
||||||
|
# This includes steps like installing compilers or runtimes (`actions/setup-node`
|
||||||
|
# or others). This is typically only required for manual builds.
|
||||||
|
# - name: Setup runtime (example)
|
||||||
|
# uses: actions/setup-example@v1
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v3
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
build-mode: ${{ matrix.build-mode }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
|
||||||
|
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||||
|
# queries: security-extended,security-and-quality
|
||||||
|
|
||||||
|
# If the analyze step fails for one of the languages you are analyzing with
|
||||||
|
# "We were unable to automatically build your code", modify the matrix above
|
||||||
|
# to set the build mode to "manual" for that language. Then modify this step
|
||||||
|
# to build your code.
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||||
|
- if: matrix.build-mode == 'manual'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo 'If you are using a "manual" build mode for one or more of the' \
|
||||||
|
'languages you are analyzing, replace this with the commands to build' \
|
||||||
|
'your code, for example:'
|
||||||
|
echo ' make bootstrap'
|
||||||
|
echo ' make release'
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v3
|
||||||
|
with:
|
||||||
|
category: "/language:${{matrix.language}}"
|
||||||
38
.github/workflows/doc-build.yml
vendored
38
.github/workflows/doc-build.yml
vendored
@ -1,38 +0,0 @@
|
|||||||
name: Deploy to GitHub Pages
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- 'doc-build'
|
|
||||||
schedule:
|
|
||||||
- cron: '0 15 * * *'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
deploy:
|
|
||||||
name: Deploy to GitHub Pages
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: doc-build
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
cache: npm
|
|
||||||
- name: Set Up Golang Environment
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: 1.23.4
|
|
||||||
cache: false
|
|
||||||
- name: download goframe docs
|
|
||||||
run: ./download.sh
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
- name: Build website
|
|
||||||
run: npm run build
|
|
||||||
- name: Deploy to GitHub Pages
|
|
||||||
uses: peaceiris/actions-gh-pages@v4
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
publish_dir: ./build
|
|
||||||
cname: pages.goframe.org
|
|
||||||
2
.github/workflows/format-code-on-push.yml
vendored
2
.github/workflows/format-code-on-push.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- name: Setup Golang ${{ matrix.go-version }}
|
- name: Setup Golang ${{ matrix.go-version }}
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
|
|||||||
2
.github/workflows/gitee-sync.yml
vendored
2
.github/workflows/gitee-sync.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout source code
|
- name: Checkout source code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
- name: Mirror GitHub to Gitee
|
- name: Mirror GitHub to Gitee
|
||||||
uses: Yikun/hub-mirror-action@v1.4
|
uses: Yikun/hub-mirror-action@v1.4
|
||||||
with:
|
with:
|
||||||
|
|||||||
14
.github/workflows/golangci-lint.yml
vendored
14
.github/workflows/golangci-lint.yml
vendored
@ -4,7 +4,7 @@
|
|||||||
# If a copy of the MIT was not distributed with this file,
|
# If a copy of the MIT was not distributed with this file,
|
||||||
# You can obtain one at https://github.com/gogf/gf.
|
# You can obtain one at https://github.com/gogf/gf.
|
||||||
|
|
||||||
name: GolangCI Lint
|
name: golangci-lint
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
@ -29,22 +29,24 @@ jobs:
|
|||||||
golang-ci:
|
golang-ci:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: [ 'stable' ]
|
go-version: [ "stable" ]
|
||||||
|
|
||||||
name: golang-ci-lint
|
name: golang-ci-lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
- name: Setup Golang ${{ matrix.go-version }}
|
- name: Setup Golang ${{ matrix.go-version }}
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go-version }}
|
go-version: ${{ matrix.go-version }}
|
||||||
- name: golang-ci-lint
|
- name: golang-ci-lint
|
||||||
uses: golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
# Required: specify the golangci-lint version without the patch version to always use the latest patch.
|
# Required: specify the golangci-lint version without the patch version to always use the latest patch.
|
||||||
version: v1.62.2
|
|
||||||
only-new-issues: true
|
only-new-issues: true
|
||||||
skip-cache: true
|
skip-cache: true
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
args: --timeout 3m0s --config=.golangci.yml -v
|
args: --config=.golangci.yml -v
|
||||||
|
|||||||
2
.github/workflows/issue-check-inactive.yml
vendored
2
.github/workflows/issue-check-inactive.yml
vendored
@ -23,6 +23,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
actions: 'check-inactive'
|
actions: 'check-inactive'
|
||||||
inactive-label: 'inactive'
|
inactive-label: 'inactive'
|
||||||
inactive-day: 7
|
inactive-day: 30
|
||||||
issue-state: open
|
issue-state: open
|
||||||
exclude-labels: 'bug,planned,$exclude-empty'
|
exclude-labels: 'bug,planned,$exclude-empty'
|
||||||
2
.github/workflows/nacos/docker-compose.yml
vendored
2
.github/workflows/nacos/docker-compose.yml
vendored
@ -17,7 +17,7 @@ services:
|
|||||||
retries: 10
|
retries: 10
|
||||||
|
|
||||||
initializer:
|
initializer:
|
||||||
image: loads/curl:latest
|
image: alpine/curl:latest
|
||||||
depends_on:
|
depends_on:
|
||||||
nacos:
|
nacos:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|||||||
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
@ -16,12 +16,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Github Code
|
- name: Checkout Github Code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set Up Golang Environment
|
- name: Set Up Golang Environment
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.23.4
|
go-version: 1.25
|
||||||
|
|
||||||
- name: Build CLI Binary
|
- name: Build CLI Binary
|
||||||
run: |
|
run: |
|
||||||
@ -52,7 +52,7 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ github.ref }}
|
tag_name: ${{ github.ref }}
|
||||||
name: GoFrame Release ${{ github.ref }}
|
name: GoFrame Release ${{ github.ref_name }}
|
||||||
draft: false
|
draft: false
|
||||||
prerelease: false
|
prerelease: false
|
||||||
|
|
||||||
|
|||||||
80
.github/workflows/scorecard.yml
vendored
Normal file
80
.github/workflows/scorecard.yml
vendored
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# This workflow uses actions that are not certified by GitHub. They are provided
|
||||||
|
# by a third-party and are governed by separate terms of service, privacy
|
||||||
|
# policy, and support documentation.
|
||||||
|
|
||||||
|
name: Scorecard supply-chain security
|
||||||
|
on:
|
||||||
|
# For Branch-Protection check. Only the default branch is supported. See
|
||||||
|
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
|
||||||
|
branch_protection_rule:
|
||||||
|
# To guarantee Maintained check is occasionally updated. See
|
||||||
|
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
|
||||||
|
schedule:
|
||||||
|
- cron: '0 21 * * *'
|
||||||
|
push:
|
||||||
|
branches: [ "master" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "master" ]
|
||||||
|
|
||||||
|
# Declare default permissions as read only.
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analysis:
|
||||||
|
name: Scorecard analysis
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# `publish_results: true` only works when run from the default branch. conditional can be removed if disabled.
|
||||||
|
if: github.event.repository.default_branch == github.ref_name || github.event_name == 'pull_request'
|
||||||
|
permissions:
|
||||||
|
# Needed to upload the results to code-scanning dashboard.
|
||||||
|
security-events: write
|
||||||
|
# Needed to publish results and get a badge (see publish_results below).
|
||||||
|
id-token: write
|
||||||
|
# Uncomment the permissions below if installing in a private repository.
|
||||||
|
# contents: read
|
||||||
|
# actions: read
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout code"
|
||||||
|
uses: actions/checkout@v4.2.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: "Run analysis"
|
||||||
|
uses: ossf/scorecard-action@v2.4.1
|
||||||
|
with:
|
||||||
|
results_file: results.sarif
|
||||||
|
results_format: sarif
|
||||||
|
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
|
||||||
|
# - you want to enable the Branch-Protection check on a *public* repository, or
|
||||||
|
# - you are installing Scorecard on a *private* repository
|
||||||
|
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action?tab=readme-ov-file#authentication-with-fine-grained-pat-optional.
|
||||||
|
# repo_token: ${{ secrets.SCORECARD_TOKEN }}
|
||||||
|
|
||||||
|
# Public repositories:
|
||||||
|
# - Publish results to OpenSSF REST API for easy access by consumers
|
||||||
|
# - Allows the repository to include the Scorecard badge.
|
||||||
|
# - See https://github.com/ossf/scorecard-action#publishing-results.
|
||||||
|
# For private repositories:
|
||||||
|
# - `publish_results` will always be set to `false`, regardless
|
||||||
|
# of the value entered here.
|
||||||
|
publish_results: true
|
||||||
|
|
||||||
|
# (Optional) Uncomment file_mode if you have a .gitattributes with files marked export-ignore
|
||||||
|
# file_mode: git
|
||||||
|
|
||||||
|
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||||
|
# format to the repository Actions tab.
|
||||||
|
- name: "Upload artifact"
|
||||||
|
uses: actions/upload-artifact@v4.6.1
|
||||||
|
with:
|
||||||
|
name: SARIF file
|
||||||
|
path: results.sarif
|
||||||
|
retention-days: 5
|
||||||
|
|
||||||
|
# Upload the results to GitHub's code scanning dashboard (optional).
|
||||||
|
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
|
||||||
|
- name: "Upload to code-scanning"
|
||||||
|
uses: github/codeql-action/upload-sarif@v3
|
||||||
|
with:
|
||||||
|
sarif_file: results.sarif
|
||||||
@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
coverage=$1
|
coverage=$1
|
||||||
|
|
||||||
|
# update code of submodules
|
||||||
|
git clone https://github.com/gogf/examples
|
||||||
|
|
||||||
|
# update go.mod in examples directory to replace github.com/gogf/gf packages with local directory
|
||||||
|
bash .github/workflows/scripts/replace_examples_gomod.sh
|
||||||
|
|
||||||
# find all path that contains go.mod.
|
# find all path that contains go.mod.
|
||||||
for file in `find . -name go.mod`; do
|
for file in `find . -name go.mod`; do
|
||||||
dirpath=$(dirname $file)
|
dirpath=$(dirname $file)
|
||||||
@ -13,21 +19,21 @@ for file in `find . -name go.mod`; do
|
|||||||
continue 1
|
continue 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# package kuhecm was moved to sub ci procedure.
|
# package kubecm was moved to sub ci procedure.
|
||||||
if [ "kubecm" = $(basename $dirpath) ]; then
|
if [ "kubecm" = $(basename $dirpath) ]; then
|
||||||
continue 1
|
continue 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if it's a contrib directory or example directory
|
# Check if it's a contrib directory or examples directory
|
||||||
if [[ $dirpath =~ "/contrib/" ]] || [ "example" = $(basename $dirpath) ]; then
|
if [[ $dirpath =~ "/contrib/" ]] || [[ $dirpath =~ "/examples/" ]]; then
|
||||||
# Check if go version meets the requirement
|
# Check if go version meets the requirement
|
||||||
if ! go version | grep -qE "go${LATEST_GO_VERSION}"; then
|
if ! go version | grep -qE "go${LATEST_GO_VERSION}"; then
|
||||||
echo "ignore path $dirpath as go version is not ${LATEST_GO_VERSION}: $(go version)"
|
echo "ignore path $dirpath as go version is not ${LATEST_GO_VERSION}: $(go version)"
|
||||||
continue 1
|
continue 1
|
||||||
fi
|
fi
|
||||||
# If it's example directory, only build without tests
|
# If it's examples directory, only build without tests
|
||||||
if [ "example" = $(basename $dirpath) ]; then
|
if [[ $dirpath =~ "/examples/" ]]; then
|
||||||
echo "the example directory only needs to be built, not unit tests and coverage tests."
|
echo "the examples directory only needs to be built, not unit tests and coverage tests."
|
||||||
cd $dirpath
|
cd $dirpath
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go build ./...
|
go build ./...
|
||||||
68
.github/workflows/scripts/ci-sub.sh
vendored
Normal file
68
.github/workflows/scripts/ci-sub.sh
vendored
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
coverage=$1
|
||||||
|
|
||||||
|
# Function to compare version numbers
|
||||||
|
version_compare() {
|
||||||
|
local ver1=$1
|
||||||
|
local ver2=$2
|
||||||
|
|
||||||
|
# Remove 'go' prefix and 'v' if present
|
||||||
|
ver1=$(echo "$ver1" | sed 's/^go//; s/^v//')
|
||||||
|
ver2=$(echo "$ver2" | sed 's/^go//; s/^v//')
|
||||||
|
|
||||||
|
# Split versions into major.minor format
|
||||||
|
local major1=$(echo "$ver1" | cut -d. -f1)
|
||||||
|
local minor1=$(echo "$ver1" | cut -d. -f2)
|
||||||
|
local major2=$(echo "$ver2" | cut -d. -f1)
|
||||||
|
local minor2=$(echo "$ver2" | cut -d. -f2)
|
||||||
|
|
||||||
|
# Compare versions: return 0 if ver1 <= ver2, 1 otherwise
|
||||||
|
if [ "$major1" -lt "$major2" ]; then
|
||||||
|
return 0
|
||||||
|
elif [ "$major1" -eq "$major2" ] && [ "$minor1" -le "$minor2" ]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get current Go version
|
||||||
|
current_go_version=$(go version | grep -oE 'go[0-9]+\.[0-9]+')
|
||||||
|
|
||||||
|
# find all path that contains go.mod.
|
||||||
|
for file in `find . -name go.mod`; do
|
||||||
|
dirpath=$(dirname $file)
|
||||||
|
echo "Processing: $dirpath"
|
||||||
|
|
||||||
|
# Only process kubecm directory, skip others
|
||||||
|
if [ "kubecm" != $(basename $dirpath) ]; then
|
||||||
|
echo " Skipping: not kubecm directory"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $dirpath
|
||||||
|
|
||||||
|
# Read Go version requirement from go.mod
|
||||||
|
if [ -f "go.mod" ]; then
|
||||||
|
go_mod_version=$(grep '^go ' go.mod | awk '{print $2}' | head -1)
|
||||||
|
|
||||||
|
if [ -n "$go_mod_version" ]; then
|
||||||
|
echo " go.mod requires: go$go_mod_version"
|
||||||
|
echo " current version: $current_go_version"
|
||||||
|
|
||||||
|
# Check if go.mod version requirement is satisfied by current Go version
|
||||||
|
if version_compare "$go_mod_version" "$current_go_version"; then
|
||||||
|
echo " ✓ Version requirement satisfied, proceeding with build and test"
|
||||||
|
|
||||||
|
go mod tidy
|
||||||
|
go build ./...
|
||||||
|
go test ./... -race || exit 1
|
||||||
|
else
|
||||||
|
echo " ✗ Current Go version ($current_go_version) does not meet requirement (go$go_mod_version), skipping"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd -
|
||||||
|
done
|
||||||
81
.github/workflows/scripts/replace_examples_gomod.sh
vendored
Executable file
81
.github/workflows/scripts/replace_examples_gomod.sh
vendored
Executable file
@ -0,0 +1,81 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Get the absolute path to the repository root
|
||||||
|
repo_root=$(pwd)
|
||||||
|
workdir=$repo_root/examples
|
||||||
|
|
||||||
|
echo "Prepare to process go.mod files in the ${workdir} directory"
|
||||||
|
|
||||||
|
# Check if examples directory exists
|
||||||
|
if [ ! -d "${workdir}" ]; then
|
||||||
|
echo "Error: examples directory not found at ${workdir}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if find command is available
|
||||||
|
if ! command -v find &> /dev/null; then
|
||||||
|
echo "Error: find command not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for file in `find ${workdir} -name go.mod`; do
|
||||||
|
goModPath=$(dirname $file)
|
||||||
|
echo ""
|
||||||
|
echo "Processing dir: $goModPath"
|
||||||
|
|
||||||
|
# Calculate relative path to root
|
||||||
|
# First get the relative path from go.mod to repo root
|
||||||
|
relativePath=""
|
||||||
|
current="$goModPath"
|
||||||
|
while [ "$current" != "$repo_root" ]; do
|
||||||
|
relativePath="../$relativePath"
|
||||||
|
current=$(dirname "$current")
|
||||||
|
done
|
||||||
|
relativePath=${relativePath%/} # Remove trailing slash
|
||||||
|
echo "Relative path to root: $relativePath"
|
||||||
|
|
||||||
|
# Get all github.com/gogf/gf dependencies
|
||||||
|
# Use awk to get package names without version numbers
|
||||||
|
dependencies=$(awk '/^[[:space:]]*github\.com\/gogf\/gf\// {print $1}' "$file" | sort -u)
|
||||||
|
|
||||||
|
if [ -n "$dependencies" ]; then
|
||||||
|
echo "Found GoFrame dependencies:"
|
||||||
|
echo "$dependencies"
|
||||||
|
echo "Adding replace directives..."
|
||||||
|
|
||||||
|
# Create temporary file
|
||||||
|
temp_file="${file}.tmp"
|
||||||
|
# Remove existing replace directives and copy to temp file
|
||||||
|
sed '/^replace.*github\.com\/gogf\/gf.*/d' "$file" > "$temp_file"
|
||||||
|
|
||||||
|
# Add new replace block
|
||||||
|
echo "" >> "$temp_file"
|
||||||
|
echo "replace (" >> "$temp_file"
|
||||||
|
|
||||||
|
while IFS= read -r dep; do
|
||||||
|
# Skip empty lines
|
||||||
|
[ -z "$dep" ] && continue
|
||||||
|
|
||||||
|
# Calculate the relative path for the replacement
|
||||||
|
if [[ "$dep" == "github.com/gogf/gf/v2" ]]; then
|
||||||
|
replacement="$relativePath"
|
||||||
|
else
|
||||||
|
# Extract the path after v2 and remove trailing version
|
||||||
|
subpath=$(echo "$dep" | sed -E 's/github\.com\/gogf\/gf\/(contrib\/[^/]+\/[^/]+)\/v2.*/\1/')
|
||||||
|
replacement="$relativePath/$subpath"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo " $dep => $replacement/" >> "$temp_file"
|
||||||
|
done <<< "$dependencies"
|
||||||
|
|
||||||
|
echo ")" >> "$temp_file"
|
||||||
|
|
||||||
|
# Replace original file with temporary file
|
||||||
|
mv "$temp_file" "$file"
|
||||||
|
echo "Replace directives added to $file"
|
||||||
|
else
|
||||||
|
echo "No GoFrame dependencies found in $file"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "\nAll go.mod files have been processed successfully."
|
||||||
50
.github/workflows/scripts/update_version.sh
vendored
Executable file
50
.github/workflows/scripts/update_version.sh
vendored
Executable file
@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Check if the number of parameters is 2
|
||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
echo "Invalid parameters, please execute in format: version.sh [directory] [version]"
|
||||||
|
echo "Example: version.sh ./contrib v1.0.0"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the first parameter is a directory and exists
|
||||||
|
if [ ! -d "$1" ]; then
|
||||||
|
echo "Error: Directory does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the second parameter starts with 'v'
|
||||||
|
if [[ "$2" != v* ]]; then
|
||||||
|
echo "Error: Version number does not start with 'v'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
workdir=$1
|
||||||
|
newVersion=$2
|
||||||
|
echo "Preparing to replace version numbers in all go.mod files under ${workdir} directory to ${newVersion}"
|
||||||
|
|
||||||
|
|
||||||
|
# Check if file exists
|
||||||
|
if [ -f "go.work" ]; then
|
||||||
|
# File exists, rename it
|
||||||
|
mv go.work go.work.${newVersion}
|
||||||
|
echo "Backup go.work file to avoid affecting the upgrade"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for file in `find ${workdir} -name go.mod`; do
|
||||||
|
goModPath=$(dirname $file)
|
||||||
|
echo ""
|
||||||
|
echo "processing dir: $goModPath"
|
||||||
|
cd $goModPath
|
||||||
|
go mod tidy
|
||||||
|
go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf"
|
||||||
|
go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf" | xargs -L1 go get -v
|
||||||
|
go mod tidy
|
||||||
|
cd -
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -f "go.work.${newVersion}" ]; then
|
||||||
|
# File exists, rename it back
|
||||||
|
mv go.work.${newVersion} go.work
|
||||||
|
echo "Restore go.work file"
|
||||||
|
fi
|
||||||
53
.github/workflows/sonarcloud.yaml
vendored
53
.github/workflows/sonarcloud.yaml
vendored
@ -1,53 +0,0 @@
|
|||||||
name: Sonarcloud Scan
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
# Weekly on Saturdays.
|
|
||||||
- cron: '30 1 * * 6'
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
# Declare default permissions as read only.
|
|
||||||
permissions: read
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
analysis:
|
|
||||||
name: Scorecards analysis
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
permissions:
|
|
||||||
# Needed to upload the results to code-scanning dashboard.
|
|
||||||
security-events: write
|
|
||||||
# Used to receive a badge. (Upcoming feature)
|
|
||||||
id-token: write
|
|
||||||
# Needs for private repositories.
|
|
||||||
contents: read
|
|
||||||
actions: read
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: "Checkout code"
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: "Run analysis"
|
|
||||||
uses: ossf/scorecard-action@v2.4.0 # v2.4.0
|
|
||||||
with:
|
|
||||||
results_file: results.sarif
|
|
||||||
results_format: sarif
|
|
||||||
publish_results: true
|
|
||||||
|
|
||||||
- name: "Upload artifact"
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: SARIF file
|
|
||||||
path: results.sarif
|
|
||||||
retention-days: 5
|
|
||||||
|
|
||||||
- name: "Upload to code-scanning"
|
|
||||||
uses: github/codeql-action/upload-sarif@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # v2.2.1
|
|
||||||
with:
|
|
||||||
sarif_file: results.sarif
|
|
||||||
38
.github/workflows/tag.yml
vendored
38
.github/workflows/tag.yml
vendored
@ -4,36 +4,56 @@ on:
|
|||||||
push:
|
push:
|
||||||
# Sequence of patterns matched against refs/tags
|
# Sequence of patterns matched against refs/tags
|
||||||
tags:
|
tags:
|
||||||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
||||||
|
|
||||||
env:
|
env:
|
||||||
TZ: Asia/Shanghai
|
TZ: Asia/Shanghai
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Auto Creating Tags
|
name: Auto Creating Tags
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Github Code
|
- name: Checkout Github Code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Auto Creating Tags For Contrib Packages
|
- name: Auto Creating Tags For Contrib Packages
|
||||||
run: |
|
run: |
|
||||||
git config --global user.email "tagrobot@goframe.org"
|
git config --global user.email "tagrobot@goframe.org"
|
||||||
git config --global user.name "TagRobot"
|
git config --global user.name "TagRobot"
|
||||||
|
|
||||||
# auto create tags for contrib packages.
|
# auto create tags for contrib packages.
|
||||||
for file in `find contrib -name go.mod`; do
|
for file in `find contrib -name go.mod`; do
|
||||||
tag=$(dirname $file)/$GITHUB_REF_NAME
|
tag=$(dirname $file)/${{ github.ref_name }}
|
||||||
git tag $tag
|
git tag $tag
|
||||||
git push origin $tag
|
git push origin $tag
|
||||||
done
|
done
|
||||||
|
- name: update dependencies
|
||||||
|
run: |
|
||||||
|
go env -w GOPRIVATE=github.com/gogf/gf
|
||||||
|
.github/workflows/scripts/update_version.sh ./cmd/gf ${{ github.ref_name }}
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: peter-evans/create-pull-request@v4
|
||||||
|
with:
|
||||||
|
commit-message: 'update gf cli to ${{ github.ref_name }}'
|
||||||
|
title: 'fix: update gf cli to ${{ github.ref_name }}'
|
||||||
|
base: master
|
||||||
|
branch: fix/${{ github.ref_name }}
|
||||||
|
delete-branch: true
|
||||||
|
- name: Commit & Push changes
|
||||||
|
uses: actions-js/push@master
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
branch: fix/${{ github.ref_name }}
|
||||||
|
author_name: TagRobot
|
||||||
|
author_email: tagrobot@goframe.org
|
||||||
|
message: 'fix: update gf cli to ${{ github.ref_name }}'
|
||||||
|
- name: Auto Creating Tags For cli tool
|
||||||
|
run: |
|
||||||
|
git config --global user.email "tagrobot@goframe.org"
|
||||||
|
git config --global user.name "TagRobot"
|
||||||
# auto create tag for cli tool
|
# auto create tag for cli tool
|
||||||
for file in `find cmd -name go.mod`; do
|
for file in `find cmd -name go.mod -not -path "*/testdata/*"`; do
|
||||||
tag=$(dirname $file)/$GITHUB_REF_NAME
|
tag=$(dirname $file)/${{ github.ref_name }}
|
||||||
git tag $tag
|
git tag $tag
|
||||||
git push origin $tag
|
git push origin $tag
|
||||||
done
|
done
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,7 +7,6 @@
|
|||||||
.settings/
|
.settings/
|
||||||
.vscode/
|
.vscode/
|
||||||
vendor/
|
vendor/
|
||||||
pkg/
|
|
||||||
bin/
|
bin/
|
||||||
**/.DS_Store
|
**/.DS_Store
|
||||||
.test/
|
.test/
|
||||||
@ -24,3 +23,5 @@ go.work.sum
|
|||||||
node_modules
|
node_modules
|
||||||
.docusaurus
|
.docusaurus
|
||||||
output
|
output
|
||||||
|
.example/
|
||||||
|
.golangci.bck.yml
|
||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "examples"]
|
||||||
|
path = examples
|
||||||
|
url = git@github.com:gogf/examples.git
|
||||||
535
.golangci.yml
535
.golangci.yml
@ -1,325 +1,220 @@
|
|||||||
## This file contains all available configuration options
|
version: "2"
|
||||||
## with their default values.
|
|
||||||
|
|
||||||
# See https://github.com/golangci/golangci-lint#config-file
|
|
||||||
# See https://golangci-lint.run/usage/configuration/
|
|
||||||
|
|
||||||
# Options for analysis running.
|
|
||||||
run:
|
run:
|
||||||
# Timeout for analysis, e.g. 30s, 5m.
|
|
||||||
# Default: 1m
|
|
||||||
timeout: 5m
|
|
||||||
# Exit code when at least one issue was found.
|
|
||||||
# Default: 1
|
|
||||||
issues-exit-code: 2
|
|
||||||
# Include test files or not.
|
|
||||||
# Default: true
|
|
||||||
tests: false
|
|
||||||
# List of build tags, all linters use it.
|
|
||||||
# Default: []
|
|
||||||
build-tags: []
|
|
||||||
# If set, we pass it to "go list -mod={option}". From "go help modules":
|
|
||||||
# If invoked with -mod=readonly, the go command is disallowed from the implicit
|
|
||||||
# automatic updating of go.mod described above. Instead, it fails when any changes
|
|
||||||
# to go.mod are needed. This setting is most useful to check that go.mod does
|
|
||||||
# not need updates, such as in a continuous integration and testing system.
|
|
||||||
# If invoked with -mod=vendor, the go command assumes that the vendor
|
|
||||||
# directory holds the correct copies of dependencies and ignores
|
|
||||||
# the dependency descriptions in go.mod.
|
|
||||||
#
|
|
||||||
# Allowed values: readonly|vendor|mod
|
|
||||||
# Default: ""
|
|
||||||
modules-download-mode: readonly
|
|
||||||
# Allow multiple parallel golangci-lint instances running.
|
|
||||||
# If false, golangci-lint acquires file lock on start.
|
|
||||||
# Default: false
|
|
||||||
allow-parallel-runners: true
|
|
||||||
# Allow multiple golangci-lint instances running, but serialize them around a lock.
|
|
||||||
# If false, golangci-lint exits with an error if it fails to acquire file lock on start.
|
|
||||||
# Default: false
|
|
||||||
allow-serial-runners: true
|
|
||||||
# Define the Go version limit.
|
|
||||||
# Mainly related to generics support since go1.18.
|
|
||||||
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.17
|
|
||||||
go: '1.20'
|
|
||||||
# Number of operating system threads (`GOMAXPROCS`) that can execute golangci-lint simultaneously.
|
|
||||||
# If it is explicitly set to 0 (i.e. not the default) then golangci-lint will automatically set the value to match Linux container CPU quota.
|
|
||||||
# Default: the number of logical CPUs in the machine
|
|
||||||
concurrency: 4
|
concurrency: 4
|
||||||
|
go: "1.25"
|
||||||
|
modules-download-mode: readonly
|
||||||
# Main linters configurations.
|
issues-exit-code: 2
|
||||||
# See https://golangci-lint.run/usage/linters
|
tests: false
|
||||||
|
allow-parallel-runners: true
|
||||||
|
allow-serial-runners: true
|
||||||
linters:
|
linters:
|
||||||
# Disable all default enabled linters.
|
default: none
|
||||||
disable-all: true
|
|
||||||
# Custom enable linters we want to use.
|
|
||||||
enable:
|
enable:
|
||||||
- errcheck # Errcheck is a program for checking for unchecked errors in go programs.
|
- errcheck
|
||||||
- errchkjson # Checks types passed to the JSON encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
|
- errchkjson
|
||||||
- funlen # Tool for detection of long functions
|
- funlen
|
||||||
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
|
- goconst
|
||||||
- goimports # Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode.
|
- gocritic
|
||||||
- gci # Gci controls Go package import order and makes it always deterministic.
|
- govet
|
||||||
- goconst # Finds repeated strings that could be replaced by a constant
|
- misspell
|
||||||
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
|
- nolintlint
|
||||||
- gosimple # Linter for Go source code that specializes in simplifying code
|
- revive
|
||||||
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
|
- staticcheck
|
||||||
- misspell # Finds commonly misspelled English words in comments
|
- usestdlibvars
|
||||||
- nolintlint # Reports ill-formed or insufficient nolint directives
|
- whitespace
|
||||||
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
|
settings:
|
||||||
- staticcheck # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
|
funlen:
|
||||||
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
|
lines: 340
|
||||||
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library.
|
statements: -1
|
||||||
- whitespace # Tool for detection of leading and trailing whitespace
|
goconst:
|
||||||
|
match-constant: false
|
||||||
|
min-len: 4
|
||||||
issues:
|
min-occurrences: 30
|
||||||
exclude-rules:
|
numbers: true
|
||||||
# helpers in tests often (rightfully) pass a *testing.T as their first argument
|
min: 5
|
||||||
- path: _test\.go
|
max: 20
|
||||||
text: "context.Context should be the first parameter of a function"
|
ignore-calls: false
|
||||||
linters:
|
gocritic:
|
||||||
- revive
|
disabled-checks:
|
||||||
# Yes, they are, but it's okay in a test
|
- ifElseChain
|
||||||
- path: _test\.go
|
- assignOp
|
||||||
text: "exported func.*returns unexported type.*which can be annoying to use"
|
- appendAssign
|
||||||
linters:
|
- singleCaseSwitch
|
||||||
- revive
|
- regexpMust
|
||||||
# https://github.com/go-critic/go-critic/issues/926
|
- typeSwitchVar
|
||||||
- linters:
|
- elseif
|
||||||
- gocritic
|
govet:
|
||||||
text: "unnecessaryDefer:"
|
disable:
|
||||||
|
- asmdecl
|
||||||
|
- assign
|
||||||
# https://golangci-lint.run/usage/linters
|
- atomic
|
||||||
linters-settings:
|
- atomicalign
|
||||||
# https://golangci-lint.run/usage/linters/#misspell
|
- bools
|
||||||
misspell:
|
- buildtag
|
||||||
locale: US
|
- cgocall
|
||||||
ignore-words:
|
- composites
|
||||||
- cancelled
|
- copylocks
|
||||||
# https://golangci-lint.run/usage/linters/#gofmt
|
- deepequalerrors
|
||||||
gofmt:
|
- errorsas
|
||||||
# Simplify code: gofmt with `-s` option.
|
- fieldalignment
|
||||||
# Default: true
|
- findcall
|
||||||
simplify: true
|
- framepointer
|
||||||
# Apply the rewrite rules to the source before reformatting.
|
- httpresponse
|
||||||
# https://pkg.go.dev/cmd/gofmt
|
- ifaceassert
|
||||||
# Default: []
|
- loopclosure
|
||||||
rewrite-rules: [ ]
|
- lostcancel
|
||||||
# - pattern: 'interface{}'
|
- nilfunc
|
||||||
# replacement: 'any'
|
- nilness
|
||||||
# - pattern: 'a[b:len(a)]'
|
- reflectvaluecompare
|
||||||
# replacement: 'a[b:]'
|
- shift
|
||||||
goimports:
|
- shadow
|
||||||
# A comma-separated list of prefixes, which, if set, checks import paths
|
- sigchanyzer
|
||||||
# with the given prefixes are grouped after 3rd-party packages.
|
- sortslice
|
||||||
# Default: ""
|
- stdmethods
|
||||||
local-prefixes: github.com/gogf/gf/v2
|
- stringintconv
|
||||||
gci:
|
- structtag
|
||||||
# Section configuration to compare against.
|
- testinggoroutine
|
||||||
# Section names are case-insensitive and may contain parameters in ().
|
- tests
|
||||||
# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,
|
- unmarshal
|
||||||
# If `custom-order` is `true`, it follows the order of `sections` option.
|
- unreachable
|
||||||
# Default: ["standard", "default"]
|
- unsafeptr
|
||||||
sections:
|
- unusedwrite
|
||||||
- standard # Standard section: captures all standard packages.
|
enable-all: true
|
||||||
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
|
settings:
|
||||||
- default # Default section: contains all imports that could not be matched to another section type.
|
printf:
|
||||||
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
|
funcs:
|
||||||
# - alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
|
||||||
# - localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
|
||||||
- prefix(github.com/gogf/gf) # Custom section: groups all imports with the specified Prefix.
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
|
||||||
- prefix(github.com/gogf/gf/cmd) # Custom section: groups all imports with the specified Prefix.
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
|
||||||
- prefix(github.com/gogf/gfcontrib) # Custom section: groups all imports with the specified Prefix.
|
unusedresult:
|
||||||
- prefix(github.com/gogf/gf/example) # Custom section: groups all imports with the specified Prefix.
|
funcs:
|
||||||
# Skip generated files.
|
- pkg.MyFunc
|
||||||
# Default: true
|
- context.WithCancel
|
||||||
skip-generated: true
|
stringmethods:
|
||||||
# Enable custom order of sections.
|
- MyMethod
|
||||||
# If `true`, make the section order the same as the order of `sections`.
|
misspell:
|
||||||
# Default: false
|
locale: US
|
||||||
custom-order: true
|
ignore-rules:
|
||||||
# Drops lexical ordering for custom sections.
|
- cancelled
|
||||||
# Default: false
|
revive:
|
||||||
no-lex-order: false
|
severity: error
|
||||||
# https://golangci-lint.run/usage/linters/#revive
|
rules:
|
||||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
|
- name: atomic
|
||||||
revive:
|
- name: line-length-limit
|
||||||
ignore-generated-header: true
|
arguments:
|
||||||
severity: error
|
- 380
|
||||||
|
severity: error
|
||||||
|
- name: unhandled-error
|
||||||
|
severity: warning
|
||||||
|
disabled: true
|
||||||
|
- name: var-naming
|
||||||
|
arguments:
|
||||||
|
- - ID
|
||||||
|
- URL
|
||||||
|
- IP
|
||||||
|
- HTTP
|
||||||
|
- JSON
|
||||||
|
- API
|
||||||
|
- UID
|
||||||
|
- Id
|
||||||
|
- Api
|
||||||
|
- Uid
|
||||||
|
- Http
|
||||||
|
- Json
|
||||||
|
- Ip
|
||||||
|
- Url
|
||||||
|
- - VM
|
||||||
|
severity: warning
|
||||||
|
disabled: true
|
||||||
|
- name: string-format
|
||||||
|
arguments:
|
||||||
|
- - core.WriteError[1].Message
|
||||||
|
- /^([^A-Z]|$)/
|
||||||
|
- must not start with a capital letter
|
||||||
|
- - fmt.Errorf[0]
|
||||||
|
- /(^|[^\.!?])$/
|
||||||
|
- must not end in punctuation
|
||||||
|
- - panic
|
||||||
|
- /^[^\n]*$/
|
||||||
|
- must not contain line breaks
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
- name: function-result-limit
|
||||||
|
arguments:
|
||||||
|
- 4
|
||||||
|
severity: warning
|
||||||
|
disabled: false
|
||||||
|
staticcheck:
|
||||||
|
checks: [ "all","-S1000","-S1009","-S1016","-S1023","-S1025","-S1029","-S1034","-S1040","-SA1016","-SA1019","-SA1029","-SA4006","-SA4015","-SA6003","-SA9003","-ST1003","-QF1001","-QF1002","-QF1003","-QF1006","-QF1007","-QF1008","-QF1011","-QF1012","-ST1011" ]
|
||||||
|
initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS" ]
|
||||||
|
dot-import-whitelist: [ "fmt" ]
|
||||||
|
http-status-code-whitelist: [ "200", "400", "404", "500" ]
|
||||||
|
exclusions:
|
||||||
|
generated: lax
|
||||||
|
presets:
|
||||||
|
- comments
|
||||||
|
- common-false-positives
|
||||||
|
- legacy
|
||||||
|
- std-error-handling
|
||||||
rules:
|
rules:
|
||||||
- name: atomic
|
- linters:
|
||||||
- name: line-length-limit
|
- revive
|
||||||
severity: error
|
path: _test\.go
|
||||||
arguments: [ 380 ]
|
text: context.Context should be the first parameter of a function
|
||||||
- name: unhandled-error
|
- linters:
|
||||||
severity: warning
|
- revive
|
||||||
disabled: true
|
path: _test\.go
|
||||||
arguments: []
|
text: exported func.*returns unexported type.*which can be annoying to use
|
||||||
- name: var-naming
|
- linters:
|
||||||
severity: warning
|
- gocritic
|
||||||
disabled: true
|
text: 'unnecessaryDefer:'
|
||||||
arguments:
|
- linters:
|
||||||
# AllowList
|
- goconst
|
||||||
- [ "ID","URL","IP","HTTP","JSON","API","UID","Id","Api","Uid","Http","Json","Ip","Url" ]
|
path: (.+)_test\.go
|
||||||
# DenyList
|
paths:
|
||||||
- [ "VM" ]
|
- third_party$
|
||||||
- name: string-format
|
- builtin$
|
||||||
severity: warning
|
- examples$
|
||||||
disabled: false
|
formatters:
|
||||||
arguments:
|
enable:
|
||||||
- - 'core.WriteError[1].Message'
|
- gci
|
||||||
- '/^([^A-Z]|$)/'
|
- gofmt
|
||||||
- must not start with a capital letter
|
- goimports
|
||||||
- - 'fmt.Errorf[0]'
|
settings:
|
||||||
- '/(^|[^\.!?])$/'
|
gci:
|
||||||
- must not end in punctuation
|
sections:
|
||||||
- - panic
|
- standard
|
||||||
- '/^[^\n]*$/'
|
- blank
|
||||||
- must not contain line breaks
|
- default
|
||||||
- name: function-result-limit
|
- dot
|
||||||
severity: warning
|
- prefix(github.com/gogf/gf/v2)
|
||||||
disabled: false
|
- prefix(github.com/gogf/gf/cmd)
|
||||||
arguments: [ 4 ]
|
- prefix(github.com/gogf/gfcontrib)
|
||||||
|
- prefix(github.com/gogf/gf/example)
|
||||||
# https://golangci-lint.run/usage/linters/#funlen
|
custom-order: true
|
||||||
funlen:
|
no-lex-order: false
|
||||||
# Checks the number of lines in a function.
|
gofmt:
|
||||||
# If lower than 0, disable the check.
|
simplify: true
|
||||||
# Default: 60
|
rewrite-rules:
|
||||||
lines: 340
|
- pattern: 'interface{}'
|
||||||
# Checks the number of statements in a function.
|
replacement: 'any'
|
||||||
# If lower than 0, disable the check.
|
- pattern: 'reflect.Ptr'
|
||||||
# Default: 40
|
replacement: 'reflect.Pointer'
|
||||||
statements: -1
|
- pattern: 'ioutil.ReadAll'
|
||||||
|
replacement: 'io.ReadAll'
|
||||||
# https://golangci-lint.run/usage/linters/#goconst
|
- pattern: 'ioutil.WriteFile'
|
||||||
goconst:
|
replacement: 'os.WriteFile'
|
||||||
# Minimal length of string constant.
|
- pattern: 'ioutil.ReadFile'
|
||||||
# Default: 3
|
replacement: 'os.ReadFile'
|
||||||
min-len: 4
|
- pattern: 'ioutil.NopCloser'
|
||||||
# Minimum occurrences of constant string count to trigger issue.
|
replacement: 'io.NopCloser'
|
||||||
# Default: 3
|
goimports:
|
||||||
# For subsequent optimization, the value is reduced.
|
local-prefixes:
|
||||||
min-occurrences: 30
|
- github.com/gogf/gf/v2
|
||||||
# Ignore test files.
|
exclusions:
|
||||||
# Default: false
|
generated: lax
|
||||||
ignore-tests: true
|
paths:
|
||||||
# Look for existing constants matching the values.
|
- third_party$
|
||||||
# Default: true
|
- builtin$
|
||||||
match-constant: false
|
- examples$
|
||||||
# Search also for duplicated numbers.
|
|
||||||
# Default: false
|
|
||||||
numbers: true
|
|
||||||
# Minimum value, only works with goconst.numbers
|
|
||||||
# Default: 3
|
|
||||||
min: 5
|
|
||||||
# Maximum value, only works with goconst.numbers
|
|
||||||
# Default: 3
|
|
||||||
max: 20
|
|
||||||
# Ignore when constant is not used as function argument.
|
|
||||||
# Default: true
|
|
||||||
ignore-calls: false
|
|
||||||
|
|
||||||
# https://golangci-lint.run/usage/linters/#gocritic
|
|
||||||
gocritic:
|
|
||||||
disabled-checks:
|
|
||||||
- ifElseChain
|
|
||||||
- assignOp
|
|
||||||
- appendAssign
|
|
||||||
- singleCaseSwitch
|
|
||||||
- regexpMust
|
|
||||||
- typeSwitchVar
|
|
||||||
- elseif
|
|
||||||
|
|
||||||
# https://golangci-lint.run/usage/linters/#gosimple
|
|
||||||
gosimple:
|
|
||||||
# Sxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
|
|
||||||
# Default: ["*"]
|
|
||||||
checks: [
|
|
||||||
"all", "-S1000", "-S1001", "-S1002", "-S1008", "-S1009", "-S1016", "-S1023", "-S1025", "-S1029", "-S1034", "-S1040"
|
|
||||||
]
|
|
||||||
|
|
||||||
# https://golangci-lint.run/usage/linters/#govet
|
|
||||||
govet:
|
|
||||||
# Report about shadowed variables.
|
|
||||||
# Default: false
|
|
||||||
# check-shadowing: true
|
|
||||||
# Settings per analyzer.
|
|
||||||
settings:
|
|
||||||
# Analyzer name, run `go tool vet help` to see all analyzers.
|
|
||||||
printf:
|
|
||||||
# Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
|
|
||||||
# Default: []
|
|
||||||
funcs:
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
|
|
||||||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
|
|
||||||
# shadow:
|
|
||||||
# Whether to be strict about shadowing; can be noisy.
|
|
||||||
# Default: false
|
|
||||||
# strict: false
|
|
||||||
unusedresult:
|
|
||||||
# Comma-separated list of functions whose results must be used
|
|
||||||
# (in addition to defaults context.WithCancel,context.WithDeadline,context.WithTimeout,context.WithValue,
|
|
||||||
# errors.New,fmt.Errorf,fmt.Sprint,fmt.Sprintf,sort.Reverse)
|
|
||||||
# Default []
|
|
||||||
funcs:
|
|
||||||
- pkg.MyFunc
|
|
||||||
- context.WithCancel
|
|
||||||
# Comma-separated list of names of methods of type func() string whose results must be used
|
|
||||||
# (in addition to default Error,String)
|
|
||||||
# Default []
|
|
||||||
stringmethods:
|
|
||||||
- MyMethod
|
|
||||||
# Enable all analyzers.
|
|
||||||
# Default: false
|
|
||||||
enable-all: true
|
|
||||||
# Disable analyzers by name.
|
|
||||||
# Run `go tool vet help` to see all analyzers.
|
|
||||||
# Default: []
|
|
||||||
disable:
|
|
||||||
- asmdecl
|
|
||||||
- assign
|
|
||||||
- atomic
|
|
||||||
- atomicalign
|
|
||||||
- bools
|
|
||||||
- buildtag
|
|
||||||
- cgocall
|
|
||||||
- composites
|
|
||||||
- copylocks
|
|
||||||
- deepequalerrors
|
|
||||||
- errorsas
|
|
||||||
- fieldalignment
|
|
||||||
- findcall
|
|
||||||
- framepointer
|
|
||||||
- httpresponse
|
|
||||||
- ifaceassert
|
|
||||||
- loopclosure
|
|
||||||
- lostcancel
|
|
||||||
- nilfunc
|
|
||||||
- nilness
|
|
||||||
- reflectvaluecompare
|
|
||||||
- shift
|
|
||||||
- shadow
|
|
||||||
- sigchanyzer
|
|
||||||
- sortslice
|
|
||||||
- stdmethods
|
|
||||||
- stringintconv
|
|
||||||
- structtag
|
|
||||||
- testinggoroutine
|
|
||||||
- tests
|
|
||||||
- unmarshal
|
|
||||||
- unreachable
|
|
||||||
- unsafeptr
|
|
||||||
- unusedwrite
|
|
||||||
|
|
||||||
# https://golangci-lint.run/usage/linters/#staticcheck
|
|
||||||
staticcheck:
|
|
||||||
# SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
|
|
||||||
# Default: ["*"]
|
|
||||||
checks: [ "all","-SA1019","-SA4015","-SA1029","-SA1016","-SA9003","-SA4006","-SA6003" ]
|
|
||||||
|
|
||||||
|
|||||||
33
.make_tidy.sh
Executable file
33
.make_tidy.sh
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
workdir=.
|
||||||
|
echo "Prepare to tidy all go.mod files in the ${workdir} directory"
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
for file in `find ${workdir} -name go.mod`; do
|
||||||
|
goModPath=$(dirname $file)
|
||||||
|
echo ""
|
||||||
|
echo "processing dir: $goModPath"
|
||||||
|
|
||||||
|
if [[ $goModPath =~ "/testdata/" ]]; then
|
||||||
|
echo "ignore testdata path $goModPath"
|
||||||
|
continue 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $goModPath =~ "/examples/" ]]; then
|
||||||
|
echo "ignore examples path $goModPath"
|
||||||
|
continue 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $goModPath
|
||||||
|
go mod tidy
|
||||||
|
# Remove toolchain line if exists
|
||||||
|
sed -i '' '/^toolchain/d' go.mod
|
||||||
|
cd - > /dev/null
|
||||||
|
done
|
||||||
@ -1,4 +1,19 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Function to detect OS and set sed parameters
|
||||||
|
setup_sed() {
|
||||||
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
# macOS
|
||||||
|
SED_INPLACE="sed -i ''"
|
||||||
|
else
|
||||||
|
# Linux/Windows Git Bash
|
||||||
|
SED_INPLACE="sed -i"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize sed command
|
||||||
|
setup_sed
|
||||||
|
|
||||||
if [ $# -ne 2 ]; then
|
if [ $# -ne 2 ]; then
|
||||||
echo "Parameter exception, please execute in the format of $0 [directory] [version number]"
|
echo "Parameter exception, please execute in the format of $0 [directory] [version number]"
|
||||||
echo "PS:$0 ./ v2.4.0"
|
echo "PS:$0 ./ v2.4.0"
|
||||||
@ -17,7 +32,7 @@ fi
|
|||||||
|
|
||||||
workdir=.
|
workdir=.
|
||||||
newVersion=$2
|
newVersion=$2
|
||||||
echo "Prepare to replace the GF library version numbers in all go.mod files in the ${workdir} directory with ${newVersion}"
|
echo "Prepare to replace the GoFrame library version numbers in all go.mod files in the ${workdir} directory with ${newVersion}"
|
||||||
|
|
||||||
# check find command support or not
|
# check find command support or not
|
||||||
output=$(find "${workdir}" -name go.mod 2>&1)
|
output=$(find "${workdir}" -name go.mod 2>&1)
|
||||||
@ -28,10 +43,10 @@ fi
|
|||||||
|
|
||||||
if [[ true ]]; then
|
if [[ true ]]; then
|
||||||
# Use sed to replace the version number in version.go
|
# Use sed to replace the version number in version.go
|
||||||
sed -i '' 's/VERSION = ".*"/VERSION = "'${newVersion}'"/' version.go
|
$SED_INPLACE 's/VERSION = ".*"/VERSION = "'${newVersion}'"/' version.go
|
||||||
|
|
||||||
# Use sed to replace the version number in README.MD
|
# Use sed to replace the version number in README.MD
|
||||||
sed -i '' 's/version=[^"]*/version='${newVersion}'/' README.MD
|
$SED_INPLACE 's/version=[^"]*/version='${newVersion}'/' README.MD
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "go.work" ]; then
|
if [ -f "go.work" ]; then
|
||||||
@ -49,6 +64,11 @@ for file in `find ${workdir} -name go.mod`; do
|
|||||||
continue 1
|
continue 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ $goModPath =~ "/examples/" ]]; then
|
||||||
|
echo "ignore examples path $goModPath"
|
||||||
|
continue 1
|
||||||
|
fi
|
||||||
|
|
||||||
cd $goModPath
|
cd $goModPath
|
||||||
if [ $goModPath = "./cmd/gf" ]; then
|
if [ $goModPath = "./cmd/gf" ]; then
|
||||||
mv go.work go.work.version.bak
|
mv go.work go.work.version.bak
|
||||||
@ -59,15 +79,18 @@ for file in `find ${workdir} -name go.mod`; do
|
|||||||
go mod edit -replace github.com/gogf/gf/contrib/drivers/oracle/v2=../../contrib/drivers/oracle
|
go mod edit -replace github.com/gogf/gf/contrib/drivers/oracle/v2=../../contrib/drivers/oracle
|
||||||
go mod edit -replace github.com/gogf/gf/contrib/drivers/pgsql/v2=../../contrib/drivers/pgsql
|
go mod edit -replace github.com/gogf/gf/contrib/drivers/pgsql/v2=../../contrib/drivers/pgsql
|
||||||
go mod edit -replace github.com/gogf/gf/contrib/drivers/sqlite/v2=../../contrib/drivers/sqlite
|
go mod edit -replace github.com/gogf/gf/contrib/drivers/sqlite/v2=../../contrib/drivers/sqlite
|
||||||
# else
|
|
||||||
# cd -
|
|
||||||
# continue 1
|
|
||||||
fi
|
fi
|
||||||
go mod tidy
|
go mod tidy
|
||||||
# Upgrading only GF related libraries, sometimes even if a version number is specified, it may not be possible to successfully upgrade. Please confirm before submitting the code
|
# Remove toolchain line if exists
|
||||||
|
$SED_INPLACE '/^toolchain/d' go.mod
|
||||||
|
|
||||||
|
# Upgrading only GoFrame related libraries, sometimes even if a version number is specified,
|
||||||
|
# it may not be possible to successfully upgrade. Please confirm before submitting the code
|
||||||
go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf"
|
go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf"
|
||||||
go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf" | xargs -L1 go get -v
|
go list -f "{{if and (not .Indirect) (not .Main)}}{{.Path}}@${newVersion}{{end}}" -m all | grep "^github.com/gogf/gf" | xargs -L1 go get -v
|
||||||
go mod tidy
|
go mod tidy
|
||||||
|
# Remove toolchain line if exists
|
||||||
|
$SED_INPLACE '/^toolchain/d' go.mod
|
||||||
if [ $goModPath = "./cmd/gf" ]; then
|
if [ $goModPath = "./cmd/gf" ]; then
|
||||||
go mod edit -dropreplace github.com/gogf/gf/v2
|
go mod edit -dropreplace github.com/gogf/gf/v2
|
||||||
go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/clickhouse/v2
|
go mod edit -dropreplace github.com/gogf/gf/contrib/drivers/clickhouse/v2
|
||||||
15
CONTRIBUTING.md
Normal file
15
CONTRIBUTING.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Thanks for taking the time to join our community and start contributing!
|
||||||
|
|
||||||
|
## With issues
|
||||||
|
- Use the search tool before opening a new issue.
|
||||||
|
- Please provide source code and commit sha if you found a bug.
|
||||||
|
- Review existing issues and provide feedback or react to them.
|
||||||
|
|
||||||
|
## With pull requests
|
||||||
|
- Open your pull request against `master`
|
||||||
|
- Your pull request should have no more than two commits, if not you should squash them.
|
||||||
|
- It should pass all tests in the available continuous integrations systems such as GitHub CI.
|
||||||
|
- You should add/modify tests to cover your proposed code changes.
|
||||||
|
- If your pull request contains a new feature, please document it on the README.
|
||||||
71
Makefile
71
Makefile
@ -3,26 +3,75 @@ SHELL := /bin/bash
|
|||||||
# execute "go mod tidy" on all folders that have go.mod file
|
# execute "go mod tidy" on all folders that have go.mod file
|
||||||
.PHONY: tidy
|
.PHONY: tidy
|
||||||
tidy:
|
tidy:
|
||||||
$(eval files=$(shell find . -name go.mod))
|
./.make_tidy.sh
|
||||||
@set -e; \
|
|
||||||
for file in ${files}; do \
|
|
||||||
goModPath=$$(dirname $$file); \
|
|
||||||
if ! echo $$goModPath | grep -q "testdata"; then \
|
|
||||||
cd $$goModPath; \
|
|
||||||
go mod tidy; \
|
|
||||||
cd -; \
|
|
||||||
fi \
|
|
||||||
done
|
|
||||||
|
|
||||||
# execute "golangci-lint" to check code style
|
# execute "golangci-lint" to check code style
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint:
|
lint:
|
||||||
golangci-lint run -c .golangci.yml
|
golangci-lint run -c .golangci.yml
|
||||||
|
|
||||||
|
# make branch to=v2.4.0
|
||||||
|
.PHONY: branch
|
||||||
|
branch:
|
||||||
|
@set -e; \
|
||||||
|
newVersion=$(to); \
|
||||||
|
if [ -z "$$newVersion" ]; then \
|
||||||
|
echo "Error: 'to' variable is required. Usage: make branch to=vX.Y.Z"; \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
branchName=fix/$$newVersion; \
|
||||||
|
echo "Switching to master branch..."; \
|
||||||
|
git checkout master; \
|
||||||
|
echo "Pulling latest changes from master..."; \
|
||||||
|
git pull origin master; \
|
||||||
|
echo "Creating and switching to branch $$branchName from master..."; \
|
||||||
|
git checkout -b $$branchName; \
|
||||||
|
echo "Branch $$branchName created successfully!"
|
||||||
|
|
||||||
# make version to=v2.4.0
|
# make version to=v2.4.0
|
||||||
.PHONY: version
|
.PHONY: version
|
||||||
version:
|
version:
|
||||||
@set -e; \
|
@set -e; \
|
||||||
newVersion=$(to); \
|
newVersion=$(to); \
|
||||||
./.set_version.sh ./ $$newVersion; \
|
./.make_version.sh ./ $$newVersion; \
|
||||||
echo "make version to=$(to) done"
|
echo "make version to=$(to) done"
|
||||||
|
|
||||||
|
# make tag to=v2.4.0
|
||||||
|
.PHONY: tag
|
||||||
|
tag:
|
||||||
|
@set -e; \
|
||||||
|
newVersion=$(to); \
|
||||||
|
echo "Switching to master branch..."; \
|
||||||
|
git checkout master; \
|
||||||
|
echo "Pulling latest changes from master..."; \
|
||||||
|
git pull origin master; \
|
||||||
|
echo "Creating annotated tag $$newVersion..."; \
|
||||||
|
git tag -a $$newVersion -m "Release $$newVersion"; \
|
||||||
|
echo "Pushing tag $$newVersion..."; \
|
||||||
|
git push origin $$newVersion; \
|
||||||
|
echo "Tag $$newVersion created and pushed successfully!"
|
||||||
|
|
||||||
|
# update submodules
|
||||||
|
.PHONY: subup
|
||||||
|
subup:
|
||||||
|
@set -e; \
|
||||||
|
echo "Updating submodules..."; \
|
||||||
|
git submodule init;\
|
||||||
|
git submodule update;
|
||||||
|
|
||||||
|
# update and commit submodules
|
||||||
|
.PHONY: subsync
|
||||||
|
subsync: subup
|
||||||
|
@set -e; \
|
||||||
|
echo "";\
|
||||||
|
cd examples; \
|
||||||
|
echo "Checking for changes..."; \
|
||||||
|
if git diff-index --quiet HEAD --; then \
|
||||||
|
echo "No changes to commit"; \
|
||||||
|
else \
|
||||||
|
echo "Found changes, committing..."; \
|
||||||
|
git add -A; \
|
||||||
|
git commit -m "examples update"; \
|
||||||
|
git push origin; \
|
||||||
|
fi; \
|
||||||
|
cd ..;
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
[](https://pkg.go.dev/github.com/gogf/gf/v2)
|
[](https://pkg.go.dev/github.com/gogf/gf/v2)
|
||||||
[](https://github.com/gogf/gf/actions/workflows/ci-main.yml)
|
[](https://github.com/gogf/gf/actions/workflows/ci-main.yml)
|
||||||
|
[](https://scorecard.dev/viewer/?uri=github.com/gogf/gf)
|
||||||
|
[](https://bestpractices.coreinfrastructure.org/projects/9233)
|
||||||
[](https://goreportcard.com/report/github.com/gogf/gf/v2)
|
[](https://goreportcard.com/report/github.com/gogf/gf/v2)
|
||||||
[](https://codecov.io/gh/gogf/gf)
|
[](https://codecov.io/gh/gogf/gf)
|
||||||
[](https://github.com/gogf/gf)
|
[](https://github.com/gogf/gf)
|
||||||
@ -36,7 +38,7 @@ A powerful framework for faster, easier, and more efficient project development.
|
|||||||
💖 [Thanks to all the contributors who made GoFrame possible](https://github.com/gogf/gf/graphs/contributors) 💖
|
💖 [Thanks to all the contributors who made GoFrame possible](https://github.com/gogf/gf/graphs/contributors) 💖
|
||||||
|
|
||||||
<a href="https://github.com/gogf/gf/graphs/contributors">
|
<a href="https://github.com/gogf/gf/graphs/contributors">
|
||||||
<img src="https://goframe.org/img/contributors.svg?version=v2.8.3" alt="goframe contributors"/>
|
<img src="https://goframe.org/img/contributors.svg?version=v2.9.4" alt="goframe contributors"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|||||||
@ -1,32 +1,33 @@
|
|||||||
module github.com/gogf/gf/cmd/gf/v2
|
module github.com/gogf/gf/cmd/gf/v2
|
||||||
|
|
||||||
go 1.20
|
go 1.23.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.8.3
|
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.9.4
|
||||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.8.3
|
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.9.4
|
||||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.3
|
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.9.4
|
||||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.8.3
|
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.9.4
|
||||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.8.3
|
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.9.4
|
||||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.8.3
|
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.9.4
|
||||||
github.com/gogf/gf/v2 v2.8.3
|
github.com/gogf/gf/v2 v2.9.4
|
||||||
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f
|
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f
|
||||||
github.com/olekukonko/tablewriter v0.0.5
|
github.com/olekukonko/tablewriter v1.1.0
|
||||||
golang.org/x/mod v0.17.0
|
github.com/schollz/progressbar/v3 v3.15.0
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d
|
golang.org/x/mod v0.26.0
|
||||||
|
golang.org/x/tools v0.35.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
aead.dev/minisign v0.2.0 // indirect
|
aead.dev/minisign v0.2.0 // indirect
|
||||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
github.com/BurntSushi/toml v1.5.0 // indirect
|
||||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.15 // indirect
|
github.com/ClickHouse/clickhouse-go/v2 v2.0.15 // indirect
|
||||||
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
github.com/clbanning/mxj/v2 v2.7.0 // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||||
github.com/emirpasic/gods v1.18.1 // indirect
|
github.com/emirpasic/gods v1.18.1 // indirect
|
||||||
github.com/fatih/color v1.18.0 // indirect
|
github.com/fatih/color v1.18.0 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||||
github.com/glebarez/go-sqlite v1.21.2 // indirect
|
github.com/glebarez/go-sqlite v1.21.2 // indirect
|
||||||
github.com/go-logr/logr v1.4.2 // indirect
|
github.com/go-logr/logr v1.4.3 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-sql-driver/mysql v1.7.1 // indirect
|
github.com/go-sql-driver/mysql v1.7.1 // indirect
|
||||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
|
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
|
||||||
@ -35,26 +36,31 @@ require (
|
|||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
github.com/gorilla/websocket v1.5.3 // indirect
|
||||||
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
|
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
|
||||||
github.com/lib/pq v1.10.9 // indirect
|
github.com/lib/pq v1.10.9 // indirect
|
||||||
github.com/magiconair/properties v1.8.9 // indirect
|
github.com/magiconair/properties v1.8.10 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||||
github.com/microsoft/go-mssqldb v1.7.1 // indirect
|
github.com/microsoft/go-mssqldb v1.7.1 // indirect
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||||
|
github.com/olekukonko/errors v1.1.0 // indirect
|
||||||
|
github.com/olekukonko/ll v0.0.9 // indirect
|
||||||
github.com/paulmach/orb v0.7.1 // indirect
|
github.com/paulmach/orb v0.7.1 // indirect
|
||||||
github.com/pierrec/lz4/v4 v4.1.14 // indirect
|
github.com/pierrec/lz4/v4 v4.1.14 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/shopspring/decimal v1.3.1 // indirect
|
github.com/shopspring/decimal v1.3.1 // indirect
|
||||||
github.com/sijms/go-ora/v2 v2.7.10 // indirect
|
github.com/sijms/go-ora/v2 v2.7.10 // indirect
|
||||||
go.opentelemetry.io/otel v1.24.0 // indirect
|
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v1.24.0 // indirect
|
go.opentelemetry.io/otel v1.38.0 // indirect
|
||||||
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
|
go.opentelemetry.io/otel/metric v1.38.0 // indirect
|
||||||
go.opentelemetry.io/otel/trace v1.24.0 // indirect
|
go.opentelemetry.io/otel/sdk v1.38.0 // indirect
|
||||||
golang.org/x/crypto v0.31.0 // indirect
|
go.opentelemetry.io/otel/trace v1.38.0 // indirect
|
||||||
golang.org/x/net v0.33.0 // indirect
|
golang.org/x/crypto v0.41.0 // indirect
|
||||||
golang.org/x/sync v0.10.0 // indirect
|
golang.org/x/net v0.43.0 // indirect
|
||||||
golang.org/x/sys v0.28.0 // indirect
|
golang.org/x/sync v0.16.0 // indirect
|
||||||
golang.org/x/text v0.21.0 // indirect
|
golang.org/x/sys v0.35.0 // indirect
|
||||||
|
golang.org/x/term v0.34.0 // indirect
|
||||||
|
golang.org/x/text v0.28.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
modernc.org/libc v1.22.5 // indirect
|
modernc.org/libc v1.22.5 // indirect
|
||||||
modernc.org/mathutil v1.5.0 // indirect
|
modernc.org/mathutil v1.5.0 // indirect
|
||||||
|
|||||||
130
cmd/gf/go.sum
130
cmd/gf/go.sum
@ -1,13 +1,19 @@
|
|||||||
aead.dev/minisign v0.2.0 h1:kAWrq/hBRu4AARY6AlciO83xhNnW9UaC8YipS2uhLPk=
|
aead.dev/minisign v0.2.0 h1:kAWrq/hBRu4AARY6AlciO83xhNnW9UaC8YipS2uhLPk=
|
||||||
aead.dev/minisign v0.2.0/go.mod h1:zdq6LdSd9TbuSxchxwhpA9zEb9YXcVGoE8JakuiGaIQ=
|
aead.dev/minisign v0.2.0/go.mod h1:zdq6LdSd9TbuSxchxwhpA9zEb9YXcVGoE8JakuiGaIQ=
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 h1:lGlwhPtrX6EVml1hO0ivjkUxsSyl4dsiw9qcA1k/3IQ=
|
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 h1:lGlwhPtrX6EVml1hO0ivjkUxsSyl4dsiw9qcA1k/3IQ=
|
||||||
|
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1/go.mod h1:RKUqNu35KJYcVG/fqTRqmuXJZYNhYkBrnC/hX7yGbTA=
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 h1:sO0/P7g68FrryJzljemN+6GTssUXdANk6aJ7T1ZxnsQ=
|
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 h1:sO0/P7g68FrryJzljemN+6GTssUXdANk6aJ7T1ZxnsQ=
|
||||||
|
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1/go.mod h1:h8hyGFDsU5HMivxiS2iYFZsgDbU9OnnJ163x5UGVKYo=
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 h1:6oNBlSdi1QqM1PNW7FPA6xOGA5UNsXnkaYZz9vdPGhA=
|
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 h1:6oNBlSdi1QqM1PNW7FPA6xOGA5UNsXnkaYZz9vdPGhA=
|
||||||
|
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1 h1:MyVTgWR8qd/Jw1Le0NZebGBUCLbtak3bJ3z1OlqZBpw=
|
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1 h1:MyVTgWR8qd/Jw1Le0NZebGBUCLbtak3bJ3z1OlqZBpw=
|
||||||
|
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1/go.mod h1:GpPjLhVR9dnUoJMyHWSPy71xY9/lcmpzIPZXmF0FCVY=
|
||||||
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0 h1:D3occbWoio4EBLkbkevetNMAVX197GkzbUMtqjGWn80=
|
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0 h1:D3occbWoio4EBLkbkevetNMAVX197GkzbUMtqjGWn80=
|
||||||
|
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0/go.mod h1:bTSOgj05NGRuHHhQwAdPnYr9TOdNmKlZTgGLL6nyAdI=
|
||||||
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 h1:DzHpqpoJVaCgOUdVHxE8QB52S6NiVdDQvGlny1qvPqA=
|
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 h1:DzHpqpoJVaCgOUdVHxE8QB52S6NiVdDQvGlny1qvPqA=
|
||||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
|
||||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||||
|
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
|
github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
|
||||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.15 h1:lLAZliqrZEygkxosLaW1qHyeTb4Ho7fVCZ0WKCpLocU=
|
github.com/ClickHouse/clickhouse-go/v2 v2.0.15 h1:lLAZliqrZEygkxosLaW1qHyeTb4Ho7fVCZ0WKCpLocU=
|
||||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.15/go.mod h1:Z21o82zD8FFqefOQDg93c0XITlxGbTsWQuRm588Azkk=
|
github.com/ClickHouse/clickhouse-go/v2 v2.0.15/go.mod h1:Z21o82zD8FFqefOQDg93c0XITlxGbTsWQuRm588Azkk=
|
||||||
@ -18,20 +24,21 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
|
|||||||
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
|
github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
||||||
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
|
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
|
||||||
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||||
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||||
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
|
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/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=
|
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.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||||
@ -39,24 +46,11 @@ 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.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 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.8.3 h1:b/AQMTxiHKPHsidEdk471AC5pkfoK88a5cPmKnzE53U=
|
|
||||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.8.3/go.mod h1:qYrF+x5urXLhce3pMcUAyccIsw3Oec0htynoDE4Boi4=
|
|
||||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.8.3 h1:F7Gt1y6YsYOIvgrUlRK07H29BL77dEgLPXilTqqVC80=
|
|
||||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.8.3/go.mod h1:K5prIMZwHANSZrqZbfm6PoEIMfLtd0PwR7u+hZD9HFs=
|
|
||||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.3 h1:RtoBg5HWACFrgIrFkpzH94kxSd5EWefNAq5k6olNY6c=
|
|
||||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.8.3/go.mod h1:elZjckHRCejwml5Kdx2zfhOUDiAV3r5i4BgXcKAeH00=
|
|
||||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.8.3 h1:10/RCoWmvQ6PSm+leoS6CsKijH4dB38HOXLgP5+aScQ=
|
|
||||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.8.3/go.mod h1:XSaHf3/vTlzj/zioUbzKmaffPuoKvPV639fT91caheM=
|
|
||||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.8.3 h1:DvpoiVac1cwGVDTqC6wzFbDb+gXNzcceRgZUIcuTmaI=
|
|
||||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.8.3/go.mod h1:zugvYVb6c/X9rJ8Gb6b5WkMe+bFz2BsxQ5OLf4RSZos=
|
|
||||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.8.3 h1:3pdibfm4UOiTGGh6UD8jfMyGZBGH9ikrrIMU8i/XANA=
|
|
||||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.8.3/go.mod h1:G5rfcFkBhtmZT4+CU7A3fJH3sNmP4WRIaJ+4JFeVE08=
|
|
||||||
github.com/gogf/gf/v2 v2.8.3 h1:h9Px3lqJnnH6It0AqHRz4/1hx0JmvaSf1IvUir5x1rA=
|
|
||||||
github.com/gogf/gf/v2 v2.8.3/go.mod h1:n++xPYGUUMadw6IygLEgGZqc6y6DRLrJKg5kqCrPLWY=
|
|
||||||
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f h1:7xfXR/BhG3JDqO1s45n65Oyx9t4E/UqDOXep6jXdLCM=
|
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/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/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
|
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
|
||||||
|
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
|
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
|
||||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
|
||||||
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
|
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
|
||||||
@ -64,8 +58,10 @@ github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EO
|
|||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
|
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
|
||||||
|
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
@ -76,28 +72,38 @@ github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
|
|||||||
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
|
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
|
||||||
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
|
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
|
||||||
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
|
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
|
||||||
|
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
|
||||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||||
|
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=
|
github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE=
|
||||||
github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
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.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||||
github.com/microsoft/go-mssqldb v1.7.1 h1:KU/g8aWeM3Hx7IMOFpiwYiUkU+9zeISb4+tx3ScVfsM=
|
github.com/microsoft/go-mssqldb v1.7.1 h1:KU/g8aWeM3Hx7IMOFpiwYiUkU+9zeISb4+tx3ScVfsM=
|
||||||
github.com/microsoft/go-mssqldb v1.7.1/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA=
|
github.com/microsoft/go-mssqldb v1.7.1/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||||
github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615/go.mod h1:Ad7oeElCZqA1Ufj0U9/liOF4BtVepxRcTvr2ey7zTvM=
|
github.com/mkevac/debugcharts v0.0.0-20191222103121-ae1c48aa8615/go.mod h1:Ad7oeElCZqA1Ufj0U9/liOF4BtVepxRcTvr2ey7zTvM=
|
||||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
github.com/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5sM=
|
||||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
|
||||||
|
github.com/olekukonko/ll v0.0.9 h1:Y+1YqDfVkqMWuEQMclsF9HUR5+a82+dxJuL1HHSRpxI=
|
||||||
|
github.com/olekukonko/ll v0.0.9/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
|
||||||
|
github.com/olekukonko/tablewriter v1.1.0 h1:N0LHrshF4T39KvI96fn6GT8HEjXRXYNDrDjKFDB7RIY=
|
||||||
|
github.com/olekukonko/tablewriter v1.1.0/go.mod h1:5c+EBPeSqvXnLLgkm9isDdzR3wjfBkHR9Nhfp3NWrzo=
|
||||||
github.com/paulmach/orb v0.7.1 h1:Zha++Z5OX/l168sqHK3k4z18LDvr+YAO/VjK0ReQ9rU=
|
github.com/paulmach/orb v0.7.1 h1:Zha++Z5OX/l168sqHK3k4z18LDvr+YAO/VjK0ReQ9rU=
|
||||||
github.com/paulmach/orb v0.7.1/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A=
|
github.com/paulmach/orb v0.7.1/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A=
|
||||||
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
|
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
|
||||||
@ -105,6 +111,7 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi
|
|||||||
github.com/pierrec/lz4/v4 v4.1.14 h1:+fL8AQEZtz/ijeNnpduH0bROTu0O3NZAlPjQxGn8LwE=
|
github.com/pierrec/lz4/v4 v4.1.14 h1:+fL8AQEZtz/ijeNnpduH0bROTu0O3NZAlPjQxGn8LwE=
|
||||||
github.com/pierrec/lz4/v4 v4.1.14/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
github.com/pierrec/lz4/v4 v4.1.14/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||||
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
|
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
|
||||||
|
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
@ -113,6 +120,10 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qq
|
|||||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||||
|
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||||
|
github.com/schollz/progressbar/v3 v3.15.0 h1:cNZmcNiVyea6oofBTg80ZhVXxf3wG/JoAhqCCwopkQo=
|
||||||
|
github.com/schollz/progressbar/v3 v3.15.0/go.mod h1:ncBdc++eweU0dQoeZJ3loXoAc+bjaallHRIm8pVVeQM=
|
||||||
github.com/shirou/gopsutil v2.19.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
github.com/shirou/gopsutil v2.19.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
|
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
|
||||||
@ -125,43 +136,50 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
|||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
|
github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
|
||||||
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
|
github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ=
|
||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||||
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
|
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
|
||||||
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
|
go.opentelemetry.io/otel v1.38.0 h1:RkfdswUDRimDg0m2Az18RKOsnI8UDzppJAtj01/Ymk8=
|
||||||
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
|
go.opentelemetry.io/otel v1.38.0/go.mod h1:zcmtmQ1+YmQM9wrNsTGV/q/uyusom3P8RxwExxkZhjM=
|
||||||
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
|
go.opentelemetry.io/otel/metric v1.38.0 h1:Kl6lzIYGAh5M159u9NgiRkmoMKjvbsKtYRwgfrA6WpA=
|
||||||
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
|
go.opentelemetry.io/otel/metric v1.38.0/go.mod h1:kB5n/QoRM8YwmUahxvI3bO34eVtQf2i4utNVLr9gEmI=
|
||||||
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
|
go.opentelemetry.io/otel/sdk v1.38.0 h1:l48sr5YbNf2hpCUj/FoGhW9yDkl+Ma+LrVl8qaM5b+E=
|
||||||
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
|
go.opentelemetry.io/otel/sdk v1.38.0/go.mod h1:ghmNdGlVemJI3+ZB5iDEuk4bWA3GkTpW+DOoZMYBVVg=
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.38.0 h1:aSH66iL0aZqo//xXzQLYozmWrXxyFkBJ6qT5wthqPoM=
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.38.0/go.mod h1:dg9PBnW9XdQ1Hd6ZnRz689CbtrUp0wMMs9iPcgT9EZA=
|
||||||
go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU=
|
go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU=
|
||||||
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
|
go.opentelemetry.io/otel/trace v1.38.0 h1:Fxk5bKrDZJUH+AMyyIXGcFAPah0oRcT+LuNtJrmcNLE=
|
||||||
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
|
go.opentelemetry.io/otel/trace v1.38.0/go.mod h1:j1P9ivuFsTceSWe1oY+EeW3sc+Pp42sO++GHkg4wwhs=
|
||||||
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/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-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||||
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
||||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
|
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
|
||||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
||||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@ -171,29 +189,33 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20210228012217-479acdf4ea46/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210228012217-479acdf4ea46/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
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-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.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||||
|
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
|
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
|
||||||
|
golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4=
|
||||||
|
golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
go 1.20
|
go 1.23.0
|
||||||
|
|
||||||
use (
|
use ./
|
||||||
./
|
|
||||||
)
|
|
||||||
|
|
||||||
// =====================================================================================================
|
// =====================================================================================================
|
||||||
// NOTE:
|
// NOTE:
|
||||||
|
|||||||
@ -11,6 +11,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
|
"github.com/olekukonko/tablewriter/renderer"
|
||||||
|
"github.com/olekukonko/tablewriter/tw"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gproc"
|
"github.com/gogf/gf/v2/os/gproc"
|
||||||
@ -61,10 +63,23 @@ func (c cEnv) Index(ctx context.Context, in cEnvInput) (out *cEnvOutput, err err
|
|||||||
}
|
}
|
||||||
array = append(array, []string{gstr.Trim(match[1]), gstr.Trim(match[2])})
|
array = append(array, []string{gstr.Trim(match[1]), gstr.Trim(match[2])})
|
||||||
}
|
}
|
||||||
tw := tablewriter.NewWriter(buffer)
|
table := tablewriter.NewTable(buffer,
|
||||||
tw.SetColumnAlignment([]int{tablewriter.ALIGN_LEFT, tablewriter.ALIGN_LEFT})
|
tablewriter.WithRenderer(renderer.NewBlueprint(tw.Rendition{
|
||||||
tw.AppendBulk(array)
|
Settings: tw.Settings{
|
||||||
tw.Render()
|
Separators: tw.Separators{BetweenRows: tw.Off, BetweenColumns: tw.On},
|
||||||
|
},
|
||||||
|
Symbols: tw.NewSymbols(tw.StyleASCII),
|
||||||
|
})),
|
||||||
|
tablewriter.WithConfig(tablewriter.Config{
|
||||||
|
Row: tw.CellConfig{
|
||||||
|
Formatting: tw.CellFormatting{AutoWrap: tw.WrapNone},
|
||||||
|
Alignment: tw.CellAlignment{PerColumn: []tw.Align{tw.AlignLeft, tw.AlignLeft}},
|
||||||
|
ColMaxWidths: tw.CellWidth{Global: 84},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
table.Bulk(array)
|
||||||
|
table.Render()
|
||||||
mlog.Print(buffer.String())
|
mlog.Print(buffer.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,13 +8,15 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
|
_ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
|
||||||
// _ "github.com/gogf/gf/contrib/drivers/dm/v2" // precompilation does not support certain target platforms.
|
|
||||||
_ "github.com/gogf/gf/contrib/drivers/mssql/v2"
|
_ "github.com/gogf/gf/contrib/drivers/mssql/v2"
|
||||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||||
_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
|
_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
|
||||||
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
|
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
|
||||||
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
|
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
|
||||||
|
|
||||||
|
// do not add dm in cli pre-compilation,
|
||||||
|
// the dm driver does not support certain target platforms.
|
||||||
|
// _ "github.com/gogf/gf/contrib/drivers/dm/v2"
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao"
|
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/container/gtype"
|
"github.com/gogf/gf/v2/container/gtype"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
@ -207,8 +208,37 @@ func (app *cRunApp) End(ctx context.Context, sig os.Signal, outputPath string) {
|
|||||||
// Delete the binary file.
|
// Delete the binary file.
|
||||||
// firstly, kill the process.
|
// firstly, kill the process.
|
||||||
if process != nil {
|
if process != nil {
|
||||||
if err := process.Kill(); err != nil {
|
if sig != nil && runtime.GOOS != "windows" {
|
||||||
mlog.Debugf("kill process error: %s", err.Error())
|
if err := process.Signal(sig); err != nil {
|
||||||
|
mlog.Debugf("send signal to process error: %s", err.Error())
|
||||||
|
if err := process.Kill(); err != nil {
|
||||||
|
mlog.Debugf("kill process error: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
waitCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
done := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-waitCtx.Done():
|
||||||
|
done <- waitCtx.Err()
|
||||||
|
case done <- process.Wait():
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
err := <-done
|
||||||
|
if err != nil {
|
||||||
|
mlog.Debugf("process wait error: %s", err.Error())
|
||||||
|
if err := process.Kill(); err != nil {
|
||||||
|
mlog.Debugf("kill process error: %s", err.Error())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mlog.Debug("process exited gracefully")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := process.Kill(); err != nil {
|
||||||
|
mlog.Debugf("kill process error: %s", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := gfile.RemoveFile(outputPath); err != nil {
|
if err := gfile.RemoveFile(outputPath); err != nil {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gogf/gf/v2/container/gset"
|
"github.com/gogf/gf/v2/container/gset"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/genv"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/gogf/gf/v2/os/gproc"
|
"github.com/gogf/gf/v2/os/gproc"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
@ -39,7 +40,11 @@ gf up
|
|||||||
gf up -a
|
gf up -a
|
||||||
gf up -c
|
gf up -c
|
||||||
gf up -cf
|
gf up -cf
|
||||||
|
gf up -a -m=install
|
||||||
|
gf up -a -m=install -p=github.com/gogf/gf/cmd/gf/v2@latest
|
||||||
`
|
`
|
||||||
|
cliMethodHttpDownload = "http"
|
||||||
|
cliMethodGoInstall = "install"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -49,10 +54,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type cUpInput struct {
|
type cUpInput struct {
|
||||||
g.Meta `name:"up" config:"gfcli.up"`
|
g.Meta `name:"up" config:"gfcli.up"`
|
||||||
All bool `name:"all" short:"a" brief:"upgrade both version and cli, auto fix codes" orphan:"true"`
|
All bool `name:"all" short:"a" brief:"upgrade both version and cli, auto fix codes" orphan:"true"`
|
||||||
Cli bool `name:"cli" short:"c" brief:"also upgrade CLI tool" orphan:"true"`
|
Cli bool `name:"cli" short:"c" brief:"also upgrade CLI tool" orphan:"true"`
|
||||||
Fix bool `name:"fix" short:"f" brief:"auto fix codes(it only make sense if cli is to be upgraded)" orphan:"true"`
|
Fix bool `name:"fix" short:"f" brief:"auto fix codes(it only make sense if cli is to be upgraded)" orphan:"true"`
|
||||||
|
CliDownloadingMethod string `name:"cli-download-method" short:"m" brief:"cli upgrade method: http=download binary via HTTP GET, install=upgrade via go install" d:"http"`
|
||||||
|
// CliModulePath specifies the module path for CLI installation via go install.
|
||||||
|
// This is used when CliDownloadingMethod is set to "install".
|
||||||
|
CliModulePath string `name:"cli-module-path" short:"p" brief:"custom cli module path for upgrade CLI tool with go install method" d:"github.com/gogf/gf/cmd/gf/v2@latest"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type cUpOutput struct{}
|
type cUpOutput struct{}
|
||||||
@ -76,7 +85,7 @@ func (c cUp) Index(ctx context.Context, in cUpInput) (out *cUpOutput, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if in.Cli {
|
if in.Cli {
|
||||||
if err = c.doUpgradeCLI(ctx); err != nil {
|
if err = c.doUpgradeCLI(ctx, in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,8 +179,22 @@ func (c cUp) doUpgradeVersion(ctx context.Context, in cUpInput) (out *doUpgradeV
|
|||||||
}
|
}
|
||||||
|
|
||||||
// doUpgradeCLI downloads the new version binary with process.
|
// doUpgradeCLI downloads the new version binary with process.
|
||||||
func (c cUp) doUpgradeCLI(ctx context.Context) (err error) {
|
func (c cUp) doUpgradeCLI(ctx context.Context, in cUpInput) (err error) {
|
||||||
mlog.Print(`start upgrading cli...`)
|
mlog.Print(`start upgrading cli...`)
|
||||||
|
fmt.Println(` cli upgrade method:`, in.CliDownloadingMethod)
|
||||||
|
switch in.CliDownloadingMethod {
|
||||||
|
case cliMethodHttpDownload:
|
||||||
|
return c.doUpgradeCLIWithHttpDownload(ctx)
|
||||||
|
case cliMethodGoInstall:
|
||||||
|
return c.doUpgradeCLIWithGoInstall(ctx, in)
|
||||||
|
default:
|
||||||
|
mlog.Fatalf(`invalid cli upgrade method: "%s", please use "http" or "install"`, in.CliDownloadingMethod)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c cUp) doUpgradeCLIWithHttpDownload(ctx context.Context) (err error) {
|
||||||
|
mlog.Print(`start upgrading cli with http get download...`)
|
||||||
var (
|
var (
|
||||||
downloadUrl = fmt.Sprintf(
|
downloadUrl = fmt.Sprintf(
|
||||||
`https://github.com/gogf/gf/releases/latest/download/gf_%s_%s`,
|
`https://github.com/gogf/gf/releases/latest/download/gf_%s_%s`,
|
||||||
@ -213,6 +236,41 @@ func (c cUp) doUpgradeCLI(ctx context.Context) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c cUp) doUpgradeCLIWithGoInstall(ctx context.Context, in cUpInput) (err error) {
|
||||||
|
mlog.Print(`upgrading cli with go install...`)
|
||||||
|
if !genv.Contains("GOPATH") {
|
||||||
|
mlog.Fatal(`"GOPATH" environment variable does not exist, please check your go installation`)
|
||||||
|
}
|
||||||
|
|
||||||
|
command := fmt.Sprintf(`go install %s`, in.CliModulePath)
|
||||||
|
mlog.Printf(`running command: %s`, command)
|
||||||
|
err = gproc.ShellRun(ctx, command)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cliFilePath := gfile.Join(genv.Get("GOPATH").String(), "bin/gf")
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
cliFilePath += ".exe"
|
||||||
|
}
|
||||||
|
|
||||||
|
// It fails if file not exist or its size is less than 1MB.
|
||||||
|
if !gfile.Exists(cliFilePath) || gfile.Size(cliFilePath) < 1024*1024 {
|
||||||
|
mlog.Fatalf(`go install %s failed, "%s" does not exist or its size is less than 1MB`, in.CliModulePath, cliFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
newFile, err := gfile.Open(cliFilePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// selfupdate
|
||||||
|
err = selfupdate.Apply(newFile, selfupdate.Options{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (c cUp) doAutoFixing(ctx context.Context, dirPath string, version string) (err error) {
|
func (c cUp) doAutoFixing(ctx context.Context, dirPath string, version string) (err error) {
|
||||||
mlog.Printf(`auto fixing directory path "%s" from version "%s" ...`, dirPath, version)
|
mlog.Printf(`auto fixing directory path "%s" from version "%s" ...`, dirPath, version)
|
||||||
command := fmt.Sprintf(`gf fix -p %s`, dirPath)
|
command := fmt.Sprintf(`gf fix -p %s`, dirPath)
|
||||||
|
|||||||
@ -104,7 +104,7 @@ func Test_Build_Single_VarMap(t *testing.T) {
|
|||||||
|
|
||||||
t.Assert(gfile.Exists(binaryPath), false)
|
t.Assert(gfile.Exists(binaryPath), false)
|
||||||
_, err = f.Index(ctx, cBuildInput{
|
_, err = f.Index(ctx, cBuildInput{
|
||||||
VarMap: map[string]interface{}{
|
VarMap: map[string]any{
|
||||||
"a": "1",
|
"a": "1",
|
||||||
"b": "2",
|
"b": "2",
|
||||||
},
|
},
|
||||||
|
|||||||
458
cmd/gf/internal/cmd/cmd_z_unit_gen_dao_issue_test.go
Normal file
458
cmd/gf/internal/cmd/cmd_z_unit_gen_dao_issue_test.go
Normal file
@ -0,0 +1,458 @@
|
|||||||
|
// 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"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gcfg"
|
||||||
|
"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"
|
||||||
|
"github.com/gogf/gf/v2/util/gutil"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao"
|
||||||
|
)
|
||||||
|
|
||||||
|
// https://github.com/gogf/gf/issues/2572
|
||||||
|
func Test_Gen_Dao_Issue2572(t *testing.T) {
|
||||||
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
db = testDB
|
||||||
|
table1 = "user1"
|
||||||
|
table2 = "user2"
|
||||||
|
issueDirPath = gtest.DataPath(`issue`, `2572`)
|
||||||
|
)
|
||||||
|
t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2572`, `sql1.sql`)))
|
||||||
|
t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2572`, `sql2.sql`)))
|
||||||
|
defer dropTableWithDb(db, table1)
|
||||||
|
defer dropTableWithDb(db, table2)
|
||||||
|
|
||||||
|
var (
|
||||||
|
path = gfile.Temp(guid.S())
|
||||||
|
group = "test"
|
||||||
|
in = gendao.CGenDaoInput{
|
||||||
|
Path: path,
|
||||||
|
Link: "",
|
||||||
|
Tables: "",
|
||||||
|
TablesEx: "",
|
||||||
|
Group: group,
|
||||||
|
Prefix: "",
|
||||||
|
RemovePrefix: "",
|
||||||
|
JsonCase: "SnakeScreaming",
|
||||||
|
ImportPrefix: "",
|
||||||
|
DaoPath: "",
|
||||||
|
DoPath: "",
|
||||||
|
EntityPath: "",
|
||||||
|
TplDaoIndexPath: "",
|
||||||
|
TplDaoInternalPath: "",
|
||||||
|
TplDaoDoPath: "",
|
||||||
|
TplDaoEntityPath: "",
|
||||||
|
StdTime: false,
|
||||||
|
WithTime: false,
|
||||||
|
GJsonSupport: false,
|
||||||
|
OverwriteDao: false,
|
||||||
|
DescriptionTag: false,
|
||||||
|
NoJsonTag: false,
|
||||||
|
NoModelComment: false,
|
||||||
|
Clear: false,
|
||||||
|
TypeMapping: nil,
|
||||||
|
FieldMapping: nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
err = gutil.FillStructWithDefault(&in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gfile.Copy(issueDirPath, path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
defer gfile.Remove(path)
|
||||||
|
|
||||||
|
pwd := gfile.Pwd()
|
||||||
|
err = gfile.Chdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
defer gfile.Chdir(pwd)
|
||||||
|
|
||||||
|
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
generatedFiles, err := gfile.ScanDir(path, "*.go", true)
|
||||||
|
t.AssertNil(err)
|
||||||
|
t.Assert(len(generatedFiles), 8)
|
||||||
|
for i, generatedFile := range generatedFiles {
|
||||||
|
generatedFiles[i] = gstr.TrimLeftStr(generatedFile, path)
|
||||||
|
}
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/dao/internal/user_1.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/dao/internal/user_2.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/dao/user_1.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/dao/user_2.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/model/do/user_1.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/model/do/user_2.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/model/entity/user_1.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/model/entity/user_2.go")), true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/gogf/gf/issues/2616
|
||||||
|
func Test_Gen_Dao_Issue2616(t *testing.T) {
|
||||||
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
db = testDB
|
||||||
|
table1 = "user1"
|
||||||
|
table2 = "user2"
|
||||||
|
issueDirPath = gtest.DataPath(`issue`, `2616`)
|
||||||
|
)
|
||||||
|
t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2616`, `sql1.sql`)))
|
||||||
|
t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2616`, `sql2.sql`)))
|
||||||
|
defer dropTableWithDb(db, table1)
|
||||||
|
defer dropTableWithDb(db, table2)
|
||||||
|
|
||||||
|
var (
|
||||||
|
path = gfile.Temp(guid.S())
|
||||||
|
group = "test"
|
||||||
|
in = gendao.CGenDaoInput{
|
||||||
|
Path: path,
|
||||||
|
Link: "",
|
||||||
|
Tables: "",
|
||||||
|
TablesEx: "",
|
||||||
|
Group: group,
|
||||||
|
Prefix: "",
|
||||||
|
RemovePrefix: "",
|
||||||
|
JsonCase: "SnakeScreaming",
|
||||||
|
ImportPrefix: "",
|
||||||
|
DaoPath: "",
|
||||||
|
DoPath: "",
|
||||||
|
EntityPath: "",
|
||||||
|
TplDaoIndexPath: "",
|
||||||
|
TplDaoInternalPath: "",
|
||||||
|
TplDaoDoPath: "",
|
||||||
|
TplDaoEntityPath: "",
|
||||||
|
StdTime: false,
|
||||||
|
WithTime: false,
|
||||||
|
GJsonSupport: false,
|
||||||
|
OverwriteDao: false,
|
||||||
|
DescriptionTag: false,
|
||||||
|
NoJsonTag: false,
|
||||||
|
NoModelComment: false,
|
||||||
|
Clear: false,
|
||||||
|
TypeMapping: nil,
|
||||||
|
FieldMapping: nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
err = gutil.FillStructWithDefault(&in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gfile.Copy(issueDirPath, path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
defer gfile.Remove(path)
|
||||||
|
|
||||||
|
pwd := gfile.Pwd()
|
||||||
|
err = gfile.Chdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
defer gfile.Chdir(pwd)
|
||||||
|
|
||||||
|
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
generatedFiles, err := gfile.ScanDir(path, "*.go", true)
|
||||||
|
t.AssertNil(err)
|
||||||
|
t.Assert(len(generatedFiles), 8)
|
||||||
|
for i, generatedFile := range generatedFiles {
|
||||||
|
generatedFiles[i] = gstr.TrimLeftStr(generatedFile, path)
|
||||||
|
}
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/dao/internal/user_1.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/dao/internal/user_2.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/dao/user_1.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/dao/user_2.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/model/do/user_1.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/model/do/user_2.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/model/entity/user_1.go")), true)
|
||||||
|
t.Assert(gstr.InArray(generatedFiles,
|
||||||
|
filepath.FromSlash("/model/entity/user_2.go")), true)
|
||||||
|
|
||||||
|
// Key string to check if overwrite the dao files.
|
||||||
|
// dao user1 is not be overwritten as configured in config.yaml.
|
||||||
|
// dao user2 is to be overwritten as configured in config.yaml.
|
||||||
|
var (
|
||||||
|
keyStr = `// I am not overwritten.`
|
||||||
|
daoUser1Content = gfile.GetContents(path + "/dao/user_1.go")
|
||||||
|
daoUser2Content = gfile.GetContents(path + "/dao/user_2.go")
|
||||||
|
)
|
||||||
|
t.Assert(gstr.Contains(daoUser1Content, keyStr), true)
|
||||||
|
t.Assert(gstr.Contains(daoUser2Content, keyStr), false)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/gogf/gf/issues/2746
|
||||||
|
func Test_Gen_Dao_Issue2746(t *testing.T) {
|
||||||
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
mdb gdb.DB
|
||||||
|
link2746 = "mariadb:root:12345678@tcp(127.0.0.1:3307)/test?loc=Local&parseTime=true"
|
||||||
|
table = "issue2746"
|
||||||
|
sqlContent = fmt.Sprintf(
|
||||||
|
gtest.DataContent(`issue`, `2746`, `sql.sql`),
|
||||||
|
table,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
mdb, err = gdb.New(gdb.ConfigNode{
|
||||||
|
Link: link2746,
|
||||||
|
})
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||||
|
for _, v := range array {
|
||||||
|
if _, err = mdb.Exec(ctx, v); err != nil {
|
||||||
|
t.AssertNil(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer dropTableWithDb(mdb, table)
|
||||||
|
|
||||||
|
var (
|
||||||
|
path = gfile.Temp(guid.S())
|
||||||
|
group = "test"
|
||||||
|
in = gendao.CGenDaoInput{
|
||||||
|
Path: path,
|
||||||
|
Link: link2746,
|
||||||
|
Tables: "",
|
||||||
|
TablesEx: "",
|
||||||
|
Group: group,
|
||||||
|
Prefix: "",
|
||||||
|
RemovePrefix: "",
|
||||||
|
JsonCase: "SnakeScreaming",
|
||||||
|
ImportPrefix: "",
|
||||||
|
DaoPath: "",
|
||||||
|
DoPath: "",
|
||||||
|
EntityPath: "",
|
||||||
|
TplDaoIndexPath: "",
|
||||||
|
TplDaoInternalPath: "",
|
||||||
|
TplDaoDoPath: "",
|
||||||
|
TplDaoEntityPath: "",
|
||||||
|
StdTime: false,
|
||||||
|
WithTime: false,
|
||||||
|
GJsonSupport: true,
|
||||||
|
OverwriteDao: false,
|
||||||
|
DescriptionTag: false,
|
||||||
|
NoJsonTag: false,
|
||||||
|
NoModelComment: false,
|
||||||
|
Clear: false,
|
||||||
|
TypeMapping: nil,
|
||||||
|
FieldMapping: nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
err = gutil.FillStructWithDefault(&in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gfile.Mkdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
defer gfile.Remove(path)
|
||||||
|
|
||||||
|
var (
|
||||||
|
file = filepath.FromSlash(path + "/model/entity/issue_2746.go")
|
||||||
|
expectContent = gtest.DataContent(`issue`, `2746`, `issue_2746.go`)
|
||||||
|
)
|
||||||
|
t.Assert(expectContent, gfile.GetContents(file))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/gogf/gf/issues/3459
|
||||||
|
func Test_Gen_Dao_Issue3459(t *testing.T) {
|
||||||
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
db = testDB
|
||||||
|
table = "table_user"
|
||||||
|
sqlContent = fmt.Sprintf(
|
||||||
|
gtest.DataContent(`gendao`, `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 (
|
||||||
|
confDir = gtest.DataPath("issue", "3459")
|
||||||
|
path = gfile.Temp(guid.S())
|
||||||
|
group = "test"
|
||||||
|
in = gendao.CGenDaoInput{
|
||||||
|
Path: path,
|
||||||
|
Link: link,
|
||||||
|
Tables: "",
|
||||||
|
TablesEx: "",
|
||||||
|
Group: group,
|
||||||
|
Prefix: "",
|
||||||
|
RemovePrefix: "",
|
||||||
|
JsonCase: "SnakeScreaming",
|
||||||
|
ImportPrefix: "",
|
||||||
|
DaoPath: "",
|
||||||
|
DoPath: "",
|
||||||
|
EntityPath: "",
|
||||||
|
TplDaoIndexPath: "",
|
||||||
|
TplDaoInternalPath: "",
|
||||||
|
TplDaoDoPath: "",
|
||||||
|
TplDaoEntityPath: "",
|
||||||
|
StdTime: false,
|
||||||
|
WithTime: false,
|
||||||
|
GJsonSupport: false,
|
||||||
|
OverwriteDao: false,
|
||||||
|
DescriptionTag: false,
|
||||||
|
NoJsonTag: false,
|
||||||
|
NoModelComment: false,
|
||||||
|
Clear: false,
|
||||||
|
TypeMapping: nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
err = g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetPath(confDir)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gutil.FillStructWithDefault(&in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gfile.Mkdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
// for go mod import path auto retrieve.
|
||||||
|
err = gfile.Copy(
|
||||||
|
gtest.DataPath("gendao", "go.mod.txt"),
|
||||||
|
gfile.Join(path, "go.mod"),
|
||||||
|
)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
defer gfile.Remove(path)
|
||||||
|
|
||||||
|
// files
|
||||||
|
files, err := gfile.ScanDir(path, "*.go", true)
|
||||||
|
t.AssertNil(err)
|
||||||
|
t.Assert(files, []string{
|
||||||
|
filepath.FromSlash(path + "/dao/internal/table_user.go"),
|
||||||
|
filepath.FromSlash(path + "/dao/table_user.go"),
|
||||||
|
filepath.FromSlash(path + "/model/do/table_user.go"),
|
||||||
|
filepath.FromSlash(path + "/model/entity/table_user.go"),
|
||||||
|
})
|
||||||
|
// content
|
||||||
|
testPath := gtest.DataPath("gendao", "generated_user")
|
||||||
|
expectFiles := []string{
|
||||||
|
filepath.FromSlash(testPath + "/dao/internal/table_user.go"),
|
||||||
|
filepath.FromSlash(testPath + "/dao/table_user.go"),
|
||||||
|
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||||
|
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||||
|
}
|
||||||
|
for i := range files {
|
||||||
|
//_ = gfile.PutContents(expectFiles[i], gfile.GetContents(files[i]))
|
||||||
|
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/gogf/gf/issues/3749
|
||||||
|
func Test_Gen_Dao_Issue3749(t *testing.T) {
|
||||||
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
db = testDB
|
||||||
|
table = "table_user"
|
||||||
|
sqlContent = fmt.Sprintf(
|
||||||
|
gtest.DataContent(`issue`, `3749`, `user.tpl.sql`),
|
||||||
|
table,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
dropTableWithDb(db, table)
|
||||||
|
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||||
|
for _, v := range array {
|
||||||
|
if _, err = db.Exec(ctx, v); err != nil {
|
||||||
|
t.AssertNil(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer dropTableWithDb(db, table)
|
||||||
|
|
||||||
|
var (
|
||||||
|
path = gfile.Temp(guid.S())
|
||||||
|
group = "test"
|
||||||
|
in = gendao.CGenDaoInput{
|
||||||
|
Path: path,
|
||||||
|
Link: link,
|
||||||
|
Group: group,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
err = gutil.FillStructWithDefault(&in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gfile.Mkdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
// for go mod import path auto retrieve.
|
||||||
|
err = gfile.Copy(
|
||||||
|
gtest.DataPath("gendao", "go.mod.txt"),
|
||||||
|
gfile.Join(path, "go.mod"),
|
||||||
|
)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
defer gfile.Remove(path)
|
||||||
|
|
||||||
|
// files
|
||||||
|
files, err := gfile.ScanDir(path, "*.go", true)
|
||||||
|
t.AssertNil(err)
|
||||||
|
t.Assert(files, []string{
|
||||||
|
filepath.FromSlash(path + "/dao/internal/table_user.go"),
|
||||||
|
filepath.FromSlash(path + "/dao/table_user.go"),
|
||||||
|
filepath.FromSlash(path + "/model/do/table_user.go"),
|
||||||
|
filepath.FromSlash(path + "/model/entity/table_user.go"),
|
||||||
|
})
|
||||||
|
// content
|
||||||
|
testPath := gtest.DataPath(`issue`, `3749`)
|
||||||
|
expectFiles := []string{
|
||||||
|
filepath.FromSlash(testPath + "/dao/internal/table_user.go"),
|
||||||
|
filepath.FromSlash(testPath + "/dao/table_user.go"),
|
||||||
|
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||||
|
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||||
|
}
|
||||||
|
for i := range files {
|
||||||
|
//_ = gfile.PutContents(expectFiles[i], gfile.GetContents(files[i]))
|
||||||
|
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
89
cmd/gf/internal/cmd/cmd_z_unit_gen_dao_sharding_test.go
Normal file
89
cmd/gf/internal/cmd/cmd_z_unit_gen_dao_sharding_test.go
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
// 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/test/gtest"
|
||||||
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
|
"github.com/gogf/gf/v2/util/guid"
|
||||||
|
"github.com/gogf/gf/v2/util/gutil"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Gen_Dao_Sharding(t *testing.T) {
|
||||||
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
db = testDB
|
||||||
|
tableSingle = "single_table"
|
||||||
|
table1 = "users_0001"
|
||||||
|
table2 = "users_0002"
|
||||||
|
table3 = "orders_0001"
|
||||||
|
table4 = "orders_0002"
|
||||||
|
sqlFilePath = gtest.DataPath(`gendao`, `sharding`, `sharding.sql`)
|
||||||
|
)
|
||||||
|
dropTableWithDb(db, tableSingle)
|
||||||
|
dropTableWithDb(db, table1)
|
||||||
|
dropTableWithDb(db, table2)
|
||||||
|
dropTableWithDb(db, table3)
|
||||||
|
dropTableWithDb(db, table4)
|
||||||
|
t.AssertNil(execSqlFile(db, sqlFilePath))
|
||||||
|
defer dropTableWithDb(db, tableSingle)
|
||||||
|
defer dropTableWithDb(db, table1)
|
||||||
|
defer dropTableWithDb(db, table2)
|
||||||
|
defer dropTableWithDb(db, table3)
|
||||||
|
defer dropTableWithDb(db, table4)
|
||||||
|
|
||||||
|
var (
|
||||||
|
path = gfile.Temp(guid.S())
|
||||||
|
// path = "/Users/john/Temp/gen_dao_sharding"
|
||||||
|
group = "test"
|
||||||
|
in = gendao.CGenDaoInput{
|
||||||
|
Path: path,
|
||||||
|
Link: link,
|
||||||
|
Group: group,
|
||||||
|
Prefix: "",
|
||||||
|
ShardingPattern: []string{
|
||||||
|
`users_?`,
|
||||||
|
`orders_?`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
err = gutil.FillStructWithDefault(&in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gfile.Mkdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
pwd := gfile.Pwd()
|
||||||
|
err = gfile.Chdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
defer gfile.Chdir(pwd)
|
||||||
|
defer gfile.RemoveAll(path)
|
||||||
|
|
||||||
|
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
generatedFiles, err := gfile.ScanDir(path, "*.go", true)
|
||||||
|
t.AssertNil(err)
|
||||||
|
t.Assert(len(generatedFiles), 12)
|
||||||
|
var (
|
||||||
|
daoSingleTableContent = gfile.GetContents(gfile.Join(path, "dao", "single_table.go"))
|
||||||
|
daoUsersContent = gfile.GetContents(gfile.Join(path, "dao", "users.go"))
|
||||||
|
daoOrdersContent = gfile.GetContents(gfile.Join(path, "dao", "orders.go"))
|
||||||
|
)
|
||||||
|
t.Assert(gstr.Contains(daoSingleTableContent, "SingleTable = singleTableDao{internal.NewSingleTableDao()}"), true)
|
||||||
|
t.Assert(gstr.Contains(daoUsersContent, "Users = usersDao{internal.NewUsersDao(usersShardingHandler)}"), true)
|
||||||
|
t.Assert(gstr.Contains(daoUsersContent, "m.Sharding(gdb.ShardingConfig{"), true)
|
||||||
|
t.Assert(gstr.Contains(daoOrdersContent, "Orders = ordersDao{internal.NewOrdersDao(ordersShardingHandler)}"), true)
|
||||||
|
t.Assert(gstr.Contains(daoOrdersContent, "m.Sharding(gdb.ShardingConfig{"), true)
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -12,8 +12,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
|
||||||
"github.com/gogf/gf/v2/os/gcfg"
|
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/gogf/gf/v2/test/gtest"
|
"github.com/gogf/gf/v2/test/gtest"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
@ -109,7 +107,7 @@ func Test_Gen_Dao_Default(t *testing.T) {
|
|||||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||||
}
|
}
|
||||||
for i, _ := range files {
|
for i := range files {
|
||||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -210,7 +208,8 @@ func Test_Gen_Dao_TypeMapping(t *testing.T) {
|
|||||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||||
}
|
}
|
||||||
for i, _ := range files {
|
for i := range files {
|
||||||
|
//_ = gfile.PutContents(expectFiles[i], gfile.GetContents(files[i]))
|
||||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -312,7 +311,8 @@ func Test_Gen_Dao_FieldMapping(t *testing.T) {
|
|||||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||||
}
|
}
|
||||||
for i, _ := range files {
|
for i := range files {
|
||||||
|
//_ = gfile.PutContents(expectFiles[i], gfile.GetContents(files[i]))
|
||||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -332,438 +332,6 @@ func execSqlFile(db gdb.DB, filePath string, args ...any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/gogf/gf/issues/2572
|
|
||||||
func Test_Gen_Dao_Issue2572(t *testing.T) {
|
|
||||||
gtest.C(t, func(t *gtest.T) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
db = testDB
|
|
||||||
table1 = "user1"
|
|
||||||
table2 = "user2"
|
|
||||||
issueDirPath = gtest.DataPath(`issue`, `2572`)
|
|
||||||
)
|
|
||||||
t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2572`, `sql1.sql`)))
|
|
||||||
t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2572`, `sql2.sql`)))
|
|
||||||
defer dropTableWithDb(db, table1)
|
|
||||||
defer dropTableWithDb(db, table2)
|
|
||||||
|
|
||||||
var (
|
|
||||||
path = gfile.Temp(guid.S())
|
|
||||||
group = "test"
|
|
||||||
in = gendao.CGenDaoInput{
|
|
||||||
Path: path,
|
|
||||||
Link: "",
|
|
||||||
Tables: "",
|
|
||||||
TablesEx: "",
|
|
||||||
Group: group,
|
|
||||||
Prefix: "",
|
|
||||||
RemovePrefix: "",
|
|
||||||
JsonCase: "SnakeScreaming",
|
|
||||||
ImportPrefix: "",
|
|
||||||
DaoPath: "",
|
|
||||||
DoPath: "",
|
|
||||||
EntityPath: "",
|
|
||||||
TplDaoIndexPath: "",
|
|
||||||
TplDaoInternalPath: "",
|
|
||||||
TplDaoDoPath: "",
|
|
||||||
TplDaoEntityPath: "",
|
|
||||||
StdTime: false,
|
|
||||||
WithTime: false,
|
|
||||||
GJsonSupport: false,
|
|
||||||
OverwriteDao: false,
|
|
||||||
DescriptionTag: false,
|
|
||||||
NoJsonTag: false,
|
|
||||||
NoModelComment: false,
|
|
||||||
Clear: false,
|
|
||||||
TypeMapping: nil,
|
|
||||||
FieldMapping: nil,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
err = gutil.FillStructWithDefault(&in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
err = gfile.Copy(issueDirPath, path)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
defer gfile.Remove(path)
|
|
||||||
|
|
||||||
pwd := gfile.Pwd()
|
|
||||||
err = gfile.Chdir(path)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
defer gfile.Chdir(pwd)
|
|
||||||
|
|
||||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
generatedFiles, err := gfile.ScanDir(path, "*.go", true)
|
|
||||||
t.AssertNil(err)
|
|
||||||
t.Assert(len(generatedFiles), 8)
|
|
||||||
for i, generatedFile := range generatedFiles {
|
|
||||||
generatedFiles[i] = gstr.TrimLeftStr(generatedFile, path)
|
|
||||||
}
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/dao/internal/user_1.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/dao/internal/user_2.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/dao/user_1.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/dao/user_2.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/model/do/user_1.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/model/do/user_2.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/model/entity/user_1.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/model/entity/user_2.go")), true)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/gogf/gf/issues/2616
|
|
||||||
func Test_Gen_Dao_Issue2616(t *testing.T) {
|
|
||||||
gtest.C(t, func(t *gtest.T) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
db = testDB
|
|
||||||
table1 = "user1"
|
|
||||||
table2 = "user2"
|
|
||||||
issueDirPath = gtest.DataPath(`issue`, `2616`)
|
|
||||||
)
|
|
||||||
t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2616`, `sql1.sql`)))
|
|
||||||
t.AssertNil(execSqlFile(db, gtest.DataPath(`issue`, `2616`, `sql2.sql`)))
|
|
||||||
defer dropTableWithDb(db, table1)
|
|
||||||
defer dropTableWithDb(db, table2)
|
|
||||||
|
|
||||||
var (
|
|
||||||
path = gfile.Temp(guid.S())
|
|
||||||
group = "test"
|
|
||||||
in = gendao.CGenDaoInput{
|
|
||||||
Path: path,
|
|
||||||
Link: "",
|
|
||||||
Tables: "",
|
|
||||||
TablesEx: "",
|
|
||||||
Group: group,
|
|
||||||
Prefix: "",
|
|
||||||
RemovePrefix: "",
|
|
||||||
JsonCase: "SnakeScreaming",
|
|
||||||
ImportPrefix: "",
|
|
||||||
DaoPath: "",
|
|
||||||
DoPath: "",
|
|
||||||
EntityPath: "",
|
|
||||||
TplDaoIndexPath: "",
|
|
||||||
TplDaoInternalPath: "",
|
|
||||||
TplDaoDoPath: "",
|
|
||||||
TplDaoEntityPath: "",
|
|
||||||
StdTime: false,
|
|
||||||
WithTime: false,
|
|
||||||
GJsonSupport: false,
|
|
||||||
OverwriteDao: false,
|
|
||||||
DescriptionTag: false,
|
|
||||||
NoJsonTag: false,
|
|
||||||
NoModelComment: false,
|
|
||||||
Clear: false,
|
|
||||||
TypeMapping: nil,
|
|
||||||
FieldMapping: nil,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
err = gutil.FillStructWithDefault(&in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
err = gfile.Copy(issueDirPath, path)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
defer gfile.Remove(path)
|
|
||||||
|
|
||||||
pwd := gfile.Pwd()
|
|
||||||
err = gfile.Chdir(path)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
defer gfile.Chdir(pwd)
|
|
||||||
|
|
||||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
generatedFiles, err := gfile.ScanDir(path, "*.go", true)
|
|
||||||
t.AssertNil(err)
|
|
||||||
t.Assert(len(generatedFiles), 8)
|
|
||||||
for i, generatedFile := range generatedFiles {
|
|
||||||
generatedFiles[i] = gstr.TrimLeftStr(generatedFile, path)
|
|
||||||
}
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/dao/internal/user_1.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/dao/internal/user_2.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/dao/user_1.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/dao/user_2.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/model/do/user_1.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/model/do/user_2.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/model/entity/user_1.go")), true)
|
|
||||||
t.Assert(gstr.InArray(generatedFiles,
|
|
||||||
filepath.FromSlash("/model/entity/user_2.go")), true)
|
|
||||||
|
|
||||||
// Key string to check if overwrite the dao files.
|
|
||||||
// dao user1 is not be overwritten as configured in config.yaml.
|
|
||||||
// dao user2 is to be overwritten as configured in config.yaml.
|
|
||||||
var (
|
|
||||||
keyStr = `// I am not overwritten.`
|
|
||||||
daoUser1Content = gfile.GetContents(path + "/dao/user_1.go")
|
|
||||||
daoUser2Content = gfile.GetContents(path + "/dao/user_2.go")
|
|
||||||
)
|
|
||||||
t.Assert(gstr.Contains(daoUser1Content, keyStr), true)
|
|
||||||
t.Assert(gstr.Contains(daoUser2Content, keyStr), false)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/gogf/gf/issues/2746
|
|
||||||
func Test_Gen_Dao_Issue2746(t *testing.T) {
|
|
||||||
gtest.C(t, func(t *gtest.T) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
mdb gdb.DB
|
|
||||||
link2746 = "mariadb:root:12345678@tcp(127.0.0.1:3307)/test?loc=Local&parseTime=true"
|
|
||||||
table = "issue2746"
|
|
||||||
sqlContent = fmt.Sprintf(
|
|
||||||
gtest.DataContent(`issue`, `2746`, `sql.sql`),
|
|
||||||
table,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
mdb, err = gdb.New(gdb.ConfigNode{
|
|
||||||
Link: link2746,
|
|
||||||
})
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
array := gstr.SplitAndTrim(sqlContent, ";")
|
|
||||||
for _, v := range array {
|
|
||||||
if _, err = mdb.Exec(ctx, v); err != nil {
|
|
||||||
t.AssertNil(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defer dropTableWithDb(mdb, table)
|
|
||||||
|
|
||||||
var (
|
|
||||||
path = gfile.Temp(guid.S())
|
|
||||||
group = "test"
|
|
||||||
in = gendao.CGenDaoInput{
|
|
||||||
Path: path,
|
|
||||||
Link: link2746,
|
|
||||||
Tables: "",
|
|
||||||
TablesEx: "",
|
|
||||||
Group: group,
|
|
||||||
Prefix: "",
|
|
||||||
RemovePrefix: "",
|
|
||||||
JsonCase: "SnakeScreaming",
|
|
||||||
ImportPrefix: "",
|
|
||||||
DaoPath: "",
|
|
||||||
DoPath: "",
|
|
||||||
EntityPath: "",
|
|
||||||
TplDaoIndexPath: "",
|
|
||||||
TplDaoInternalPath: "",
|
|
||||||
TplDaoDoPath: "",
|
|
||||||
TplDaoEntityPath: "",
|
|
||||||
StdTime: false,
|
|
||||||
WithTime: false,
|
|
||||||
GJsonSupport: true,
|
|
||||||
OverwriteDao: false,
|
|
||||||
DescriptionTag: false,
|
|
||||||
NoJsonTag: false,
|
|
||||||
NoModelComment: false,
|
|
||||||
Clear: false,
|
|
||||||
TypeMapping: nil,
|
|
||||||
FieldMapping: nil,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
err = gutil.FillStructWithDefault(&in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
err = gfile.Mkdir(path)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
defer gfile.Remove(path)
|
|
||||||
|
|
||||||
var (
|
|
||||||
file = filepath.FromSlash(path + "/model/entity/issue_2746.go")
|
|
||||||
expectContent = gtest.DataContent(`issue`, `2746`, `issue_2746.go`)
|
|
||||||
)
|
|
||||||
t.Assert(expectContent, gfile.GetContents(file))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/gogf/gf/issues/3459
|
|
||||||
func Test_Gen_Dao_Issue3459(t *testing.T) {
|
|
||||||
gtest.C(t, func(t *gtest.T) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
db = testDB
|
|
||||||
table = "table_user"
|
|
||||||
sqlContent = fmt.Sprintf(
|
|
||||||
gtest.DataContent(`gendao`, `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 (
|
|
||||||
confDir = gtest.DataPath("issue", "3459")
|
|
||||||
path = gfile.Temp(guid.S())
|
|
||||||
group = "test"
|
|
||||||
in = gendao.CGenDaoInput{
|
|
||||||
Path: path,
|
|
||||||
Link: link,
|
|
||||||
Tables: "",
|
|
||||||
TablesEx: "",
|
|
||||||
Group: group,
|
|
||||||
Prefix: "",
|
|
||||||
RemovePrefix: "",
|
|
||||||
JsonCase: "SnakeScreaming",
|
|
||||||
ImportPrefix: "",
|
|
||||||
DaoPath: "",
|
|
||||||
DoPath: "",
|
|
||||||
EntityPath: "",
|
|
||||||
TplDaoIndexPath: "",
|
|
||||||
TplDaoInternalPath: "",
|
|
||||||
TplDaoDoPath: "",
|
|
||||||
TplDaoEntityPath: "",
|
|
||||||
StdTime: false,
|
|
||||||
WithTime: false,
|
|
||||||
GJsonSupport: false,
|
|
||||||
OverwriteDao: false,
|
|
||||||
DescriptionTag: false,
|
|
||||||
NoJsonTag: false,
|
|
||||||
NoModelComment: false,
|
|
||||||
Clear: false,
|
|
||||||
TypeMapping: nil,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
err = g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetPath(confDir)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
err = gutil.FillStructWithDefault(&in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
err = gfile.Mkdir(path)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
// for go mod import path auto retrieve.
|
|
||||||
err = gfile.Copy(
|
|
||||||
gtest.DataPath("gendao", "go.mod.txt"),
|
|
||||||
gfile.Join(path, "go.mod"),
|
|
||||||
)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
defer gfile.Remove(path)
|
|
||||||
|
|
||||||
// files
|
|
||||||
files, err := gfile.ScanDir(path, "*.go", true)
|
|
||||||
t.AssertNil(err)
|
|
||||||
t.Assert(files, []string{
|
|
||||||
filepath.FromSlash(path + "/dao/internal/table_user.go"),
|
|
||||||
filepath.FromSlash(path + "/dao/table_user.go"),
|
|
||||||
filepath.FromSlash(path + "/model/do/table_user.go"),
|
|
||||||
filepath.FromSlash(path + "/model/entity/table_user.go"),
|
|
||||||
})
|
|
||||||
// content
|
|
||||||
testPath := gtest.DataPath("gendao", "generated_user")
|
|
||||||
expectFiles := []string{
|
|
||||||
filepath.FromSlash(testPath + "/dao/internal/table_user.go"),
|
|
||||||
filepath.FromSlash(testPath + "/dao/table_user.go"),
|
|
||||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
|
||||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
|
||||||
}
|
|
||||||
for i, _ := range files {
|
|
||||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/gogf/gf/issues/3749
|
|
||||||
func Test_Gen_Dao_Issue3749(t *testing.T) {
|
|
||||||
gtest.C(t, func(t *gtest.T) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
db = testDB
|
|
||||||
table = "table_user"
|
|
||||||
sqlContent = fmt.Sprintf(
|
|
||||||
gtest.DataContent(`issue`, `3749`, `user.tpl.sql`),
|
|
||||||
table,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
dropTableWithDb(db, table)
|
|
||||||
array := gstr.SplitAndTrim(sqlContent, ";")
|
|
||||||
for _, v := range array {
|
|
||||||
if _, err = db.Exec(ctx, v); err != nil {
|
|
||||||
t.AssertNil(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defer dropTableWithDb(db, table)
|
|
||||||
|
|
||||||
var (
|
|
||||||
path = gfile.Temp(guid.S())
|
|
||||||
group = "test"
|
|
||||||
in = gendao.CGenDaoInput{
|
|
||||||
Path: path,
|
|
||||||
Link: link,
|
|
||||||
Group: group,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
err = gutil.FillStructWithDefault(&in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
err = gfile.Mkdir(path)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
// for go mod import path auto retrieve.
|
|
||||||
err = gfile.Copy(
|
|
||||||
gtest.DataPath("gendao", "go.mod.txt"),
|
|
||||||
gfile.Join(path, "go.mod"),
|
|
||||||
)
|
|
||||||
t.AssertNil(err)
|
|
||||||
|
|
||||||
_, err = gendao.CGenDao{}.Dao(ctx, in)
|
|
||||||
t.AssertNil(err)
|
|
||||||
defer gfile.Remove(path)
|
|
||||||
|
|
||||||
// files
|
|
||||||
files, err := gfile.ScanDir(path, "*.go", true)
|
|
||||||
t.AssertNil(err)
|
|
||||||
t.Assert(files, []string{
|
|
||||||
filepath.FromSlash(path + "/dao/internal/table_user.go"),
|
|
||||||
filepath.FromSlash(path + "/dao/table_user.go"),
|
|
||||||
filepath.FromSlash(path + "/model/do/table_user.go"),
|
|
||||||
filepath.FromSlash(path + "/model/entity/table_user.go"),
|
|
||||||
})
|
|
||||||
// content
|
|
||||||
testPath := gtest.DataPath(`issue`, `3749`)
|
|
||||||
expectFiles := []string{
|
|
||||||
filepath.FromSlash(testPath + "/dao/internal/table_user.go"),
|
|
||||||
filepath.FromSlash(testPath + "/dao/table_user.go"),
|
|
||||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
|
||||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
|
||||||
}
|
|
||||||
for i, _ := range files {
|
|
||||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_Gen_Dao_Sqlite3(t *testing.T) {
|
func Test_Gen_Dao_Sqlite3(t *testing.T) {
|
||||||
gtest.C(t, func(t *gtest.T) {
|
gtest.C(t, func(t *gtest.T) {
|
||||||
var (
|
var (
|
||||||
@ -835,7 +403,8 @@ func Test_Gen_Dao_Sqlite3(t *testing.T) {
|
|||||||
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
filepath.FromSlash(testPath + "/model/do/table_user.go"),
|
||||||
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
filepath.FromSlash(testPath + "/model/entity/table_user.go"),
|
||||||
}
|
}
|
||||||
for i, _ := range files {
|
for i := range files {
|
||||||
|
//_ = gfile.PutContents(expectFiles[i], gfile.GetContents(files[i]))
|
||||||
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -55,7 +55,7 @@ func TestGenPbIssue3882(t *testing.T) {
|
|||||||
func TestGenPbIssue3953(t *testing.T) {
|
func TestGenPbIssue3953(t *testing.T) {
|
||||||
gtest.C(t, func(t *gtest.T) {
|
gtest.C(t, func(t *gtest.T) {
|
||||||
var (
|
var (
|
||||||
outputPath = gfile.Temp(guid.S())
|
outputPath = gfile.Temp("f" + guid.S())
|
||||||
outputApiPath = filepath.Join(outputPath, "api")
|
outputApiPath = filepath.Join(outputPath, "api")
|
||||||
outputCtrlPath = filepath.Join(outputPath, "controller")
|
outputCtrlPath = filepath.Join(outputPath, "controller")
|
||||||
|
|
||||||
|
|||||||
@ -286,3 +286,226 @@ func Test_Issue_3685(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/gogf/gf/issues/3955
|
||||||
|
func Test_Issue_3955(t *testing.T) {
|
||||||
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
db = testDB
|
||||||
|
table1 = "table_user_a"
|
||||||
|
table2 = "table_user_b"
|
||||||
|
sqlContent = fmt.Sprintf(
|
||||||
|
gtest.DataContent(`genpbentity`, `user.tpl.sql`),
|
||||||
|
table1,
|
||||||
|
)
|
||||||
|
sqlContent2 = fmt.Sprintf(
|
||||||
|
gtest.DataContent(`genpbentity`, `user.tpl.sql`),
|
||||||
|
table2,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
dropTableWithDb(db, table1)
|
||||||
|
dropTableWithDb(db, table2)
|
||||||
|
|
||||||
|
array := gstr.SplitAndTrim(sqlContent, ";")
|
||||||
|
for _, v := range array {
|
||||||
|
if _, err = db.Exec(ctx, v); err != nil {
|
||||||
|
t.AssertNil(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
array = gstr.SplitAndTrim(sqlContent2, ";")
|
||||||
|
for _, v := range array {
|
||||||
|
if _, err = db.Exec(ctx, v); err != nil {
|
||||||
|
t.AssertNil(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defer dropTableWithDb(db, table1)
|
||||||
|
defer dropTableWithDb(db, table2)
|
||||||
|
|
||||||
|
var (
|
||||||
|
path = gfile.Temp(guid.S())
|
||||||
|
in = genpbentity.CGenPbEntityInput{
|
||||||
|
Path: path,
|
||||||
|
Package: "unittest",
|
||||||
|
Link: link,
|
||||||
|
Tables: "",
|
||||||
|
Prefix: "",
|
||||||
|
RemovePrefix: "",
|
||||||
|
RemoveFieldPrefix: "",
|
||||||
|
NameCase: "",
|
||||||
|
JsonCase: "",
|
||||||
|
Option: "",
|
||||||
|
TablesEx: "table_user_a",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
err = gutil.FillStructWithDefault(&in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gfile.Mkdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
defer gfile.Remove(path)
|
||||||
|
|
||||||
|
_, err = genpbentity.CGenPbEntity{}.PbEntity(ctx, in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
files, err := gfile.ScanDir(path, "*.proto", false)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
t.AssertEQ(len(files), 1)
|
||||||
|
|
||||||
|
t.Assert(files, []string{
|
||||||
|
path + filepath.FromSlash("/table_user_b.proto"),
|
||||||
|
})
|
||||||
|
|
||||||
|
expectFiles := []string{
|
||||||
|
path + filepath.FromSlash("/table_user_b.proto"),
|
||||||
|
}
|
||||||
|
for i := range files {
|
||||||
|
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_Issue_4330_TypeMapping_Ineffective(t *testing.T) {
|
||||||
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
db = testDB
|
||||||
|
table = "table_user"
|
||||||
|
sqlContent = fmt.Sprintf(
|
||||||
|
gtest.DataContent(`issue`, `3685`, `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())
|
||||||
|
in = genpbentity.CGenPbEntityInput{
|
||||||
|
Path: path,
|
||||||
|
Package: "",
|
||||||
|
Link: link,
|
||||||
|
Tables: "",
|
||||||
|
Prefix: "",
|
||||||
|
RemovePrefix: "",
|
||||||
|
RemoveFieldPrefix: "",
|
||||||
|
NameCase: "",
|
||||||
|
JsonCase: "",
|
||||||
|
Option: "",
|
||||||
|
TypeMapping: map[genpbentity.DBFieldTypeName]genpbentity.CustomAttributeType{
|
||||||
|
"json": {
|
||||||
|
Type: "google.protobuf.Value",
|
||||||
|
Import: "google/protobuf/struct.proto",
|
||||||
|
},
|
||||||
|
"decimal": {
|
||||||
|
Type: "double",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
FieldMapping: nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
err = gutil.FillStructWithDefault(&in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gfile.Mkdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
defer gfile.Remove(path)
|
||||||
|
|
||||||
|
_, err = genpbentity.CGenPbEntity{}.PbEntity(ctx, in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
// files
|
||||||
|
files, err := gfile.ScanDir(path, "*.proto", false)
|
||||||
|
t.AssertNil(err)
|
||||||
|
t.Assert(files, []string{
|
||||||
|
path + filepath.FromSlash("/table_user.proto"),
|
||||||
|
})
|
||||||
|
|
||||||
|
// contents
|
||||||
|
testPath := gtest.DataPath("issue", "4330")
|
||||||
|
expectFiles := []string{
|
||||||
|
testPath + filepath.FromSlash("/issue4330_double.proto"),
|
||||||
|
}
|
||||||
|
for i := range files {
|
||||||
|
t.Assert(gfile.GetContents(files[i]), gfile.GetContents(expectFiles[i]))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_Gen_Pbentity_Sharding(t *testing.T) {
|
||||||
|
gtest.C(t, func(t *gtest.T) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
db = testDB
|
||||||
|
tableSingle = "single_table"
|
||||||
|
table1 = "users_0001"
|
||||||
|
table2 = "users_0002"
|
||||||
|
table3 = "orders_0001"
|
||||||
|
table4 = "orders_0002"
|
||||||
|
sqlFilePath = gtest.DataPath(`gendao`, `sharding`, `sharding.sql`)
|
||||||
|
)
|
||||||
|
dropTableWithDb(db, tableSingle)
|
||||||
|
dropTableWithDb(db, table1)
|
||||||
|
dropTableWithDb(db, table2)
|
||||||
|
dropTableWithDb(db, table3)
|
||||||
|
dropTableWithDb(db, table4)
|
||||||
|
t.AssertNil(execSqlFile(db, sqlFilePath))
|
||||||
|
defer dropTableWithDb(db, tableSingle)
|
||||||
|
defer dropTableWithDb(db, table1)
|
||||||
|
defer dropTableWithDb(db, table2)
|
||||||
|
defer dropTableWithDb(db, table3)
|
||||||
|
defer dropTableWithDb(db, table4)
|
||||||
|
|
||||||
|
var (
|
||||||
|
path = gfile.Temp(guid.S())
|
||||||
|
in = genpbentity.CGenPbEntityInput{
|
||||||
|
Path: path,
|
||||||
|
Package: "unittest",
|
||||||
|
Link: link,
|
||||||
|
Tables: "",
|
||||||
|
RemovePrefix: "",
|
||||||
|
RemoveFieldPrefix: "",
|
||||||
|
NameCase: "",
|
||||||
|
JsonCase: "",
|
||||||
|
Option: "",
|
||||||
|
TypeMapping: nil,
|
||||||
|
FieldMapping: nil,
|
||||||
|
ShardingPattern: []string{
|
||||||
|
`users_?`,
|
||||||
|
`orders_?`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
err = gutil.FillStructWithDefault(&in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
err = gfile.Mkdir(path)
|
||||||
|
t.AssertNil(err)
|
||||||
|
defer gfile.Remove(path)
|
||||||
|
|
||||||
|
_, err = genpbentity.CGenPbEntity{}.PbEntity(ctx, in)
|
||||||
|
t.AssertNil(err)
|
||||||
|
|
||||||
|
// files
|
||||||
|
t.AssertNil(err)
|
||||||
|
generatedFiles, err := gfile.ScanDir(path, "*.proto", true)
|
||||||
|
t.Assert(len(generatedFiles), 3)
|
||||||
|
var (
|
||||||
|
msgSingleTableContent = gfile.GetContents(gfile.Join(path, "single_table.proto"))
|
||||||
|
msgUsersContent = gfile.GetContents(gfile.Join(path, "users.proto"))
|
||||||
|
msgOrdersContent = gfile.GetContents(gfile.Join(path, "orders.proto"))
|
||||||
|
)
|
||||||
|
t.Assert(gstr.Contains(msgSingleTableContent, "message SingleTable {"), true)
|
||||||
|
t.Assert(gstr.Contains(msgUsersContent, "message Users {"), true)
|
||||||
|
t.Assert(gstr.Contains(msgOrdersContent, "message Orders {"), true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -9,13 +9,14 @@ package genctrl
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
|
||||||
"github.com/gogf/gf/v2/container/gset"
|
"github.com/gogf/gf/v2/container/gset"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
"github.com/gogf/gf/v2/util/gtag"
|
"github.com/gogf/gf/v2/util/gtag"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@ -6,7 +6,11 @@
|
|||||||
|
|
||||||
package genctrl
|
package genctrl
|
||||||
|
|
||||||
import "github.com/gogf/gf/v2/text/gstr"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
|
)
|
||||||
|
|
||||||
type apiItem struct {
|
type apiItem struct {
|
||||||
Import string `eg:"demo.com/api/user/v1"`
|
Import string `eg:"demo.com/api/user/v1"`
|
||||||
@ -14,6 +18,7 @@ type apiItem struct {
|
|||||||
Module string `eg:"user"`
|
Module string `eg:"user"`
|
||||||
Version string `eg:"v1"`
|
Version string `eg:"v1"`
|
||||||
MethodName string `eg:"GetList"`
|
MethodName string `eg:"GetList"`
|
||||||
|
Comment string `eg:"GetList get list"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a apiItem) String() string {
|
func (a apiItem) String() string {
|
||||||
@ -21,3 +26,12 @@ func (a apiItem) String() string {
|
|||||||
a.Import, a.Module, a.Version, a.MethodName,
|
a.Import, a.Module, a.Version, a.MethodName,
|
||||||
}, ",")
|
}, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetComment returns the comment of apiItem.
|
||||||
|
func (a apiItem) GetComment() string {
|
||||||
|
if a.Comment == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
// format for handling comments
|
||||||
|
return fmt.Sprintf("\n// %s %s", a.MethodName, a.Comment)
|
||||||
|
}
|
||||||
|
|||||||
@ -17,9 +17,14 @@ import (
|
|||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getStructsNameInSrc retrieves all struct names
|
type structInfo struct {
|
||||||
|
structName string
|
||||||
|
comment string
|
||||||
|
}
|
||||||
|
|
||||||
|
// getStructsNameInSrc retrieves all struct names and comment
|
||||||
// that end in "Req" and have "g.Meta" in their body.
|
// that end in "Req" and have "g.Meta" in their body.
|
||||||
func (c CGenCtrl) getStructsNameInSrc(filePath string) (structsName []string, err error) {
|
func (c CGenCtrl) getStructsNameInSrc(filePath string) (structInfos []*structInfo, err error) {
|
||||||
var (
|
var (
|
||||||
fileContent = gfile.GetContents(filePath)
|
fileContent = gfile.GetContents(filePath)
|
||||||
fileSet = token.NewFileSet()
|
fileSet = token.NewFileSet()
|
||||||
@ -32,8 +37,8 @@ func (c CGenCtrl) getStructsNameInSrc(filePath string) (structsName []string, er
|
|||||||
|
|
||||||
ast.Inspect(node, func(n ast.Node) bool {
|
ast.Inspect(node, func(n ast.Node) bool {
|
||||||
if typeSpec, ok := n.(*ast.TypeSpec); ok {
|
if typeSpec, ok := n.(*ast.TypeSpec); ok {
|
||||||
methodName := typeSpec.Name.Name
|
structName := typeSpec.Name.Name
|
||||||
if !gstr.HasSuffix(methodName, "Req") {
|
if !gstr.HasSuffix(structName, "Req") {
|
||||||
// ignore struct name that do not end in "Req"
|
// ignore struct name that do not end in "Req"
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -46,7 +51,19 @@ func (c CGenCtrl) getStructsNameInSrc(filePath string) (structsName []string, er
|
|||||||
if !gstr.Contains(buf.String(), `g.Meta`) {
|
if !gstr.Contains(buf.String(), `g.Meta`) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
structsName = append(structsName, methodName)
|
|
||||||
|
comment := typeSpec.Doc.Text()
|
||||||
|
// remove the struct name from the comment
|
||||||
|
if gstr.HasPrefix(comment, structName) {
|
||||||
|
comment = gstr.TrimLeftStr(comment, structName, 1)
|
||||||
|
}
|
||||||
|
// remove the comment \n or space
|
||||||
|
comment = gstr.Trim(comment)
|
||||||
|
|
||||||
|
structInfos = append(structInfos, &structInfo{
|
||||||
|
structName: structName,
|
||||||
|
comment: comment,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
@ -39,15 +39,16 @@ func (c CGenCtrl) getApiItemsInSrc(apiModuleFolderPath string) (items []apiItem,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, methodName := range structsInfo {
|
for _, s := range structsInfo {
|
||||||
// remove end "Req"
|
// remove end "Req"
|
||||||
methodName = gstr.TrimRightStr(methodName, "Req", 1)
|
methodName := gstr.TrimRightStr(s.structName, "Req", 1)
|
||||||
item := apiItem{
|
item := apiItem{
|
||||||
Import: gstr.Trim(importPath, `"`),
|
Import: gstr.Trim(importPath, `"`),
|
||||||
FileName: gfile.Name(apiFileFolderPath),
|
FileName: gfile.Name(apiFileFolderPath),
|
||||||
Module: gfile.Basename(apiModuleFolderPath),
|
Module: gfile.Basename(apiModuleFolderPath),
|
||||||
Version: gfile.Basename(apiVersionFolderPath),
|
Version: gfile.Basename(apiVersionFolderPath),
|
||||||
MethodName: methodName,
|
MethodName: methodName,
|
||||||
|
Comment: s.comment,
|
||||||
}
|
}
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,10 +138,11 @@ func (c *controllerGenerator) doGenerateCtrlItem(dstModuleFolderPath string, ite
|
|||||||
|
|
||||||
if gfile.Exists(methodFilePath) {
|
if gfile.Exists(methodFilePath) {
|
||||||
content = gstr.ReplaceByMap(consts.TemplateGenCtrlControllerMethodFuncMerge, g.MapStrStr{
|
content = gstr.ReplaceByMap(consts.TemplateGenCtrlControllerMethodFuncMerge, g.MapStrStr{
|
||||||
"{Module}": item.Module,
|
"{Module}": item.Module,
|
||||||
"{CtrlName}": ctrlName,
|
"{CtrlName}": ctrlName,
|
||||||
"{Version}": item.Version,
|
"{Version}": item.Version,
|
||||||
"{MethodName}": item.MethodName,
|
"{MethodName}": item.MethodName,
|
||||||
|
"{MethodComment}": item.GetComment(),
|
||||||
})
|
})
|
||||||
|
|
||||||
if gstr.Contains(gfile.GetContents(methodFilePath), fmt.Sprintf(`func (c *%v) %v(`, ctrlName, item.MethodName)) {
|
if gstr.Contains(gfile.GetContents(methodFilePath), fmt.Sprintf(`func (c *%v) %v(`, ctrlName, item.MethodName)) {
|
||||||
@ -152,11 +153,12 @@ func (c *controllerGenerator) doGenerateCtrlItem(dstModuleFolderPath string, ite
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
content = gstr.ReplaceByMap(consts.TemplateGenCtrlControllerMethodFunc, g.MapStrStr{
|
content = gstr.ReplaceByMap(consts.TemplateGenCtrlControllerMethodFunc, g.MapStrStr{
|
||||||
"{Module}": item.Module,
|
"{Module}": item.Module,
|
||||||
"{ImportPath}": item.Import,
|
"{ImportPath}": item.Import,
|
||||||
"{CtrlName}": ctrlName,
|
"{CtrlName}": ctrlName,
|
||||||
"{Version}": item.Version,
|
"{Version}": item.Version,
|
||||||
"{MethodName}": item.MethodName,
|
"{MethodName}": item.MethodName,
|
||||||
|
"{MethodComment}": item.GetComment(),
|
||||||
})
|
})
|
||||||
if err = gfile.PutContents(methodFilePath, gstr.TrimLeft(content)); err != nil {
|
if err = gfile.PutContents(methodFilePath, gstr.TrimLeft(content)); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -192,10 +194,11 @@ func (c *controllerGenerator) doGenerateCtrlMergeItem(dstModuleFolderPath string
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctrl := gstr.TrimLeft(gstr.ReplaceByMap(consts.TemplateGenCtrlControllerMethodFuncMerge, g.MapStrStr{
|
ctrl := gstr.TrimLeft(gstr.ReplaceByMap(consts.TemplateGenCtrlControllerMethodFuncMerge, g.MapStrStr{
|
||||||
"{Module}": api.Module,
|
"{Module}": api.Module,
|
||||||
"{CtrlName}": fmt.Sprintf(`Controller%s`, gstr.UcFirst(api.Version)),
|
"{CtrlName}": fmt.Sprintf(`Controller%s`, gstr.UcFirst(api.Version)),
|
||||||
"{Version}": api.Version,
|
"{Version}": api.Version,
|
||||||
"{MethodName}": api.MethodName,
|
"{MethodName}": api.MethodName,
|
||||||
|
"{MethodComment}": api.GetComment(),
|
||||||
}))
|
}))
|
||||||
ctrlFileItem.controllers.WriteString(ctrl)
|
ctrlFileItem.controllers.WriteString(ctrl)
|
||||||
doneApiSet.Add(api.String())
|
doneApiSet.Add(api.String())
|
||||||
|
|||||||
@ -180,6 +180,7 @@ func (c *apiSdkGenerator) doGenerateSdkImplementer(
|
|||||||
"{Version}": item.Version,
|
"{Version}": item.Version,
|
||||||
"{MethodName}": item.MethodName,
|
"{MethodName}": item.MethodName,
|
||||||
"{ImplementerName}": implementerName,
|
"{ImplementerName}": implementerName,
|
||||||
|
"{MethodComment}": item.GetComment(),
|
||||||
}))
|
}))
|
||||||
implementerFileContent += "\n"
|
implementerFileContent += "\n"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,118 +11,83 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/olekukonko/tablewriter"
|
||||||
|
"github.com/olekukonko/tablewriter/renderer"
|
||||||
|
"github.com/olekukonko/tablewriter/tw"
|
||||||
"golang.org/x/mod/modfile"
|
"golang.org/x/mod/modfile"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/container/garray"
|
"github.com/gogf/gf/v2/container/garray"
|
||||||
|
"github.com/gogf/gf/v2/container/gset"
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/gogf/gf/v2/os/gproc"
|
"github.com/gogf/gf/v2/os/gproc"
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
"github.com/gogf/gf/v2/os/gview"
|
||||||
|
"github.com/gogf/gf/v2/text/gregex"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
"github.com/gogf/gf/v2/util/gtag"
|
|
||||||
|
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
|
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
type (
|
||||||
CGenDaoConfig = `gfcli.gen.dao`
|
CGenDao struct{}
|
||||||
CGenDaoUsage = `gf gen dao [OPTION]`
|
CGenDaoInput struct {
|
||||||
CGenDaoBrief = `automatically generate go files for dao/do/entity`
|
g.Meta `name:"dao" config:"{CGenDaoConfig}" usage:"{CGenDaoUsage}" brief:"{CGenDaoBrief}" eg:"{CGenDaoEg}" ad:"{CGenDaoAd}"`
|
||||||
CGenDaoEg = `
|
Path string `name:"path" short:"p" brief:"{CGenDaoBriefPath}" d:"internal"`
|
||||||
gf gen dao
|
Link string `name:"link" short:"l" brief:"{CGenDaoBriefLink}"`
|
||||||
gf gen dao -l "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
Tables string `name:"tables" short:"t" brief:"{CGenDaoBriefTables}"`
|
||||||
gf gen dao -p ./model -g user-center -t user,user_detail,user_login
|
TablesEx string `name:"tablesEx" short:"x" brief:"{CGenDaoBriefTablesEx}"`
|
||||||
gf gen dao -r user_
|
ShardingPattern []string `name:"shardingPattern" short:"sp" brief:"{CGenDaoBriefShardingPattern}"`
|
||||||
`
|
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"`
|
||||||
|
DoPath string `name:"doPath" short:"o" brief:"{CGenDaoBriefDoPath}" d:"model/do"`
|
||||||
|
EntityPath string `name:"entityPath" short:"e" brief:"{CGenDaoBriefEntityPath}" d:"model/entity"`
|
||||||
|
TplDaoIndexPath string `name:"tplDaoIndexPath" short:"t1" brief:"{CGenDaoBriefTplDaoIndexPath}"`
|
||||||
|
TplDaoInternalPath string `name:"tplDaoInternalPath" short:"t2" brief:"{CGenDaoBriefTplDaoInternalPath}"`
|
||||||
|
TplDaoDoPath string `name:"tplDaoDoPath" short:"t3" brief:"{CGenDaoBriefTplDaoDoPathPath}"`
|
||||||
|
TplDaoEntityPath string `name:"tplDaoEntityPath" short:"t4" brief:"{CGenDaoBriefTplDaoEntityPath}"`
|
||||||
|
StdTime bool `name:"stdTime" short:"s" brief:"{CGenDaoBriefStdTime}" orphan:"true"`
|
||||||
|
WithTime bool `name:"withTime" short:"w" brief:"{CGenDaoBriefWithTime}" orphan:"true"`
|
||||||
|
GJsonSupport bool `name:"gJsonSupport" short:"n" brief:"{CGenDaoBriefGJsonSupport}" orphan:"true"`
|
||||||
|
OverwriteDao bool `name:"overwriteDao" short:"v" brief:"{CGenDaoBriefOverwriteDao}" orphan:"true"`
|
||||||
|
DescriptionTag bool `name:"descriptionTag" short:"c" brief:"{CGenDaoBriefDescriptionTag}" orphan:"true"`
|
||||||
|
NoJsonTag bool `name:"noJsonTag" short:"k" brief:"{CGenDaoBriefNoJsonTag}" orphan:"true"`
|
||||||
|
NoModelComment bool `name:"noModelComment" short:"m" brief:"{CGenDaoBriefNoModelComment}" orphan:"true"`
|
||||||
|
Clear bool `name:"clear" short:"a" brief:"{CGenDaoBriefClear}" orphan:"true"`
|
||||||
|
|
||||||
CGenDaoAd = `
|
TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenDaoBriefTypeMapping}" orphan:"true"`
|
||||||
CONFIGURATION SUPPORT
|
FieldMapping map[DBTableFieldName]CustomAttributeType `name:"fieldMapping" short:"fm" brief:"{CGenDaoBriefFieldMapping}" orphan:"true"`
|
||||||
Options are also supported by configuration file.
|
|
||||||
It's suggested using configuration file instead of command line arguments making producing.
|
|
||||||
The configuration node name is "gfcli.gen.dao", which also supports multiple databases, for example(config.yaml):
|
|
||||||
gfcli:
|
|
||||||
gen:
|
|
||||||
dao:
|
|
||||||
- link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
|
||||||
tables: "order,products"
|
|
||||||
jsonCase: "CamelLower"
|
|
||||||
- link: "mysql:root:12345678@tcp(127.0.0.1:3306)/primary"
|
|
||||||
path: "./my-app"
|
|
||||||
prefix: "primary_"
|
|
||||||
tables: "user, userDetail"
|
|
||||||
typeMapping:
|
|
||||||
decimal:
|
|
||||||
type: decimal.Decimal
|
|
||||||
import: github.com/shopspring/decimal
|
|
||||||
numeric:
|
|
||||||
type: string
|
|
||||||
fieldMapping:
|
|
||||||
table_name.field_name:
|
|
||||||
type: decimal.Decimal
|
|
||||||
import: github.com/shopspring/decimal
|
|
||||||
`
|
|
||||||
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`
|
|
||||||
CGenDaoBriefFieldMapping = `custom local type mapping for generated struct attributes relevant to specific 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"
|
|
||||||
`
|
|
||||||
CGenDaoBriefJsonCase = `
|
|
||||||
generated json tag case for model struct, cases are as follows:
|
|
||||||
| Case | Example |
|
|
||||||
|---------------- |--------------------|
|
|
||||||
| Camel | AnyKindOfString |
|
|
||||||
| CamelLower | anyKindOfString | default
|
|
||||||
| Snake | any_kind_of_string |
|
|
||||||
| SnakeScreaming | ANY_KIND_OF_STRING |
|
|
||||||
| SnakeFirstUpper | rgb_code_md5 |
|
|
||||||
| Kebab | any-kind-of-string |
|
|
||||||
| KebabScreaming | ANY-KIND-OF-STRING |
|
|
||||||
`
|
|
||||||
CGenDaoBriefTplDaoIndexPath = `template file path for dao index file`
|
|
||||||
CGenDaoBriefTplDaoInternalPath = `template file path for dao internal file`
|
|
||||||
CGenDaoBriefTplDaoDoPathPath = `template file path for dao do file`
|
|
||||||
CGenDaoBriefTplDaoEntityPath = `template file path for dao entity file`
|
|
||||||
|
|
||||||
tplVarTableName = `{TplTableName}`
|
// internal usage purpose.
|
||||||
tplVarTableNameCamelCase = `{TplTableNameCamelCase}`
|
genItems *CGenDaoInternalGenItems
|
||||||
tplVarTableNameCamelLowerCase = `{TplTableNameCamelLowerCase}`
|
}
|
||||||
tplVarPackageImports = `{TplPackageImports}`
|
CGenDaoOutput struct{}
|
||||||
tplVarImportPrefix = `{TplImportPrefix}`
|
|
||||||
tplVarStructDefine = `{TplStructDefine}`
|
CGenDaoInternalInput struct {
|
||||||
tplVarColumnDefine = `{TplColumnDefine}`
|
CGenDaoInput
|
||||||
tplVarColumnNames = `{TplColumnNames}`
|
DB gdb.DB
|
||||||
tplVarGroupName = `{TplGroupName}`
|
TableNames []string
|
||||||
tplVarDatetimeStr = `{TplDatetimeStr}`
|
NewTableNames []string
|
||||||
tplVarCreatedAtDatetimeStr = `{TplCreatedAtDatetimeStr}`
|
ShardingTableSet *gset.StrSet
|
||||||
tplVarPackageName = `{TplPackageName}`
|
}
|
||||||
|
DBTableFieldName = string
|
||||||
|
DBFieldTypeName = string
|
||||||
|
CustomAttributeType struct {
|
||||||
|
Type string `brief:"custom attribute type name"`
|
||||||
|
Import string `brief:"custom import for this type"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
createdAt = gtime.Now()
|
createdAt = gtime.Now()
|
||||||
|
tplView = gview.New()
|
||||||
defaultTypeMapping = map[DBFieldTypeName]CustomAttributeType{
|
defaultTypeMapping = map[DBFieldTypeName]CustomAttributeType{
|
||||||
"decimal": {
|
"decimal": {
|
||||||
Type: "float64",
|
Type: "float64",
|
||||||
@ -137,97 +102,20 @@ var (
|
|||||||
Type: "float64",
|
Type: "float64",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
// tablewriter Options
|
||||||
gtag.Sets(g.MapStrStr{
|
twRenderer = tablewriter.WithRenderer(renderer.NewBlueprint(tw.Rendition{
|
||||||
`CGenDaoConfig`: CGenDaoConfig,
|
Borders: tw.Border{Top: tw.Off, Bottom: tw.Off, Left: tw.Off, Right: tw.Off},
|
||||||
`CGenDaoUsage`: CGenDaoUsage,
|
Settings: tw.Settings{
|
||||||
`CGenDaoBrief`: CGenDaoBrief,
|
Separators: tw.Separators{BetweenRows: tw.Off, BetweenColumns: tw.Off},
|
||||||
`CGenDaoEg`: CGenDaoEg,
|
},
|
||||||
`CGenDaoAd`: CGenDaoAd,
|
Symbols: tw.NewSymbols(tw.StyleASCII),
|
||||||
`CGenDaoBriefPath`: CGenDaoBriefPath,
|
}))
|
||||||
`CGenDaoBriefLink`: CGenDaoBriefLink,
|
twConfig = tablewriter.WithConfig(tablewriter.Config{
|
||||||
`CGenDaoBriefTables`: CGenDaoBriefTables,
|
Row: tw.CellConfig{
|
||||||
`CGenDaoBriefTablesEx`: CGenDaoBriefTablesEx,
|
Formatting: tw.CellFormatting{AutoWrap: tw.WrapNone},
|
||||||
`CGenDaoBriefPrefix`: CGenDaoBriefPrefix,
|
},
|
||||||
`CGenDaoBriefRemovePrefix`: CGenDaoBriefRemovePrefix,
|
|
||||||
`CGenDaoBriefRemoveFieldPrefix`: CGenDaoBriefRemoveFieldPrefix,
|
|
||||||
`CGenDaoBriefStdTime`: CGenDaoBriefStdTime,
|
|
||||||
`CGenDaoBriefWithTime`: CGenDaoBriefWithTime,
|
|
||||||
`CGenDaoBriefDaoPath`: CGenDaoBriefDaoPath,
|
|
||||||
`CGenDaoBriefDoPath`: CGenDaoBriefDoPath,
|
|
||||||
`CGenDaoBriefEntityPath`: CGenDaoBriefEntityPath,
|
|
||||||
`CGenDaoBriefGJsonSupport`: CGenDaoBriefGJsonSupport,
|
|
||||||
`CGenDaoBriefImportPrefix`: CGenDaoBriefImportPrefix,
|
|
||||||
`CGenDaoBriefOverwriteDao`: CGenDaoBriefOverwriteDao,
|
|
||||||
`CGenDaoBriefModelFile`: CGenDaoBriefModelFile,
|
|
||||||
`CGenDaoBriefModelFileForDao`: CGenDaoBriefModelFileForDao,
|
|
||||||
`CGenDaoBriefDescriptionTag`: CGenDaoBriefDescriptionTag,
|
|
||||||
`CGenDaoBriefNoJsonTag`: CGenDaoBriefNoJsonTag,
|
|
||||||
`CGenDaoBriefNoModelComment`: CGenDaoBriefNoModelComment,
|
|
||||||
`CGenDaoBriefClear`: CGenDaoBriefClear,
|
|
||||||
`CGenDaoBriefTypeMapping`: CGenDaoBriefTypeMapping,
|
|
||||||
`CGenDaoBriefFieldMapping`: CGenDaoBriefFieldMapping,
|
|
||||||
`CGenDaoBriefGroup`: CGenDaoBriefGroup,
|
|
||||||
`CGenDaoBriefJsonCase`: CGenDaoBriefJsonCase,
|
|
||||||
`CGenDaoBriefTplDaoIndexPath`: CGenDaoBriefTplDaoIndexPath,
|
|
||||||
`CGenDaoBriefTplDaoInternalPath`: CGenDaoBriefTplDaoInternalPath,
|
|
||||||
`CGenDaoBriefTplDaoDoPathPath`: CGenDaoBriefTplDaoDoPathPath,
|
|
||||||
`CGenDaoBriefTplDaoEntityPath`: CGenDaoBriefTplDaoEntityPath,
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
|
||||||
CGenDao struct{}
|
|
||||||
CGenDaoInput struct {
|
|
||||||
g.Meta `name:"dao" config:"{CGenDaoConfig}" usage:"{CGenDaoUsage}" brief:"{CGenDaoBrief}" eg:"{CGenDaoEg}" ad:"{CGenDaoAd}"`
|
|
||||||
Path string `name:"path" short:"p" brief:"{CGenDaoBriefPath}" d:"internal"`
|
|
||||||
Link string `name:"link" short:"l" brief:"{CGenDaoBriefLink}"`
|
|
||||||
Tables string `name:"tables" short:"t" brief:"{CGenDaoBriefTables}"`
|
|
||||||
TablesEx string `name:"tablesEx" short:"x" brief:"{CGenDaoBriefTablesEx}"`
|
|
||||||
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"`
|
|
||||||
DoPath string `name:"doPath" short:"o" brief:"{CGenDaoBriefDoPath}" d:"model/do"`
|
|
||||||
EntityPath string `name:"entityPath" short:"e" brief:"{CGenDaoBriefEntityPath}" d:"model/entity"`
|
|
||||||
TplDaoIndexPath string `name:"tplDaoIndexPath" short:"t1" brief:"{CGenDaoBriefTplDaoIndexPath}"`
|
|
||||||
TplDaoInternalPath string `name:"tplDaoInternalPath" short:"t2" brief:"{CGenDaoBriefTplDaoInternalPath}"`
|
|
||||||
TplDaoDoPath string `name:"tplDaoDoPath" short:"t3" brief:"{CGenDaoBriefTplDaoDoPathPath}"`
|
|
||||||
TplDaoEntityPath string `name:"tplDaoEntityPath" short:"t4" brief:"{CGenDaoBriefTplDaoEntityPath}"`
|
|
||||||
StdTime bool `name:"stdTime" short:"s" brief:"{CGenDaoBriefStdTime}" orphan:"true"`
|
|
||||||
WithTime bool `name:"withTime" short:"w" brief:"{CGenDaoBriefWithTime}" orphan:"true"`
|
|
||||||
GJsonSupport bool `name:"gJsonSupport" short:"n" brief:"{CGenDaoBriefGJsonSupport}" orphan:"true"`
|
|
||||||
OverwriteDao bool `name:"overwriteDao" short:"v" brief:"{CGenDaoBriefOverwriteDao}" orphan:"true"`
|
|
||||||
DescriptionTag bool `name:"descriptionTag" short:"c" brief:"{CGenDaoBriefDescriptionTag}" orphan:"true"`
|
|
||||||
NoJsonTag bool `name:"noJsonTag" short:"k" brief:"{CGenDaoBriefNoJsonTag}" orphan:"true"`
|
|
||||||
NoModelComment bool `name:"noModelComment" short:"m" brief:"{CGenDaoBriefNoModelComment}" orphan:"true"`
|
|
||||||
Clear bool `name:"clear" short:"a" brief:"{CGenDaoBriefClear}" orphan:"true"`
|
|
||||||
|
|
||||||
TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenDaoBriefTypeMapping}" orphan:"true"`
|
|
||||||
FieldMapping map[DBTableFieldName]CustomAttributeType `name:"fieldMapping" short:"fm" brief:"{CGenDaoBriefFieldMapping}" orphan:"true"`
|
|
||||||
|
|
||||||
// internal usage purpose.
|
|
||||||
genItems *CGenDaoInternalGenItems
|
|
||||||
}
|
|
||||||
CGenDaoOutput struct{}
|
|
||||||
|
|
||||||
CGenDaoInternalInput struct {
|
|
||||||
CGenDaoInput
|
|
||||||
DB gdb.DB
|
|
||||||
TableNames []string
|
|
||||||
NewTableNames []string
|
|
||||||
}
|
|
||||||
DBTableFieldName = string
|
|
||||||
DBFieldTypeName = string
|
|
||||||
CustomAttributeType struct {
|
|
||||||
Type string `brief:"custom attribute type name"`
|
|
||||||
Import string `brief:"custom import for this type"`
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c CGenDao) Dao(ctx context.Context, in CGenDaoInput) (out *CGenDaoOutput, err error) {
|
func (c CGenDao) Dao(ctx context.Context, in CGenDaoInput) (out *CGenDaoOutput, err error) {
|
||||||
@ -274,9 +162,12 @@ func doGenDaoForArray(ctx context.Context, index int, in CGenDaoInput) {
|
|||||||
// It uses user passed database configuration.
|
// It uses user passed database configuration.
|
||||||
if in.Link != "" {
|
if in.Link != "" {
|
||||||
var tempGroup = gtime.TimestampNanoStr()
|
var tempGroup = gtime.TimestampNanoStr()
|
||||||
gdb.AddConfigNode(tempGroup, gdb.ConfigNode{
|
err = gdb.AddConfigNode(tempGroup, gdb.ConfigNode{
|
||||||
Link: in.Link,
|
Link: in.Link,
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
mlog.Fatalf(`database configuration failed: %+v`, err)
|
||||||
|
}
|
||||||
if db, err = gdb.Instance(tempGroup); err != nil {
|
if db, err = gdb.Instance(tempGroup); err != nil {
|
||||||
mlog.Fatalf(`database initialization failed: %+v`, err)
|
mlog.Fatalf(`database initialization failed: %+v`, err)
|
||||||
}
|
}
|
||||||
@ -299,8 +190,29 @@ func doGenDaoForArray(ctx context.Context, index int, in CGenDaoInput) {
|
|||||||
// Table excluding.
|
// Table excluding.
|
||||||
if in.TablesEx != "" {
|
if in.TablesEx != "" {
|
||||||
array := garray.NewStrArrayFrom(tableNames)
|
array := garray.NewStrArrayFrom(tableNames)
|
||||||
for _, v := range gstr.SplitAndTrim(in.TablesEx, ",") {
|
for _, p := range gstr.SplitAndTrim(in.TablesEx, ",") {
|
||||||
array.RemoveValue(v)
|
if gstr.Contains(p, "*") || gstr.Contains(p, "?") {
|
||||||
|
p = gstr.ReplaceByMap(p, map[string]string{
|
||||||
|
"\r": "",
|
||||||
|
"\n": "",
|
||||||
|
})
|
||||||
|
p = gstr.ReplaceByMap(p, map[string]string{
|
||||||
|
"*": "\r",
|
||||||
|
"?": "\n",
|
||||||
|
})
|
||||||
|
p = gregex.Quote(p)
|
||||||
|
p = gstr.ReplaceByMap(p, map[string]string{
|
||||||
|
"\r": ".*",
|
||||||
|
"\n": ".",
|
||||||
|
})
|
||||||
|
for _, v := range array.Clone().Slice() {
|
||||||
|
if gregex.IsMatchString(p, v) {
|
||||||
|
array.RemoveValue(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
array.RemoveValue(p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tableNames = array.Slice()
|
tableNames = array.Slice()
|
||||||
}
|
}
|
||||||
@ -317,24 +229,55 @@ func doGenDaoForArray(ctx context.Context, index int, in CGenDaoInput) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generating dao & model go files one by one according to given table name.
|
// Generating dao & model go files one by one according to given table name.
|
||||||
newTableNames := make([]string, len(tableNames))
|
var (
|
||||||
|
newTableNames = make([]string, len(tableNames))
|
||||||
|
shardingNewTableSet = gset.NewStrSet()
|
||||||
|
)
|
||||||
for i, tableName := range tableNames {
|
for i, tableName := range tableNames {
|
||||||
newTableName := tableName
|
newTableName := tableName
|
||||||
for _, v := range removePrefixArray {
|
for _, v := range removePrefixArray {
|
||||||
newTableName = gstr.TrimLeftStr(newTableName, v, 1)
|
newTableName = gstr.TrimLeftStr(newTableName, v, 1)
|
||||||
}
|
}
|
||||||
|
if len(in.ShardingPattern) > 0 {
|
||||||
|
for _, pattern := range in.ShardingPattern {
|
||||||
|
var (
|
||||||
|
match []string
|
||||||
|
regPattern = gstr.Replace(pattern, "?", `(.+)`)
|
||||||
|
)
|
||||||
|
match, err = gregex.MatchString(regPattern, newTableName)
|
||||||
|
if err != nil {
|
||||||
|
mlog.Fatalf(`invalid sharding pattern "%s": %+v`, pattern, err)
|
||||||
|
}
|
||||||
|
if len(match) < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newTableName = gstr.Replace(pattern, "?", "")
|
||||||
|
newTableName = gstr.Trim(newTableName, `_.-`)
|
||||||
|
if shardingNewTableSet.Contains(newTableName) {
|
||||||
|
tableNames[i] = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Add prefix to sharding table name, if not, the isSharding check would not match.
|
||||||
|
shardingNewTableSet.Add(in.Prefix + newTableName)
|
||||||
|
}
|
||||||
|
}
|
||||||
newTableName = in.Prefix + newTableName
|
newTableName = in.Prefix + newTableName
|
||||||
newTableNames[i] = newTableName
|
if tableNames[i] != "" {
|
||||||
|
// If shardingNewTableSet contains newTableName (tableName is empty), it should not be added to tableNames, make it empty and filter later.
|
||||||
|
newTableNames[i] = newTableName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
tableNames = garray.NewStrArrayFrom(tableNames).FilterEmpty().Slice()
|
||||||
|
newTableNames = garray.NewStrArrayFrom(newTableNames).FilterEmpty().Slice() // Filter empty table names. make sure that newTableNames and tableNames have the same length.
|
||||||
in.genItems.Scale()
|
in.genItems.Scale()
|
||||||
|
|
||||||
// Dao: index and internal.
|
// Dao: index and internal.
|
||||||
generateDao(ctx, CGenDaoInternalInput{
|
generateDao(ctx, CGenDaoInternalInput{
|
||||||
CGenDaoInput: in,
|
CGenDaoInput: in,
|
||||||
DB: db,
|
DB: db,
|
||||||
TableNames: tableNames,
|
TableNames: tableNames,
|
||||||
NewTableNames: newTableNames,
|
NewTableNames: newTableNames,
|
||||||
|
ShardingTableSet: shardingNewTableSet,
|
||||||
})
|
})
|
||||||
// Do.
|
// Do.
|
||||||
generateDo(ctx, CGenDaoInternalInput{
|
generateDo(ctx, CGenDaoInternalInput{
|
||||||
@ -407,13 +350,15 @@ func getImportPartContent(ctx context.Context, source string, isDo bool, appendI
|
|||||||
return packageImportsStr
|
return packageImportsStr
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceDefaultVar(in CGenDaoInternalInput, origin string) string {
|
func assignDefaultVar(view *gview.View, in CGenDaoInternalInput) {
|
||||||
var tplCreatedAtDatetimeStr string
|
var (
|
||||||
var tplDatetimeStr string = createdAt.String()
|
tplCreatedAtDatetimeStr string
|
||||||
|
tplDatetimeStr = createdAt.String()
|
||||||
|
)
|
||||||
if in.WithTime {
|
if in.WithTime {
|
||||||
tplCreatedAtDatetimeStr = fmt.Sprintf(`Created at %s`, tplDatetimeStr)
|
tplCreatedAtDatetimeStr = fmt.Sprintf(`Created at %s`, tplDatetimeStr)
|
||||||
}
|
}
|
||||||
return gstr.ReplaceByMap(origin, g.MapStrStr{
|
view.Assigns(g.Map{
|
||||||
tplVarDatetimeStr: tplDatetimeStr,
|
tplVarDatetimeStr: tplDatetimeStr,
|
||||||
tplVarCreatedAtDatetimeStr: tplCreatedAtDatetimeStr,
|
tplVarCreatedAtDatetimeStr: tplCreatedAtDatetimeStr,
|
||||||
})
|
})
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
|
"github.com/gogf/gf/v2/os/gview"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
|
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
|
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
|
||||||
@ -32,22 +33,30 @@ func generateDao(ctx context.Context, in CGenDaoInternalInput) {
|
|||||||
)
|
)
|
||||||
in.genItems.AppendDirPath(dirPathDao)
|
in.genItems.AppendDirPath(dirPathDao)
|
||||||
for i := 0; i < len(in.TableNames); i++ {
|
for i := 0; i < len(in.TableNames); i++ {
|
||||||
|
var (
|
||||||
|
realTableName = in.TableNames[i]
|
||||||
|
newTableName = in.NewTableNames[i]
|
||||||
|
)
|
||||||
generateDaoSingle(ctx, generateDaoSingleInput{
|
generateDaoSingle(ctx, generateDaoSingleInput{
|
||||||
CGenDaoInternalInput: in,
|
CGenDaoInternalInput: in,
|
||||||
TableName: in.TableNames[i],
|
TableName: realTableName,
|
||||||
NewTableName: in.NewTableNames[i],
|
NewTableName: newTableName,
|
||||||
DirPathDao: dirPathDao,
|
DirPathDao: dirPathDao,
|
||||||
DirPathDaoInternal: dirPathDaoInternal,
|
DirPathDaoInternal: dirPathDaoInternal,
|
||||||
|
IsSharding: in.ShardingTableSet.Contains(newTableName),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type generateDaoSingleInput struct {
|
type generateDaoSingleInput struct {
|
||||||
CGenDaoInternalInput
|
CGenDaoInternalInput
|
||||||
TableName string // TableName specifies the table name of the table.
|
// TableName specifies the table name of the table.
|
||||||
NewTableName string // NewTableName specifies the prefix-stripped name of the table.
|
TableName string
|
||||||
|
// NewTableName specifies the prefix-stripped or custom edited name of the table.
|
||||||
|
NewTableName string
|
||||||
DirPathDao string
|
DirPathDao string
|
||||||
DirPathDaoInternal string
|
DirPathDaoInternal string
|
||||||
|
IsSharding bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// generateDaoSingle generates the dao and model content of given table.
|
// generateDaoSingle generates the dao and model content of given table.
|
||||||
@ -109,17 +118,27 @@ func generateDaoIndex(in generateDaoIndexInput) {
|
|||||||
// It should add path to result slice whenever it would generate the path file or not.
|
// It should add path to result slice whenever it would generate the path file or not.
|
||||||
in.genItems.AppendGeneratedFilePath(path)
|
in.genItems.AppendGeneratedFilePath(path)
|
||||||
if in.OverwriteDao || !gfile.Exists(path) {
|
if in.OverwriteDao || !gfile.Exists(path) {
|
||||||
indexContent := gstr.ReplaceByMap(
|
var (
|
||||||
getTemplateFromPathOrDefault(in.TplDaoIndexPath, consts.TemplateGenDaoIndexContent),
|
ctx = context.Background()
|
||||||
g.MapStrStr{
|
tplContent = getTemplateFromPathOrDefault(
|
||||||
tplVarImportPrefix: in.ImportPrefix,
|
in.TplDaoIndexPath, consts.TemplateGenDaoIndexContent,
|
||||||
tplVarTableName: in.TableName,
|
)
|
||||||
tplVarTableNameCamelCase: in.TableNameCamelCase,
|
)
|
||||||
tplVarTableNameCamelLowerCase: in.TableNameCamelLowerCase,
|
tplView.ClearAssigns()
|
||||||
tplVarPackageName: filepath.Base(in.DaoPath),
|
tplView.Assigns(gview.Params{
|
||||||
})
|
tplVarTableSharding: in.IsSharding,
|
||||||
indexContent = replaceDefaultVar(in.CGenDaoInternalInput, indexContent)
|
tplVarTableShardingPrefix: in.NewTableName + "_",
|
||||||
if err := gfile.PutContents(path, strings.TrimSpace(indexContent)); err != nil {
|
tplVarImportPrefix: in.ImportPrefix,
|
||||||
|
tplVarTableName: in.TableName,
|
||||||
|
tplVarTableNameCamelCase: in.TableNameCamelCase,
|
||||||
|
tplVarTableNameCamelLowerCase: in.TableNameCamelLowerCase,
|
||||||
|
tplVarPackageName: filepath.Base(in.DaoPath),
|
||||||
|
})
|
||||||
|
indexContent, err := tplView.ParseContent(ctx, tplContent)
|
||||||
|
if err != nil {
|
||||||
|
mlog.Fatalf("parsing template content failed: %v", err)
|
||||||
|
}
|
||||||
|
if err = gfile.PutContents(path, strings.TrimSpace(indexContent)); err != nil {
|
||||||
mlog.Fatalf("writing content to '%s' failed: %v", path, err)
|
mlog.Fatalf("writing content to '%s' failed: %v", path, err)
|
||||||
} else {
|
} else {
|
||||||
utils.GoFmt(path)
|
utils.GoFmt(path)
|
||||||
@ -138,20 +157,29 @@ type generateDaoInternalInput struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generateDaoInternal(in generateDaoInternalInput) {
|
func generateDaoInternal(in generateDaoInternalInput) {
|
||||||
|
var (
|
||||||
|
ctx = context.Background()
|
||||||
|
removeFieldPrefixArray = gstr.SplitAndTrim(in.RemoveFieldPrefix, ",")
|
||||||
|
tplContent = getTemplateFromPathOrDefault(
|
||||||
|
in.TplDaoInternalPath, consts.TemplateGenDaoInternalContent,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
tplView.ClearAssigns()
|
||||||
|
tplView.Assigns(gview.Params{
|
||||||
|
tplVarImportPrefix: in.ImportPrefix,
|
||||||
|
tplVarTableName: in.TableName,
|
||||||
|
tplVarGroupName: in.Group,
|
||||||
|
tplVarTableNameCamelCase: in.TableNameCamelCase,
|
||||||
|
tplVarTableNameCamelLowerCase: in.TableNameCamelLowerCase,
|
||||||
|
tplVarColumnDefine: gstr.Trim(generateColumnDefinitionForDao(in.FieldMap, removeFieldPrefixArray)),
|
||||||
|
tplVarColumnNames: gstr.Trim(generateColumnNamesForDao(in.FieldMap, removeFieldPrefixArray)),
|
||||||
|
})
|
||||||
|
assignDefaultVar(tplView, in.CGenDaoInternalInput)
|
||||||
|
modelContent, err := tplView.ParseContent(ctx, tplContent)
|
||||||
|
if err != nil {
|
||||||
|
mlog.Fatalf("parsing template content failed: %v", err)
|
||||||
|
}
|
||||||
path := filepath.FromSlash(gfile.Join(in.DirPathDaoInternal, in.FileName+".go"))
|
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{
|
|
||||||
tplVarImportPrefix: in.ImportPrefix,
|
|
||||||
tplVarTableName: in.TableName,
|
|
||||||
tplVarGroupName: in.Group,
|
|
||||||
tplVarTableNameCamelCase: in.TableNameCamelCase,
|
|
||||||
tplVarTableNameCamelLowerCase: in.TableNameCamelLowerCase,
|
|
||||||
tplVarColumnDefine: gstr.Trim(generateColumnDefinitionForDao(in.FieldMap, removeFieldPrefixArray)),
|
|
||||||
tplVarColumnNames: gstr.Trim(generateColumnNamesForDao(in.FieldMap, removeFieldPrefixArray)),
|
|
||||||
})
|
|
||||||
modelContent = replaceDefaultVar(in.CGenDaoInternalInput, modelContent)
|
|
||||||
in.genItems.AppendGeneratedFilePath(path)
|
in.genItems.AppendGeneratedFilePath(path)
|
||||||
if err := gfile.PutContents(path, strings.TrimSpace(modelContent)); err != nil {
|
if err := gfile.PutContents(path, strings.TrimSpace(modelContent)); err != nil {
|
||||||
mlog.Fatalf("writing content to '%s' failed: %v", path, err)
|
mlog.Fatalf("writing content to '%s' failed: %v", path, err)
|
||||||
@ -183,13 +211,9 @@ func generateColumnNamesForDao(fieldMap map[string]*gdb.TableField, removeFieldP
|
|||||||
fmt.Sprintf(` #"%s",`, field.Name),
|
fmt.Sprintf(` #"%s",`, field.Name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tw := tablewriter.NewWriter(buffer)
|
table := tablewriter.NewTable(buffer, twRenderer, twConfig)
|
||||||
tw.SetBorder(false)
|
table.Bulk(array)
|
||||||
tw.SetRowLine(false)
|
table.Render()
|
||||||
tw.SetAutoWrapText(false)
|
|
||||||
tw.SetColumnSeparator("")
|
|
||||||
tw.AppendBulk(array)
|
|
||||||
tw.Render()
|
|
||||||
namesContent := buffer.String()
|
namesContent := buffer.String()
|
||||||
// Let's do this hack of table writer for indent!
|
// Let's do this hack of table writer for indent!
|
||||||
namesContent = gstr.Replace(namesContent, " #", "")
|
namesContent = gstr.Replace(namesContent, " #", "")
|
||||||
@ -224,13 +248,9 @@ func generateColumnDefinitionForDao(fieldMap map[string]*gdb.TableField, removeF
|
|||||||
" #" + fmt.Sprintf(`// %s`, comment),
|
" #" + fmt.Sprintf(`// %s`, comment),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tw := tablewriter.NewWriter(buffer)
|
table := tablewriter.NewTable(buffer, twRenderer, twConfig)
|
||||||
tw.SetBorder(false)
|
table.Bulk(array)
|
||||||
tw.SetRowLine(false)
|
table.Render()
|
||||||
tw.SetAutoWrapText(false)
|
|
||||||
tw.SetColumnSeparator("")
|
|
||||||
tw.AppendBulk(array)
|
|
||||||
tw.Render()
|
|
||||||
defineContent := buffer.String()
|
defineContent := buffer.String()
|
||||||
// Let's do this hack of table writer for indent!
|
// Let's do this hack of table writer for indent!
|
||||||
defineContent = gstr.Replace(defineContent, " #", "")
|
defineContent = gstr.Replace(defineContent, " #", "")
|
||||||
|
|||||||
@ -12,8 +12,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
|
"github.com/gogf/gf/v2/os/gview"
|
||||||
"github.com/gogf/gf/v2/text/gregex"
|
"github.com/gogf/gf/v2/text/gregex"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
|
|
||||||
@ -45,14 +45,14 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
|
|||||||
IsDo: true,
|
IsDo: true,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
// replace all types to interface{}.
|
// replace all types to any.
|
||||||
structDefinition, _ = gregex.ReplaceStringFuncMatch(
|
structDefinition, _ = gregex.ReplaceStringFuncMatch(
|
||||||
"([A-Z]\\w*?)\\s+([\\w\\*\\.]+?)\\s+(//)",
|
"([A-Z]\\w*?)\\s+([\\w\\*\\.]+?)\\s+(//)",
|
||||||
structDefinition,
|
structDefinition,
|
||||||
func(match []string) string {
|
func(match []string) string {
|
||||||
// If the type is already a pointer/slice/map, it does nothing.
|
// If the type is already a pointer/slice/map, it does nothing.
|
||||||
if !gstr.HasPrefix(match[2], "*") && !gstr.HasPrefix(match[2], "[]") && !gstr.HasPrefix(match[2], "map") {
|
if !gstr.HasPrefix(match[2], "*") && !gstr.HasPrefix(match[2], "[]") && !gstr.HasPrefix(match[2], "map") {
|
||||||
return fmt.Sprintf(`%s interface{} %s`, match[1], match[3])
|
return fmt.Sprintf(`%s any %s`, match[1], match[3])
|
||||||
}
|
}
|
||||||
return match[0]
|
return match[0]
|
||||||
},
|
},
|
||||||
@ -78,16 +78,23 @@ func generateDo(ctx context.Context, in CGenDaoInternalInput) {
|
|||||||
func generateDoContent(
|
func generateDoContent(
|
||||||
ctx context.Context, in CGenDaoInternalInput, tableName, tableNameCamelCase, structDefine string,
|
ctx context.Context, in CGenDaoInternalInput, tableName, tableNameCamelCase, structDefine string,
|
||||||
) string {
|
) string {
|
||||||
doContent := gstr.ReplaceByMap(
|
var (
|
||||||
getTemplateFromPathOrDefault(in.TplDaoDoPath, consts.TemplateGenDaoDoContent),
|
tplContent = getTemplateFromPathOrDefault(
|
||||||
g.MapStrStr{
|
in.TplDaoDoPath, consts.TemplateGenDaoDoContent,
|
||||||
tplVarTableName: tableName,
|
)
|
||||||
tplVarPackageImports: getImportPartContent(ctx, structDefine, true, nil),
|
|
||||||
tplVarTableNameCamelCase: tableNameCamelCase,
|
|
||||||
tplVarStructDefine: structDefine,
|
|
||||||
tplVarPackageName: filepath.Base(in.DoPath),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
doContent = replaceDefaultVar(in, doContent)
|
tplView.ClearAssigns()
|
||||||
|
tplView.Assigns(gview.Params{
|
||||||
|
tplVarTableName: tableName,
|
||||||
|
tplVarPackageImports: getImportPartContent(ctx, structDefine, true, nil),
|
||||||
|
tplVarTableNameCamelCase: tableNameCamelCase,
|
||||||
|
tplVarStructDefine: structDefine,
|
||||||
|
tplVarPackageName: filepath.Base(in.DoPath),
|
||||||
|
})
|
||||||
|
assignDefaultVar(tplView, in)
|
||||||
|
doContent, err := tplView.ParseContent(ctx, tplContent)
|
||||||
|
if err != nil {
|
||||||
|
mlog.Fatalf("parsing template content failed: %v", err)
|
||||||
|
}
|
||||||
return doContent
|
return doContent
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,8 +11,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
|
"github.com/gogf/gf/v2/os/gview"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
|
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
|
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
|
||||||
@ -63,16 +63,23 @@ func generateEntity(ctx context.Context, in CGenDaoInternalInput) {
|
|||||||
func generateEntityContent(
|
func generateEntityContent(
|
||||||
ctx context.Context, in CGenDaoInternalInput, tableName, tableNameCamelCase, structDefine string, appendImports []string,
|
ctx context.Context, in CGenDaoInternalInput, tableName, tableNameCamelCase, structDefine string, appendImports []string,
|
||||||
) string {
|
) string {
|
||||||
entityContent := gstr.ReplaceByMap(
|
var (
|
||||||
getTemplateFromPathOrDefault(in.TplDaoEntityPath, consts.TemplateGenDaoEntityContent),
|
tplContent = getTemplateFromPathOrDefault(
|
||||||
g.MapStrStr{
|
in.TplDaoEntityPath, consts.TemplateGenDaoEntityContent,
|
||||||
tplVarTableName: tableName,
|
)
|
||||||
tplVarPackageImports: getImportPartContent(ctx, structDefine, false, appendImports),
|
|
||||||
tplVarTableNameCamelCase: tableNameCamelCase,
|
|
||||||
tplVarStructDefine: structDefine,
|
|
||||||
tplVarPackageName: filepath.Base(in.EntityPath),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
entityContent = replaceDefaultVar(in, entityContent)
|
tplView.ClearAssigns()
|
||||||
|
tplView.Assigns(gview.Params{
|
||||||
|
tplVarTableName: tableName,
|
||||||
|
tplVarPackageImports: getImportPartContent(ctx, structDefine, false, appendImports),
|
||||||
|
tplVarTableNameCamelCase: tableNameCamelCase,
|
||||||
|
tplVarStructDefine: structDefine,
|
||||||
|
tplVarPackageName: filepath.Base(in.EntityPath),
|
||||||
|
})
|
||||||
|
assignDefaultVar(tplView, in)
|
||||||
|
entityContent, err := tplView.ParseContent(ctx, tplContent)
|
||||||
|
if err != nil {
|
||||||
|
mlog.Fatalf("parsing template content failed: %v", err)
|
||||||
|
}
|
||||||
return entityContent
|
return entityContent
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,14 +38,14 @@ func (i *CGenDaoInternalGenItems) SetClear(clear bool) {
|
|||||||
i.Items[i.index].Clear = clear
|
i.Items[i.index].Clear = clear
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i CGenDaoInternalGenItems) AppendDirPath(storageDirPath string) {
|
func (i *CGenDaoInternalGenItems) AppendDirPath(storageDirPath string) {
|
||||||
i.Items[i.index].StorageDirPaths = append(
|
i.Items[i.index].StorageDirPaths = append(
|
||||||
i.Items[i.index].StorageDirPaths,
|
i.Items[i.index].StorageDirPaths,
|
||||||
storageDirPath,
|
storageDirPath,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i CGenDaoInternalGenItems) AppendGeneratedFilePath(generatedFilePath string) {
|
func (i *CGenDaoInternalGenItems) AppendGeneratedFilePath(generatedFilePath string) {
|
||||||
i.Items[i.index].GeneratedFilePaths = append(
|
i.Items[i.index].GeneratedFilePaths = append(
|
||||||
i.Items[i.index].GeneratedFilePaths,
|
i.Items[i.index].GeneratedFilePaths,
|
||||||
generatedFilePath,
|
generatedFilePath,
|
||||||
|
|||||||
@ -41,28 +41,55 @@ func generateStructDefinition(ctx context.Context, in generateStructDefinitionIn
|
|||||||
appendImports = append(appendImports, imports)
|
appendImports = append(appendImports, imports)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tw := tablewriter.NewWriter(buffer)
|
table := tablewriter.NewTable(buffer, twRenderer, twConfig)
|
||||||
tw.SetBorder(false)
|
table.Bulk(array)
|
||||||
tw.SetRowLine(false)
|
table.Render()
|
||||||
tw.SetAutoWrapText(false)
|
|
||||||
tw.SetColumnSeparator("")
|
|
||||||
tw.AppendBulk(array)
|
|
||||||
tw.Render()
|
|
||||||
stContent := buffer.String()
|
stContent := buffer.String()
|
||||||
// Let's do this hack of table writer for indent!
|
// Let's do this hack of table writer for indent!
|
||||||
stContent = gstr.Replace(stContent, " #", "")
|
stContent = gstr.Replace(stContent, " #", "")
|
||||||
stContent = gstr.Replace(stContent, "` ", "`")
|
stContent = gstr.Replace(stContent, "` ", "`")
|
||||||
stContent = gstr.Replace(stContent, "``", "")
|
stContent = gstr.Replace(stContent, "``", "")
|
||||||
buffer.Reset()
|
buffer.Reset()
|
||||||
buffer.WriteString(fmt.Sprintf("type %s struct {\n", in.StructName))
|
fmt.Fprintf(buffer, "type %s struct {\n", in.StructName)
|
||||||
if in.IsDo {
|
if in.IsDo {
|
||||||
buffer.WriteString(fmt.Sprintf("g.Meta `orm:\"table:%s, do:true\"`\n", in.TableName))
|
fmt.Fprintf(buffer, "g.Meta `orm:\"table:%s, do:true\"`\n", in.TableName)
|
||||||
}
|
}
|
||||||
buffer.WriteString(stContent)
|
buffer.WriteString(stContent)
|
||||||
buffer.WriteString("}")
|
buffer.WriteString("}")
|
||||||
return buffer.String(), appendImports
|
return buffer.String(), appendImports
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTypeMappingInfo(
|
||||||
|
ctx context.Context, fieldType string, inTypeMapping map[DBFieldTypeName]CustomAttributeType,
|
||||||
|
) (typeNameStr, importStr string) {
|
||||||
|
if typeMapping, ok := inTypeMapping[strings.ToLower(fieldType)]; ok {
|
||||||
|
typeNameStr = typeMapping.Type
|
||||||
|
importStr = typeMapping.Import
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tryTypeMatch, _ := gregex.MatchString(`(.+?)\(([^\(\)]+)\)([\s\)]*)`, fieldType)
|
||||||
|
var (
|
||||||
|
tryTypeName string
|
||||||
|
moreTry bool
|
||||||
|
)
|
||||||
|
if len(tryTypeMatch) == 4 {
|
||||||
|
tryTypeMatch3, _ := gregex.ReplaceString(`\s+`, "", tryTypeMatch[3])
|
||||||
|
tryTypeName = gstr.Trim(tryTypeMatch[1]) + tryTypeMatch3
|
||||||
|
moreTry = tryTypeMatch3 != ""
|
||||||
|
} else {
|
||||||
|
tryTypeName = gstr.Split(fieldType, " ")[0]
|
||||||
|
}
|
||||||
|
if tryTypeName != "" {
|
||||||
|
if typeMapping, ok := inTypeMapping[strings.ToLower(tryTypeName)]; ok {
|
||||||
|
typeNameStr = typeMapping.Type
|
||||||
|
importStr = typeMapping.Import
|
||||||
|
} else if moreTry {
|
||||||
|
typeNameStr, importStr = getTypeMappingInfo(ctx, tryTypeName, inTypeMapping)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// generateStructFieldDefinition generates and returns the attribute definition for specified field.
|
// generateStructFieldDefinition generates and returns the attribute definition for specified field.
|
||||||
func generateStructFieldDefinition(
|
func generateStructFieldDefinition(
|
||||||
ctx context.Context, field *gdb.TableField, in generateStructDefinitionInput,
|
ctx context.Context, field *gdb.TableField, in generateStructDefinitionInput,
|
||||||
@ -75,21 +102,7 @@ func generateStructFieldDefinition(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if in.TypeMapping != nil && len(in.TypeMapping) > 0 {
|
if in.TypeMapping != nil && len(in.TypeMapping) > 0 {
|
||||||
var (
|
localTypeNameStr, appendImport = getTypeMappingInfo(ctx, field.Type, in.TypeMapping)
|
||||||
tryTypeName string
|
|
||||||
)
|
|
||||||
tryTypeMatch, _ := gregex.MatchString(`(.+?)\((.+)\)`, field.Type)
|
|
||||||
if len(tryTypeMatch) == 3 {
|
|
||||||
tryTypeName = gstr.Trim(tryTypeMatch[1])
|
|
||||||
} else {
|
|
||||||
tryTypeName = gstr.Split(field.Type, " ")[0]
|
|
||||||
}
|
|
||||||
if tryTypeName != "" {
|
|
||||||
if typeMapping, ok := in.TypeMapping[strings.ToLower(tryTypeName)]; ok {
|
|
||||||
localTypeNameStr = typeMapping.Type
|
|
||||||
appendImport = typeMapping.Import
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if localTypeNameStr == "" {
|
if localTypeNameStr == "" {
|
||||||
|
|||||||
150
cmd/gf/internal/cmd/gendao/gendao_tag.go
Normal file
150
cmd/gf/internal/cmd/gendao/gendao_tag.go
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||||
|
//
|
||||||
|
// This Source Code Form is subject to the terms of the MIT License.
|
||||||
|
// If a copy of the MIT was not distributed with this file,
|
||||||
|
// You can obtain one at https://github.com/gogf/gf.
|
||||||
|
|
||||||
|
package gendao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/util/gtag"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CGenDaoConfig = `gfcli.gen.dao`
|
||||||
|
CGenDaoUsage = `gf gen dao [OPTION]`
|
||||||
|
CGenDaoBrief = `automatically generate go files for dao/do/entity`
|
||||||
|
CGenDaoEg = `
|
||||||
|
gf gen dao
|
||||||
|
gf gen dao -l "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
||||||
|
gf gen dao -p ./model -g user-center -t user,user_detail,user_login
|
||||||
|
gf gen dao -r user_
|
||||||
|
`
|
||||||
|
|
||||||
|
CGenDaoAd = `
|
||||||
|
CONFIGURATION SUPPORT
|
||||||
|
Options are also supported by configuration file.
|
||||||
|
It's suggested using configuration file instead of command line arguments making producing.
|
||||||
|
The configuration node name is "gfcli.gen.dao", which also supports multiple databases, for example(config.yaml):
|
||||||
|
gfcli:
|
||||||
|
gen:
|
||||||
|
dao:
|
||||||
|
- link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
|
||||||
|
tables: "order,products"
|
||||||
|
jsonCase: "CamelLower"
|
||||||
|
- link: "mysql:root:12345678@tcp(127.0.0.1:3306)/primary"
|
||||||
|
path: "./my-app"
|
||||||
|
prefix: "primary_"
|
||||||
|
tables: "user, userDetail"
|
||||||
|
typeMapping:
|
||||||
|
decimal:
|
||||||
|
type: decimal.Decimal
|
||||||
|
import: github.com/shopspring/decimal
|
||||||
|
numeric:
|
||||||
|
type: string
|
||||||
|
fieldMapping:
|
||||||
|
table_name.field_name:
|
||||||
|
type: decimal.Decimal
|
||||||
|
import: github.com/shopspring/decimal
|
||||||
|
`
|
||||||
|
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`
|
||||||
|
CGenDaoBriefFieldMapping = `custom local type mapping for generated struct attributes relevant to specific fields of table`
|
||||||
|
CGenDaoBriefShardingPattern = `sharding pattern for table name, e.g. "users_?" will be replace tables "users_001,users_002,..." to "users" dao`
|
||||||
|
CGenDaoBriefGroup = `
|
||||||
|
specifying the configuration group name of database for generated ORM instance,
|
||||||
|
it's not necessary and the default value is "default"
|
||||||
|
`
|
||||||
|
CGenDaoBriefJsonCase = `
|
||||||
|
generated json tag case for model struct, cases are as follows:
|
||||||
|
| Case | Example |
|
||||||
|
|---------------- |--------------------|
|
||||||
|
| Camel | AnyKindOfString |
|
||||||
|
| CamelLower | anyKindOfString | default
|
||||||
|
| Snake | any_kind_of_string |
|
||||||
|
| SnakeScreaming | ANY_KIND_OF_STRING |
|
||||||
|
| SnakeFirstUpper | rgb_code_md5 |
|
||||||
|
| Kebab | any-kind-of-string |
|
||||||
|
| KebabScreaming | ANY-KIND-OF-STRING |
|
||||||
|
`
|
||||||
|
CGenDaoBriefTplDaoIndexPath = `template file path for dao index file`
|
||||||
|
CGenDaoBriefTplDaoInternalPath = `template file path for dao internal file`
|
||||||
|
CGenDaoBriefTplDaoDoPathPath = `template file path for dao do file`
|
||||||
|
CGenDaoBriefTplDaoEntityPath = `template file path for dao entity file`
|
||||||
|
|
||||||
|
tplVarTableName = `TplTableName`
|
||||||
|
tplVarTableNameCamelCase = `TplTableNameCamelCase`
|
||||||
|
tplVarTableNameCamelLowerCase = `TplTableNameCamelLowerCase`
|
||||||
|
tplVarTableSharding = `TplTableSharding`
|
||||||
|
tplVarTableShardingPrefix = `TplTableShardingPrefix`
|
||||||
|
tplVarPackageImports = `TplPackageImports`
|
||||||
|
tplVarImportPrefix = `TplImportPrefix`
|
||||||
|
tplVarStructDefine = `TplStructDefine`
|
||||||
|
tplVarColumnDefine = `TplColumnDefine`
|
||||||
|
tplVarColumnNames = `TplColumnNames`
|
||||||
|
tplVarGroupName = `TplGroupName`
|
||||||
|
tplVarDatetimeStr = `TplDatetimeStr`
|
||||||
|
tplVarCreatedAtDatetimeStr = `TplCreatedAtDatetimeStr`
|
||||||
|
tplVarPackageName = `TplPackageName`
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
gtag.Sets(g.MapStrStr{
|
||||||
|
`CGenDaoConfig`: CGenDaoConfig,
|
||||||
|
`CGenDaoUsage`: CGenDaoUsage,
|
||||||
|
`CGenDaoBrief`: CGenDaoBrief,
|
||||||
|
`CGenDaoEg`: CGenDaoEg,
|
||||||
|
`CGenDaoAd`: CGenDaoAd,
|
||||||
|
`CGenDaoBriefPath`: CGenDaoBriefPath,
|
||||||
|
`CGenDaoBriefLink`: CGenDaoBriefLink,
|
||||||
|
`CGenDaoBriefTables`: CGenDaoBriefTables,
|
||||||
|
`CGenDaoBriefTablesEx`: CGenDaoBriefTablesEx,
|
||||||
|
`CGenDaoBriefPrefix`: CGenDaoBriefPrefix,
|
||||||
|
`CGenDaoBriefRemovePrefix`: CGenDaoBriefRemovePrefix,
|
||||||
|
`CGenDaoBriefRemoveFieldPrefix`: CGenDaoBriefRemoveFieldPrefix,
|
||||||
|
`CGenDaoBriefStdTime`: CGenDaoBriefStdTime,
|
||||||
|
`CGenDaoBriefWithTime`: CGenDaoBriefWithTime,
|
||||||
|
`CGenDaoBriefDaoPath`: CGenDaoBriefDaoPath,
|
||||||
|
`CGenDaoBriefDoPath`: CGenDaoBriefDoPath,
|
||||||
|
`CGenDaoBriefEntityPath`: CGenDaoBriefEntityPath,
|
||||||
|
`CGenDaoBriefGJsonSupport`: CGenDaoBriefGJsonSupport,
|
||||||
|
`CGenDaoBriefImportPrefix`: CGenDaoBriefImportPrefix,
|
||||||
|
`CGenDaoBriefOverwriteDao`: CGenDaoBriefOverwriteDao,
|
||||||
|
`CGenDaoBriefModelFile`: CGenDaoBriefModelFile,
|
||||||
|
`CGenDaoBriefModelFileForDao`: CGenDaoBriefModelFileForDao,
|
||||||
|
`CGenDaoBriefDescriptionTag`: CGenDaoBriefDescriptionTag,
|
||||||
|
`CGenDaoBriefNoJsonTag`: CGenDaoBriefNoJsonTag,
|
||||||
|
`CGenDaoBriefNoModelComment`: CGenDaoBriefNoModelComment,
|
||||||
|
`CGenDaoBriefClear`: CGenDaoBriefClear,
|
||||||
|
`CGenDaoBriefTypeMapping`: CGenDaoBriefTypeMapping,
|
||||||
|
`CGenDaoBriefFieldMapping`: CGenDaoBriefFieldMapping,
|
||||||
|
`CGenDaoBriefShardingPattern`: CGenDaoBriefShardingPattern,
|
||||||
|
`CGenDaoBriefGroup`: CGenDaoBriefGroup,
|
||||||
|
`CGenDaoBriefJsonCase`: CGenDaoBriefJsonCase,
|
||||||
|
`CGenDaoBriefTplDaoIndexPath`: CGenDaoBriefTplDaoIndexPath,
|
||||||
|
`CGenDaoBriefTplDaoInternalPath`: CGenDaoBriefTplDaoInternalPath,
|
||||||
|
`CGenDaoBriefTplDaoDoPathPath`: CGenDaoBriefTplDaoDoPathPath,
|
||||||
|
`CGenDaoBriefTplDaoEntityPath`: CGenDaoBriefTplDaoEntityPath,
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -113,12 +113,12 @@ func (p *EnumsParser) ParsePackage(pkg *packages.Package) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *EnumsParser) Export() string {
|
func (p *EnumsParser) Export() string {
|
||||||
var typeEnumMap = make(map[string][]interface{})
|
var typeEnumMap = make(map[string][]any)
|
||||||
for _, enum := range p.enums {
|
for _, enum := range p.enums {
|
||||||
if typeEnumMap[enum.Type] == nil {
|
if typeEnumMap[enum.Type] == nil {
|
||||||
typeEnumMap[enum.Type] = make([]interface{}, 0)
|
typeEnumMap[enum.Type] = make([]any, 0)
|
||||||
}
|
}
|
||||||
var value interface{}
|
var value any
|
||||||
switch enum.Kind {
|
switch enum.Kind {
|
||||||
case constant.Int:
|
case constant.Int:
|
||||||
value = gconv.Int64(enum.Value)
|
value = gconv.Int64(enum.Value)
|
||||||
|
|||||||
@ -109,7 +109,7 @@ func (c CGenPb) tagCommentIntoListMap(comment string, lineTagMap *gmap.ListMap)
|
|||||||
|
|
||||||
func (c CGenPb) listMapToStructTag(lineTagMap *gmap.ListMap) string {
|
func (c CGenPb) listMapToStructTag(lineTagMap *gmap.ListMap) string {
|
||||||
var tag string
|
var tag string
|
||||||
lineTagMap.Iterator(func(key, value interface{}) bool {
|
lineTagMap.Iterator(func(key, value any) bool {
|
||||||
if tag != "" {
|
if tag != "" {
|
||||||
tag += " "
|
tag += " "
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,8 +15,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
|
"github.com/olekukonko/tablewriter/renderer"
|
||||||
|
"github.com/olekukonko/tablewriter/tw"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/container/garray"
|
"github.com/gogf/gf/v2/container/garray"
|
||||||
|
"github.com/gogf/gf/v2/container/gset"
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
@ -36,16 +39,19 @@ type (
|
|||||||
CGenPbEntity struct{}
|
CGenPbEntity struct{}
|
||||||
CGenPbEntityInput struct {
|
CGenPbEntityInput struct {
|
||||||
g.Meta `name:"pbentity" config:"{CGenPbEntityConfig}" brief:"{CGenPbEntityBrief}" eg:"{CGenPbEntityEg}" ad:"{CGenPbEntityAd}"`
|
g.Meta `name:"pbentity" config:"{CGenPbEntityConfig}" brief:"{CGenPbEntityBrief}" eg:"{CGenPbEntityEg}" ad:"{CGenPbEntityAd}"`
|
||||||
Path string `name:"path" short:"p" brief:"{CGenPbEntityBriefPath}" d:"manifest/protobuf/pbentity"`
|
Path string `name:"path" short:"p" brief:"{CGenPbEntityBriefPath}" d:"manifest/protobuf/pbentity"`
|
||||||
Package string `name:"package" short:"k" brief:"{CGenPbEntityBriefPackage}"`
|
Package string `name:"package" short:"k" brief:"{CGenPbEntityBriefPackage}"`
|
||||||
Link string `name:"link" short:"l" brief:"{CGenPbEntityBriefLink}"`
|
GoPackage string `name:"goPackage" short:"g" brief:"{CGenPbEntityBriefGoPackage}"`
|
||||||
Tables string `name:"tables" short:"t" brief:"{CGenPbEntityBriefTables}"`
|
Link string `name:"link" short:"l" brief:"{CGenPbEntityBriefLink}"`
|
||||||
Prefix string `name:"prefix" short:"f" brief:"{CGenPbEntityBriefPrefix}"`
|
Tables string `name:"tables" short:"t" brief:"{CGenPbEntityBriefTables}"`
|
||||||
RemovePrefix string `name:"removePrefix" short:"r" brief:"{CGenPbEntityBriefRemovePrefix}"`
|
Prefix string `name:"prefix" short:"f" brief:"{CGenPbEntityBriefPrefix}"`
|
||||||
RemoveFieldPrefix string `name:"removeFieldPrefix" short:"rf" brief:"{CGenPbEntityBriefRemoveFieldPrefix}"`
|
RemovePrefix string `name:"removePrefix" short:"r" brief:"{CGenPbEntityBriefRemovePrefix}"`
|
||||||
NameCase string `name:"nameCase" short:"n" brief:"{CGenPbEntityBriefNameCase}" d:"Camel"`
|
RemoveFieldPrefix string `name:"removeFieldPrefix" short:"rf" brief:"{CGenPbEntityBriefRemoveFieldPrefix}"`
|
||||||
JsonCase string `name:"jsonCase" short:"j" brief:"{CGenPbEntityBriefJsonCase}" d:"none"`
|
TablesEx string `name:"tablesEx" short:"x" brief:"{CGenDaoBriefTablesEx}"`
|
||||||
Option string `name:"option" short:"o" brief:"{CGenPbEntityBriefOption}"`
|
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}"`
|
||||||
|
ShardingPattern []string `name:"shardingPattern" short:"sp" brief:"{CGenDaoBriefShardingPattern}"`
|
||||||
|
|
||||||
TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenPbEntityBriefTypeMapping}" orphan:"true"`
|
TypeMapping map[DBFieldTypeName]CustomAttributeType `name:"typeMapping" short:"y" brief:"{CGenPbEntityBriefTypeMapping}" orphan:"true"`
|
||||||
FieldMapping map[DBTableFieldName]CustomAttributeType `name:"fieldMapping" short:"fm" brief:"{CGenPbEntityBriefFieldMapping}" orphan:"true"`
|
FieldMapping map[DBTableFieldName]CustomAttributeType `name:"fieldMapping" short:"fm" brief:"{CGenPbEntityBriefFieldMapping}" orphan:"true"`
|
||||||
@ -111,12 +117,15 @@ CONFIGURATION SUPPORT
|
|||||||
`
|
`
|
||||||
CGenPbEntityBriefPath = `directory path for generated files storing`
|
CGenPbEntityBriefPath = `directory path for generated files storing`
|
||||||
CGenPbEntityBriefPackage = `package path for all entity proto files`
|
CGenPbEntityBriefPackage = `package path for all entity proto files`
|
||||||
|
CGenPbEntityBriefGoPackage = `go package path for all entity proto files`
|
||||||
CGenPbEntityBriefLink = `database configuration, the same as the ORM configuration of GoFrame`
|
CGenPbEntityBriefLink = `database configuration, the same as the ORM configuration of GoFrame`
|
||||||
CGenPbEntityBriefTables = `generate models only for given tables, multiple table names separated with ','`
|
CGenPbEntityBriefTables = `generate models only for given tables, multiple table names separated with ','`
|
||||||
CGenPbEntityBriefPrefix = `add specified prefix for all entity names and entity proto files`
|
CGenPbEntityBriefPrefix = `add specified prefix for all entity names and entity proto files`
|
||||||
CGenPbEntityBriefRemovePrefix = `remove specified prefix of the table, multiple prefix separated with ','`
|
CGenPbEntityBriefRemovePrefix = `remove specified prefix of the table, multiple prefix separated with ','`
|
||||||
|
CGenPbEntityBriefTablesEx = `generate all models exclude the specified tables, multiple prefix separated with ','`
|
||||||
CGenPbEntityBriefRemoveFieldPrefix = `remove specified prefix of the field, multiple prefix separated with ','`
|
CGenPbEntityBriefRemoveFieldPrefix = `remove specified prefix of the field, multiple prefix separated with ','`
|
||||||
CGenPbEntityBriefOption = `extra protobuf options`
|
CGenPbEntityBriefOption = `extra protobuf options`
|
||||||
|
CGenPbEntityBriefShardingPattern = `sharding pattern for table name, e.g. "users_?" will replace tables "users_001,users_002,..." to "users" pbentity`
|
||||||
CGenPbEntityBriefGroup = `
|
CGenPbEntityBriefGroup = `
|
||||||
specifying the configuration group name of database for generated ORM instance,
|
specifying the configuration group name of database for generated ORM instance,
|
||||||
it's not necessary and the default value is "default"
|
it's not necessary and the default value is "default"
|
||||||
@ -236,15 +245,18 @@ func init() {
|
|||||||
`CGenPbEntityAd`: CGenPbEntityAd,
|
`CGenPbEntityAd`: CGenPbEntityAd,
|
||||||
`CGenPbEntityBriefPath`: CGenPbEntityBriefPath,
|
`CGenPbEntityBriefPath`: CGenPbEntityBriefPath,
|
||||||
`CGenPbEntityBriefPackage`: CGenPbEntityBriefPackage,
|
`CGenPbEntityBriefPackage`: CGenPbEntityBriefPackage,
|
||||||
|
`CGenPbEntityBriefGoPackage`: CGenPbEntityBriefGoPackage,
|
||||||
`CGenPbEntityBriefLink`: CGenPbEntityBriefLink,
|
`CGenPbEntityBriefLink`: CGenPbEntityBriefLink,
|
||||||
`CGenPbEntityBriefTables`: CGenPbEntityBriefTables,
|
`CGenPbEntityBriefTables`: CGenPbEntityBriefTables,
|
||||||
`CGenPbEntityBriefPrefix`: CGenPbEntityBriefPrefix,
|
`CGenPbEntityBriefPrefix`: CGenPbEntityBriefPrefix,
|
||||||
`CGenPbEntityBriefRemovePrefix`: CGenPbEntityBriefRemovePrefix,
|
`CGenPbEntityBriefRemovePrefix`: CGenPbEntityBriefRemovePrefix,
|
||||||
|
`CGenPbEntityBriefTablesEx`: CGenPbEntityBriefTablesEx,
|
||||||
`CGenPbEntityBriefRemoveFieldPrefix`: CGenPbEntityBriefRemoveFieldPrefix,
|
`CGenPbEntityBriefRemoveFieldPrefix`: CGenPbEntityBriefRemoveFieldPrefix,
|
||||||
`CGenPbEntityBriefGroup`: CGenPbEntityBriefGroup,
|
`CGenPbEntityBriefGroup`: CGenPbEntityBriefGroup,
|
||||||
`CGenPbEntityBriefNameCase`: CGenPbEntityBriefNameCase,
|
`CGenPbEntityBriefNameCase`: CGenPbEntityBriefNameCase,
|
||||||
`CGenPbEntityBriefJsonCase`: CGenPbEntityBriefJsonCase,
|
`CGenPbEntityBriefJsonCase`: CGenPbEntityBriefJsonCase,
|
||||||
`CGenPbEntityBriefOption`: CGenPbEntityBriefOption,
|
`CGenPbEntityBriefOption`: CGenPbEntityBriefOption,
|
||||||
|
`CGenPbEntityBriefShardingPattern`: CGenPbEntityBriefShardingPattern,
|
||||||
`CGenPbEntityBriefTypeMapping`: CGenPbEntityBriefTypeMapping,
|
`CGenPbEntityBriefTypeMapping`: CGenPbEntityBriefTypeMapping,
|
||||||
`CGenPbEntityBriefFieldMapping`: CGenPbEntityBriefFieldMapping,
|
`CGenPbEntityBriefFieldMapping`: CGenPbEntityBriefFieldMapping,
|
||||||
})
|
})
|
||||||
@ -290,6 +302,9 @@ func doGenPbEntityForArray(ctx context.Context, index int, in CGenPbEntityInput)
|
|||||||
in.Package = modName + "/" + defaultPackageSuffix
|
in.Package = modName + "/" + defaultPackageSuffix
|
||||||
}
|
}
|
||||||
removePrefixArray := gstr.SplitAndTrim(in.RemovePrefix, ",")
|
removePrefixArray := gstr.SplitAndTrim(in.RemovePrefix, ",")
|
||||||
|
|
||||||
|
excludeTables := gset.NewStrSetFrom(gstr.SplitAndTrim(in.TablesEx, ","))
|
||||||
|
|
||||||
// It uses user passed database configuration.
|
// It uses user passed database configuration.
|
||||||
if in.Link != "" {
|
if in.Link != "" {
|
||||||
var (
|
var (
|
||||||
@ -311,6 +326,7 @@ func doGenPbEntityForArray(ctx context.Context, index int, in CGenPbEntityInput)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tableNames := ([]string)(nil)
|
tableNames := ([]string)(nil)
|
||||||
|
shardingNewTableSet := gset.NewStrSet()
|
||||||
if in.Tables != "" {
|
if in.Tables != "" {
|
||||||
tableNames = gstr.SplitAndTrim(in.Tables, ",")
|
tableNames = gstr.SplitAndTrim(in.Tables, ",")
|
||||||
} else {
|
} else {
|
||||||
@ -331,10 +347,38 @@ func doGenPbEntityForArray(ctx context.Context, index int, in CGenPbEntityInput)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, tableName := range tableNames {
|
for _, tableName := range tableNames {
|
||||||
|
if excludeTables.Contains(tableName) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
newTableName := tableName
|
newTableName := tableName
|
||||||
for _, v := range removePrefixArray {
|
for _, v := range removePrefixArray {
|
||||||
newTableName = gstr.TrimLeftStr(newTableName, v, 1)
|
newTableName = gstr.TrimLeftStr(newTableName, v, 1)
|
||||||
}
|
}
|
||||||
|
var shardingTableName string
|
||||||
|
if len(in.ShardingPattern) > 0 {
|
||||||
|
for _, pattern := range in.ShardingPattern {
|
||||||
|
var (
|
||||||
|
match []string
|
||||||
|
regPattern = gstr.Replace(pattern, "?", `(.+)`)
|
||||||
|
)
|
||||||
|
match, err = gregex.MatchString(regPattern, newTableName)
|
||||||
|
if err != nil {
|
||||||
|
mlog.Fatalf(`invalid sharding pattern "%s": %+v`, pattern, err)
|
||||||
|
}
|
||||||
|
if len(match) < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
shardingTableName = gstr.Replace(pattern, "?", "")
|
||||||
|
shardingTableName = gstr.Trim(shardingTableName, `_.-`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if shardingTableName != "" {
|
||||||
|
if shardingNewTableSet.Contains(shardingTableName) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
shardingNewTableSet.Add(shardingTableName)
|
||||||
|
newTableName = shardingTableName
|
||||||
|
}
|
||||||
generatePbEntityContentFile(ctx, CGenPbEntityInternalInput{
|
generatePbEntityContentFile(ctx, CGenPbEntityInternalInput{
|
||||||
CGenPbEntityInput: in,
|
CGenPbEntityInput: in,
|
||||||
DB: db,
|
DB: db,
|
||||||
@ -369,10 +413,13 @@ func generatePbEntityContentFile(ctx context.Context, in CGenPbEntityInternalInp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if in.GoPackage == "" {
|
||||||
|
in.GoPackage = in.Package
|
||||||
|
}
|
||||||
entityContent := gstr.ReplaceByMap(getTplPbEntityContent(""), g.MapStrStr{
|
entityContent := gstr.ReplaceByMap(getTplPbEntityContent(""), g.MapStrStr{
|
||||||
"{Imports}": packageImportsArray.Join("\n"),
|
"{Imports}": packageImportsArray.Join("\n"),
|
||||||
"{PackageName}": gfile.Basename(in.Package),
|
"{PackageName}": gfile.Basename(in.Package),
|
||||||
"{GoPackage}": in.Package,
|
"{GoPackage}": in.GoPackage,
|
||||||
"{OptionContent}": in.Option,
|
"{OptionContent}": in.Option,
|
||||||
"{EntityMessage}": entityMessageDefine,
|
"{EntityMessage}": entityMessageDefine,
|
||||||
})
|
})
|
||||||
@ -398,13 +445,22 @@ func generateEntityMessageDefinition(entityName string, fieldMap map[string]*gdb
|
|||||||
appendImports = append(appendImports, imports)
|
appendImports = append(appendImports, imports)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tw := tablewriter.NewWriter(buffer)
|
table := tablewriter.NewTable(buffer,
|
||||||
tw.SetBorder(false)
|
tablewriter.WithRenderer(renderer.NewBlueprint(tw.Rendition{
|
||||||
tw.SetRowLine(false)
|
Borders: tw.Border{Top: tw.Off, Bottom: tw.Off, Left: tw.On, Right: tw.Off},
|
||||||
tw.SetAutoWrapText(false)
|
Settings: tw.Settings{
|
||||||
tw.SetColumnSeparator("")
|
Separators: tw.Separators{BetweenRows: tw.Off, BetweenColumns: tw.Off},
|
||||||
tw.AppendBulk(array)
|
},
|
||||||
tw.Render()
|
Symbols: tw.NewSymbolCustom("Proto").WithColumn(" "),
|
||||||
|
})),
|
||||||
|
tablewriter.WithConfig(tablewriter.Config{
|
||||||
|
Row: tw.CellConfig{
|
||||||
|
Formatting: tw.CellFormatting{AutoWrap: tw.WrapNone},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
table.Bulk(array)
|
||||||
|
table.Render()
|
||||||
stContent := buffer.String()
|
stContent := buffer.String()
|
||||||
// Let's do this hack of table writer for indent!
|
// Let's do this hack of table writer for indent!
|
||||||
stContent = regexp.MustCompile(`\s+\n`).ReplaceAllString(gstr.Replace(stContent, " #", ""), "\n")
|
stContent = regexp.MustCompile(`\s+\n`).ReplaceAllString(gstr.Replace(stContent, " #", ""), "\n")
|
||||||
@ -425,14 +481,23 @@ func generateMessageFieldForPbEntity(index int, field *gdb.TableField, in CGenPb
|
|||||||
err error
|
err error
|
||||||
ctx = gctx.GetInitCtx()
|
ctx = gctx.GetInitCtx()
|
||||||
)
|
)
|
||||||
|
|
||||||
if in.TypeMapping != nil && len(in.TypeMapping) > 0 {
|
if in.TypeMapping != nil && len(in.TypeMapping) > 0 {
|
||||||
|
// match typeMapping after local type transform.
|
||||||
|
// eg: double => string, varchar => string etc.
|
||||||
localTypeName, err = in.DB.CheckLocalTypeForField(ctx, field.Type, nil)
|
localTypeName, err = in.DB.CheckLocalTypeForField(ctx, field.Type, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if localTypeName != "" {
|
if localTypeName != "" {
|
||||||
if typeMapping, ok := in.TypeMapping[strings.ToLower(string(localTypeName))]; ok {
|
if typeMappingLocal, localOk := in.TypeMapping[strings.ToLower(string(localTypeName))]; localOk {
|
||||||
|
localTypeNameStr = typeMappingLocal.Type
|
||||||
|
appendImport = typeMappingLocal.Import
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Try match unknown / string localTypeName with db type.
|
||||||
|
if localTypeName == "" || localTypeName == gdb.LocalTypeString {
|
||||||
|
formattedFieldType, _ := in.DB.GetFormattedDBTypeNameForField(field.Type)
|
||||||
|
if typeMapping, ok := in.TypeMapping[strings.ToLower(formattedFieldType)]; ok {
|
||||||
localTypeNameStr = typeMapping.Type
|
localTypeNameStr = typeMapping.Type
|
||||||
appendImport = typeMapping.Import
|
appendImport = typeMapping.Import
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,8 +13,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
|
|
||||||
"github.com/gogf/gf/v2/container/garray"
|
"github.com/gogf/gf/v2/container/garray"
|
||||||
"github.com/gogf/gf/v2/container/gmap"
|
"github.com/gogf/gf/v2/container/gmap"
|
||||||
"github.com/gogf/gf/v2/container/gset"
|
"github.com/gogf/gf/v2/container/gset"
|
||||||
@ -25,6 +23,9 @@ import (
|
|||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
"github.com/gogf/gf/v2/util/gtag"
|
"github.com/gogf/gf/v2/util/gtag"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||||
|
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@ -33,7 +33,7 @@ func (c CGenService) generateType(generatedContent *bytes.Buffer, srcStructFunct
|
|||||||
generatedContent.WriteString("type(")
|
generatedContent.WriteString("type(")
|
||||||
generatedContent.WriteString("\n")
|
generatedContent.WriteString("\n")
|
||||||
|
|
||||||
srcStructFunctions.Iterator(func(key, value interface{}) bool {
|
srcStructFunctions.Iterator(func(key, value any) bool {
|
||||||
var (
|
var (
|
||||||
funcContents = make([]string, 0)
|
funcContents = make([]string, 0)
|
||||||
funcContent string
|
funcContent string
|
||||||
@ -71,7 +71,7 @@ func (c CGenService) generateVar(generatedContent *bytes.Buffer, srcStructFuncti
|
|||||||
// Generating variable and register definitions.
|
// Generating variable and register definitions.
|
||||||
var variableContent string
|
var variableContent string
|
||||||
|
|
||||||
srcStructFunctions.Iterator(func(key, value interface{}) bool {
|
srcStructFunctions.Iterator(func(key, value any) bool {
|
||||||
structName := key.(string)
|
structName := key.(string)
|
||||||
variableContent += gstr.Trim(gstr.ReplaceByMap(consts.TemplateGenServiceContentVariable, g.MapStrStr{
|
variableContent += gstr.Trim(gstr.ReplaceByMap(consts.TemplateGenServiceContentVariable, g.MapStrStr{
|
||||||
"{StructName}": structName,
|
"{StructName}": structName,
|
||||||
@ -93,7 +93,7 @@ func (c CGenService) generateVar(generatedContent *bytes.Buffer, srcStructFuncti
|
|||||||
// See: const.TemplateGenServiceContentRegister
|
// See: const.TemplateGenServiceContentRegister
|
||||||
func (c CGenService) generateFunc(generatedContent *bytes.Buffer, srcStructFunctions *gmap.ListMap) {
|
func (c CGenService) generateFunc(generatedContent *bytes.Buffer, srcStructFunctions *gmap.ListMap) {
|
||||||
// Variable register function definitions.
|
// Variable register function definitions.
|
||||||
srcStructFunctions.Iterator(func(key, value interface{}) bool {
|
srcStructFunctions.Iterator(func(key, value any) bool {
|
||||||
structName := key.(string)
|
structName := key.(string)
|
||||||
generatedContent.WriteString(gstr.Trim(gstr.ReplaceByMap(consts.TemplateGenServiceContentRegister, g.MapStrStr{
|
generatedContent.WriteString(gstr.Trim(gstr.ReplaceByMap(consts.TemplateGenServiceContentRegister, g.MapStrStr{
|
||||||
"{StructName}": structName,
|
"{StructName}": structName,
|
||||||
|
|||||||
11
cmd/gf/internal/cmd/testdata/build/varmap/go.mod
vendored
11
cmd/gf/internal/cmd/testdata/build/varmap/go.mod
vendored
@ -1,12 +1,15 @@
|
|||||||
module github.com/gogf/gf/cmd/gf/cmd/gf/testdata/vardump/v2
|
module github.com/gogf/gf/cmd/gf/cmd/gf/testdata/vardump/v2
|
||||||
|
|
||||||
go 1.18
|
go 1.23.0
|
||||||
|
|
||||||
require github.com/gogf/gf/v2 v2.8.2
|
toolchain go1.24.6
|
||||||
|
|
||||||
|
require github.com/gogf/gf/v2 v2.9.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
go.opentelemetry.io/otel v1.24.0 // indirect
|
go.opentelemetry.io/otel v1.37.0 // indirect
|
||||||
go.opentelemetry.io/otel/trace v1.24.0 // indirect
|
go.opentelemetry.io/otel/trace v1.37.0 // indirect
|
||||||
|
golang.org/x/text v0.28.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/gogf/gf/v2 => ../../../../../../../
|
replace github.com/gogf/gf/v2 => ../../../../../../../
|
||||||
|
|||||||
71
cmd/gf/internal/cmd/testdata/build/varmap/go.sum
vendored
71
cmd/gf/internal/cmd/testdata/build/varmap/go.sum
vendored
@ -1,29 +1,62 @@
|
|||||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||||
|
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
|
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
|
||||||
|
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
||||||
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
|
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
|
||||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
|
||||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
|
||||||
|
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||||
|
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||||
|
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||||
|
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
|
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
|
||||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
|
||||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE=
|
||||||
|
github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||||
|
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||||
|
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
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/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
|
||||||
|
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5sM=
|
||||||
|
github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
|
||||||
|
github.com/olekukonko/ll v0.0.9 h1:Y+1YqDfVkqMWuEQMclsF9HUR5+a82+dxJuL1HHSRpxI=
|
||||||
|
github.com/olekukonko/ll v0.0.9/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
|
||||||
|
github.com/olekukonko/tablewriter v1.0.9 h1:XGwRsYLC2bY7bNd93Dk51bcPZksWZmLYuaTHR0FqfL8=
|
||||||
|
github.com/olekukonko/tablewriter v1.0.9/go.mod h1:5c+EBPeSqvXnLLgkm9isDdzR3wjfBkHR9Nhfp3NWrzo=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
|
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||||
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
|
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||||
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
|
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
|
||||||
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
|
go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
|
||||||
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE=
|
||||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E=
|
||||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
go.opentelemetry.io/otel/sdk v1.37.0 h1:ItB0QUqnjesGRvNcmAcU0LyvkVyGJ2xftD29bWdDvKI=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.37.0/go.mod h1:VredYzxUvuo2q3WRcDnKDjbdvmO0sCzOvVAiY+yUkAg=
|
||||||
|
go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
|
||||||
|
go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
|
||||||
|
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
||||||
|
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
||||||
|
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||||
|
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
|
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
||||||
|
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
@ -9,6 +9,7 @@ package v1
|
|||||||
import "github.com/gogf/gf/v2/frame/g"
|
import "github.com/gogf/gf/v2/frame/g"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// CreateReq add title.
|
||||||
CreateReq struct {
|
CreateReq struct {
|
||||||
g.Meta `path:"/article/create" method:"post" tags:"ArticleService"`
|
g.Meta `path:"/article/create" method:"post" tags:"ArticleService"`
|
||||||
Title string `v:"required"`
|
Title string `v:"required"`
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/testdata/genctrl/api/article/v1"
|
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/testdata/genctrl/api/article/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Create add title.
|
||||||
func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) {
|
func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) {
|
||||||
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,9 +13,10 @@ import (
|
|||||||
|
|
||||||
// TableUserDao is the data access object for the table table_user.
|
// TableUserDao is the data access object for the table table_user.
|
||||||
type TableUserDao struct {
|
type TableUserDao struct {
|
||||||
table string // table is the underlying table name of the DAO.
|
table string // table is the underlying table name of the DAO.
|
||||||
group string // group is the database configuration group name of the current DAO.
|
group string // group is the database configuration group name of the current DAO.
|
||||||
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
handlers []gdb.ModelHandler // handlers for customized model modification.
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableUserColumns defines and stores column names for the table table_user.
|
// TableUserColumns defines and stores column names for the table table_user.
|
||||||
@ -41,11 +42,12 @@ var tableUserColumns = TableUserColumns{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTableUserDao creates and returns a new DAO object for table data access.
|
// NewTableUserDao creates and returns a new DAO object for table data access.
|
||||||
func NewTableUserDao() *TableUserDao {
|
func NewTableUserDao(handlers ...gdb.ModelHandler) *TableUserDao {
|
||||||
return &TableUserDao{
|
return &TableUserDao{
|
||||||
group: "test",
|
group: "test",
|
||||||
table: "table_user",
|
table: "table_user",
|
||||||
columns: tableUserColumns,
|
columns: tableUserColumns,
|
||||||
|
handlers: handlers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +73,11 @@ func (dao *TableUserDao) Group() string {
|
|||||||
|
|
||||||
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
||||||
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
model := dao.DB().Model(dao.table)
|
||||||
|
for _, handler := range dao.handlers {
|
||||||
|
model = handler(model)
|
||||||
|
}
|
||||||
|
return model.Safe().Ctx(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transaction wraps the transaction logic using function f.
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
|||||||
@ -8,20 +8,15 @@ import (
|
|||||||
"for-gendao-test/pkg/dao/internal"
|
"for-gendao-test/pkg/dao/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// internalTableUserDao is an internal type for wrapping the internal DAO implementation.
|
|
||||||
type internalTableUserDao = *internal.TableUserDao
|
|
||||||
|
|
||||||
// tableUserDao is the data access object for the table table_user.
|
// tableUserDao is the data access object for the table table_user.
|
||||||
// You can define custom methods on it to extend its functionality as needed.
|
// You can define custom methods on it to extend its functionality as needed.
|
||||||
type tableUserDao struct {
|
type tableUserDao struct {
|
||||||
internalTableUserDao
|
*internal.TableUserDao
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// TableUser is a globally accessible object for table table_user operations.
|
// TableUser is a globally accessible object for table table_user operations.
|
||||||
TableUser = tableUserDao{
|
TableUser = tableUserDao{internal.NewTableUserDao()}
|
||||||
internal.NewTableUserDao(),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add your custom methods and functionality below.
|
// Add your custom methods and functionality below.
|
||||||
|
|||||||
@ -12,11 +12,11 @@ import (
|
|||||||
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
||||||
type TableUser struct {
|
type TableUser struct {
|
||||||
g.Meta `orm:"table:table_user, do:true"`
|
g.Meta `orm:"table:table_user, do:true"`
|
||||||
Id interface{} // User ID
|
Id any // User ID
|
||||||
Passport interface{} // User Passport
|
Passport any // User Passport
|
||||||
Password interface{} // User Password
|
Password any // User Password
|
||||||
Nickname interface{} // User Nickname
|
Nickname any // User Nickname
|
||||||
Score interface{} // Total score amount.
|
Score any // Total score amount.
|
||||||
CreateAt *gtime.Time // Created Time
|
CreateAt *gtime.Time // Created Time
|
||||||
UpdateAt *gtime.Time // Updated Time
|
UpdateAt *gtime.Time // Updated Time
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,9 +13,10 @@ import (
|
|||||||
|
|
||||||
// TableUserDao is the data access object for the table table_user.
|
// TableUserDao is the data access object for the table table_user.
|
||||||
type TableUserDao struct {
|
type TableUserDao struct {
|
||||||
table string // table is the underlying table name of the DAO.
|
table string // table is the underlying table name of the DAO.
|
||||||
group string // group is the database configuration group name of the current DAO.
|
group string // group is the database configuration group name of the current DAO.
|
||||||
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
handlers []gdb.ModelHandler // handlers for customized model modification.
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableUserColumns defines and stores column names for the table table_user.
|
// TableUserColumns defines and stores column names for the table table_user.
|
||||||
@ -41,11 +42,12 @@ var tableUserColumns = TableUserColumns{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTableUserDao creates and returns a new DAO object for table data access.
|
// NewTableUserDao creates and returns a new DAO object for table data access.
|
||||||
func NewTableUserDao() *TableUserDao {
|
func NewTableUserDao(handlers ...gdb.ModelHandler) *TableUserDao {
|
||||||
return &TableUserDao{
|
return &TableUserDao{
|
||||||
group: "test",
|
group: "test",
|
||||||
table: "table_user",
|
table: "table_user",
|
||||||
columns: tableUserColumns,
|
columns: tableUserColumns,
|
||||||
|
handlers: handlers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +73,11 @@ func (dao *TableUserDao) Group() string {
|
|||||||
|
|
||||||
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
||||||
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
model := dao.DB().Model(dao.table)
|
||||||
|
for _, handler := range dao.handlers {
|
||||||
|
model = handler(model)
|
||||||
|
}
|
||||||
|
return model.Safe().Ctx(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transaction wraps the transaction logic using function f.
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
|||||||
@ -8,20 +8,15 @@ import (
|
|||||||
"for-gendao-test/pkg/dao/internal"
|
"for-gendao-test/pkg/dao/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// internalTableUserDao is an internal type for wrapping the internal DAO implementation.
|
|
||||||
type internalTableUserDao = *internal.TableUserDao
|
|
||||||
|
|
||||||
// tableUserDao is the data access object for the table table_user.
|
// tableUserDao is the data access object for the table table_user.
|
||||||
// You can define custom methods on it to extend its functionality as needed.
|
// You can define custom methods on it to extend its functionality as needed.
|
||||||
type tableUserDao struct {
|
type tableUserDao struct {
|
||||||
internalTableUserDao
|
*internal.TableUserDao
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// TableUser is a globally accessible object for table table_user operations.
|
// TableUser is a globally accessible object for table table_user operations.
|
||||||
TableUser = tableUserDao{
|
TableUser = tableUserDao{internal.NewTableUserDao()}
|
||||||
internal.NewTableUserDao(),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add your custom methods and functionality below.
|
// Add your custom methods and functionality below.
|
||||||
|
|||||||
@ -12,11 +12,11 @@ import (
|
|||||||
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
||||||
type TableUser struct {
|
type TableUser struct {
|
||||||
g.Meta `orm:"table:table_user, do:true"`
|
g.Meta `orm:"table:table_user, do:true"`
|
||||||
Id interface{} // User ID
|
Id any // User ID
|
||||||
Passport interface{} // User Passport
|
Passport any // User Passport
|
||||||
Password interface{} // User Password
|
Password any // User Password
|
||||||
Nickname interface{} // User Nickname
|
Nickname any // User Nickname
|
||||||
Score interface{} // Total score amount.
|
Score any // Total score amount.
|
||||||
CreateAt *gtime.Time // Created Time
|
CreateAt *gtime.Time // Created Time
|
||||||
UpdateAt *gtime.Time // Updated Time
|
UpdateAt *gtime.Time // Updated Time
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,9 +13,10 @@ import (
|
|||||||
|
|
||||||
// TableUserDao is the data access object for the table table_user.
|
// TableUserDao is the data access object for the table table_user.
|
||||||
type TableUserDao struct {
|
type TableUserDao struct {
|
||||||
table string // table is the underlying table name of the DAO.
|
table string // table is the underlying table name of the DAO.
|
||||||
group string // group is the database configuration group name of the current DAO.
|
group string // group is the database configuration group name of the current DAO.
|
||||||
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
handlers []gdb.ModelHandler // handlers for customized model modification.
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableUserColumns defines and stores column names for the table table_user.
|
// TableUserColumns defines and stores column names for the table table_user.
|
||||||
@ -39,11 +40,12 @@ var tableUserColumns = TableUserColumns{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTableUserDao creates and returns a new DAO object for table data access.
|
// NewTableUserDao creates and returns a new DAO object for table data access.
|
||||||
func NewTableUserDao() *TableUserDao {
|
func NewTableUserDao(handlers ...gdb.ModelHandler) *TableUserDao {
|
||||||
return &TableUserDao{
|
return &TableUserDao{
|
||||||
group: "test",
|
group: "test",
|
||||||
table: "table_user",
|
table: "table_user",
|
||||||
columns: tableUserColumns,
|
columns: tableUserColumns,
|
||||||
|
handlers: handlers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +71,11 @@ func (dao *TableUserDao) Group() string {
|
|||||||
|
|
||||||
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
||||||
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
model := dao.DB().Model(dao.table)
|
||||||
|
for _, handler := range dao.handlers {
|
||||||
|
model = handler(model)
|
||||||
|
}
|
||||||
|
return model.Safe().Ctx(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transaction wraps the transaction logic using function f.
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
|||||||
@ -8,20 +8,15 @@ import (
|
|||||||
"for-gendao-test/pkg/dao/internal"
|
"for-gendao-test/pkg/dao/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// internalTableUserDao is an internal type for wrapping the internal DAO implementation.
|
|
||||||
type internalTableUserDao = *internal.TableUserDao
|
|
||||||
|
|
||||||
// tableUserDao is the data access object for the table table_user.
|
// tableUserDao is the data access object for the table table_user.
|
||||||
// You can define custom methods on it to extend its functionality as needed.
|
// You can define custom methods on it to extend its functionality as needed.
|
||||||
type tableUserDao struct {
|
type tableUserDao struct {
|
||||||
internalTableUserDao
|
*internal.TableUserDao
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// TableUser is a globally accessible object for table table_user operations.
|
// TableUser is a globally accessible object for table table_user operations.
|
||||||
TableUser = tableUserDao{
|
TableUser = tableUserDao{internal.NewTableUserDao()}
|
||||||
internal.NewTableUserDao(),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add your custom methods and functionality below.
|
// Add your custom methods and functionality below.
|
||||||
|
|||||||
@ -12,10 +12,10 @@ import (
|
|||||||
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
||||||
type TableUser struct {
|
type TableUser struct {
|
||||||
g.Meta `orm:"table:table_user, do:true"`
|
g.Meta `orm:"table:table_user, do:true"`
|
||||||
Id interface{} //
|
Id any //
|
||||||
Passport interface{} //
|
Passport any //
|
||||||
Password interface{} //
|
Password any //
|
||||||
Nickname interface{} //
|
Nickname any //
|
||||||
CreatedAt *gtime.Time //
|
CreatedAt *gtime.Time //
|
||||||
UpdatedAt *gtime.Time //
|
UpdatedAt *gtime.Time //
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,9 +13,10 @@ import (
|
|||||||
|
|
||||||
// TableUserDao is the data access object for the table table_user.
|
// TableUserDao is the data access object for the table table_user.
|
||||||
type TableUserDao struct {
|
type TableUserDao struct {
|
||||||
table string // table is the underlying table name of the DAO.
|
table string // table is the underlying table name of the DAO.
|
||||||
group string // group is the database configuration group name of the current DAO.
|
group string // group is the database configuration group name of the current DAO.
|
||||||
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
handlers []gdb.ModelHandler // handlers for customized model modification.
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableUserColumns defines and stores column names for the table table_user.
|
// TableUserColumns defines and stores column names for the table table_user.
|
||||||
@ -41,11 +42,12 @@ var tableUserColumns = TableUserColumns{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTableUserDao creates and returns a new DAO object for table data access.
|
// NewTableUserDao creates and returns a new DAO object for table data access.
|
||||||
func NewTableUserDao() *TableUserDao {
|
func NewTableUserDao(handlers ...gdb.ModelHandler) *TableUserDao {
|
||||||
return &TableUserDao{
|
return &TableUserDao{
|
||||||
group: "test",
|
group: "test",
|
||||||
table: "table_user",
|
table: "table_user",
|
||||||
columns: tableUserColumns,
|
columns: tableUserColumns,
|
||||||
|
handlers: handlers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +73,11 @@ func (dao *TableUserDao) Group() string {
|
|||||||
|
|
||||||
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
||||||
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
model := dao.DB().Model(dao.table)
|
||||||
|
for _, handler := range dao.handlers {
|
||||||
|
model = handler(model)
|
||||||
|
}
|
||||||
|
return model.Safe().Ctx(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transaction wraps the transaction logic using function f.
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
|||||||
@ -8,20 +8,15 @@ import (
|
|||||||
"for-gendao-test/pkg/dao/internal"
|
"for-gendao-test/pkg/dao/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// internalTableUserDao is an internal type for wrapping the internal DAO implementation.
|
|
||||||
type internalTableUserDao = *internal.TableUserDao
|
|
||||||
|
|
||||||
// tableUserDao is the data access object for the table table_user.
|
// tableUserDao is the data access object for the table table_user.
|
||||||
// You can define custom methods on it to extend its functionality as needed.
|
// You can define custom methods on it to extend its functionality as needed.
|
||||||
type tableUserDao struct {
|
type tableUserDao struct {
|
||||||
internalTableUserDao
|
*internal.TableUserDao
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// TableUser is a globally accessible object for table table_user operations.
|
// TableUser is a globally accessible object for table table_user operations.
|
||||||
TableUser = tableUserDao{
|
TableUser = tableUserDao{internal.NewTableUserDao()}
|
||||||
internal.NewTableUserDao(),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add your custom methods and functionality below.
|
// Add your custom methods and functionality below.
|
||||||
|
|||||||
@ -12,11 +12,11 @@ import (
|
|||||||
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
||||||
type TableUser struct {
|
type TableUser struct {
|
||||||
g.Meta `orm:"table:table_user, do:true"`
|
g.Meta `orm:"table:table_user, do:true"`
|
||||||
Id interface{} // User ID
|
Id any // User ID
|
||||||
Passport interface{} // User Passport
|
Passport any // User Passport
|
||||||
Password interface{} // User Password
|
Password any // User Password
|
||||||
Nickname interface{} // User Nickname
|
Nickname any // User Nickname
|
||||||
Score interface{} // Total score amount.
|
Score any // Total score amount.
|
||||||
CreateAt *gtime.Time // Created Time
|
CreateAt *gtime.Time // Created Time
|
||||||
UpdateAt *gtime.Time // Updated Time
|
UpdateAt *gtime.Time // Updated Time
|
||||||
}
|
}
|
||||||
|
|||||||
55
cmd/gf/internal/cmd/testdata/gendao/sharding/sharding.sql
vendored
Normal file
55
cmd/gf/internal/cmd/testdata/gendao/sharding/sharding.sql
vendored
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
CREATE TABLE `single_table`
|
||||||
|
(
|
||||||
|
`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;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE `users_0001`
|
||||||
|
(
|
||||||
|
`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;
|
||||||
|
|
||||||
|
CREATE TABLE `users_0002`
|
||||||
|
(
|
||||||
|
`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;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE `orders_0001`
|
||||||
|
(
|
||||||
|
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ORDER ID',
|
||||||
|
`amount` decimal(10, 2) unsigned DEFAULT NULL COMMENT 'Total 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;
|
||||||
|
|
||||||
|
CREATE TABLE `orders_0002`
|
||||||
|
(
|
||||||
|
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ORDER ID',
|
||||||
|
`amount` decimal(10, 2) unsigned DEFAULT NULL COMMENT 'Total 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;
|
||||||
@ -63,14 +63,14 @@ func (s *sArticle) T3(ctx context.Context, b *gdbas.Model) (c, d *gdbas.Model, e
|
|||||||
* random comment
|
* random comment
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// func (s *sArticle) T4(i interface{}) interface{}
|
// func (s *sArticle) T4(i any) any
|
||||||
// # $ % ^ & * ( ) _ + - = { } | [ ] \ : " ; ' < > ? , . /
|
// # $ % ^ & * ( ) _ + - = { } | [ ] \ : " ; ' < > ? , . /
|
||||||
func (s *sArticle) T4(i interface{}) interface{} {
|
func (s *sArticle) T4(i any) any {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* func (s *sArticle) T4(i interface{}) interface{} {
|
* func (s *sArticle) T4(i any) any {
|
||||||
* return nil
|
* return nil
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -36,9 +36,9 @@ type (
|
|||||||
* @author oldme
|
* @author oldme
|
||||||
*/
|
*/
|
||||||
T3(ctx context.Context, b *gdbas.Model) (c *gdbas.Model, d *gdbas.Model, err error)
|
T3(ctx context.Context, b *gdbas.Model) (c *gdbas.Model, d *gdbas.Model, err error)
|
||||||
// func (s *sArticle) T4(i interface{}) interface{}
|
// func (s *sArticle) T4(i any) any
|
||||||
// # $ % ^ & * ( ) _ + - = { } | [ ] \ : " ; ' < > ? , . /
|
// # $ % ^ & * ( ) _ + - = { } | [ ] \ : " ; ' < > ? , . /
|
||||||
T4(i interface{}) interface{}
|
T4(i any) any
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -12,11 +12,11 @@ import (
|
|||||||
// User1 is the golang structure of table user1 for DAO operations like Where/Data.
|
// User1 is the golang structure of table user1 for DAO operations like Where/Data.
|
||||||
type User1 struct {
|
type User1 struct {
|
||||||
g.Meta `orm:"table:user1, do:true"`
|
g.Meta `orm:"table:user1, do:true"`
|
||||||
Id interface{} // User ID
|
Id any // User ID
|
||||||
Passport interface{} // User Passport
|
Passport any // User Passport
|
||||||
Password interface{} // User Password
|
Password any // User Password
|
||||||
Nickname interface{} // User Nickname
|
Nickname any // User Nickname
|
||||||
Score interface{} // Total score amount.
|
Score any // Total score amount.
|
||||||
CreateAt *gtime.Time // Created Time
|
CreateAt *gtime.Time // Created Time
|
||||||
UpdateAt *gtime.Time // Updated Time
|
UpdateAt *gtime.Time // Updated Time
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,11 +12,11 @@ import (
|
|||||||
// User2 is the golang structure of table user2 for DAO operations like Where/Data.
|
// User2 is the golang structure of table user2 for DAO operations like Where/Data.
|
||||||
type User2 struct {
|
type User2 struct {
|
||||||
g.Meta `orm:"table:user2, do:true"`
|
g.Meta `orm:"table:user2, do:true"`
|
||||||
Id interface{} // User ID
|
Id any // User ID
|
||||||
Passport interface{} // User Passport
|
Passport any // User Passport
|
||||||
Password interface{} // User Password
|
Password any // User Password
|
||||||
Nickname interface{} // User Nickname
|
Nickname any // User Nickname
|
||||||
Score interface{} // Total score amount.
|
Score any // Total score amount.
|
||||||
CreateAt *gtime.Time // Created Time
|
CreateAt *gtime.Time // Created Time
|
||||||
UpdateAt *gtime.Time // Updated Time
|
UpdateAt *gtime.Time // Updated Time
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,11 +12,11 @@ import (
|
|||||||
// User1 is the golang structure of table user1 for DAO operations like Where/Data.
|
// User1 is the golang structure of table user1 for DAO operations like Where/Data.
|
||||||
type User1 struct {
|
type User1 struct {
|
||||||
g.Meta `orm:"table:user1, do:true"`
|
g.Meta `orm:"table:user1, do:true"`
|
||||||
Id interface{} // User ID
|
Id any // User ID
|
||||||
Passport interface{} // User Passport
|
Passport any // User Passport
|
||||||
Password interface{} // User Password
|
Password any // User Password
|
||||||
Nickname interface{} // User Nickname
|
Nickname any // User Nickname
|
||||||
Score interface{} // Total score amount.
|
Score any // Total score amount.
|
||||||
CreateAt *gtime.Time // Created Time
|
CreateAt *gtime.Time // Created Time
|
||||||
UpdateAt *gtime.Time // Updated Time
|
UpdateAt *gtime.Time // Updated Time
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,11 +12,11 @@ import (
|
|||||||
// User2 is the golang structure of table user2 for DAO operations like Where/Data.
|
// User2 is the golang structure of table user2 for DAO operations like Where/Data.
|
||||||
type User2 struct {
|
type User2 struct {
|
||||||
g.Meta `orm:"table:user2, do:true"`
|
g.Meta `orm:"table:user2, do:true"`
|
||||||
Id interface{} // User ID
|
Id any // User ID
|
||||||
Passport interface{} // User Passport
|
Passport any // User Passport
|
||||||
Password interface{} // User Password
|
Password any // User Password
|
||||||
Nickname interface{} // User Nickname
|
Nickname any // User Nickname
|
||||||
Score interface{} // Total score amount.
|
Score any // Total score amount.
|
||||||
CreateAt *gtime.Time // Created Time
|
CreateAt *gtime.Time // Created Time
|
||||||
UpdateAt *gtime.Time // Updated Time
|
UpdateAt *gtime.Time // Updated Time
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,9 +13,10 @@ import (
|
|||||||
|
|
||||||
// TableUserDao is the data access object for the table table_user.
|
// TableUserDao is the data access object for the table table_user.
|
||||||
type TableUserDao struct {
|
type TableUserDao struct {
|
||||||
table string // table is the underlying table name of the DAO.
|
table string // table is the underlying table name of the DAO.
|
||||||
group string // group is the database configuration group name of the current DAO.
|
group string // group is the database configuration group name of the current DAO.
|
||||||
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
columns TableUserColumns // columns contains all the column names of Table for convenient usage.
|
||||||
|
handlers []gdb.ModelHandler // handlers for customized model modification.
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableUserColumns defines and stores column names for the table table_user.
|
// TableUserColumns defines and stores column names for the table table_user.
|
||||||
@ -41,11 +42,12 @@ var tableUserColumns = TableUserColumns{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewTableUserDao creates and returns a new DAO object for table data access.
|
// NewTableUserDao creates and returns a new DAO object for table data access.
|
||||||
func NewTableUserDao() *TableUserDao {
|
func NewTableUserDao(handlers ...gdb.ModelHandler) *TableUserDao {
|
||||||
return &TableUserDao{
|
return &TableUserDao{
|
||||||
group: "test",
|
group: "test",
|
||||||
table: "table_user",
|
table: "table_user",
|
||||||
columns: tableUserColumns,
|
columns: tableUserColumns,
|
||||||
|
handlers: handlers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +73,11 @@ func (dao *TableUserDao) Group() string {
|
|||||||
|
|
||||||
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
||||||
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
func (dao *TableUserDao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
model := dao.DB().Model(dao.table)
|
||||||
|
for _, handler := range dao.handlers {
|
||||||
|
model = handler(model)
|
||||||
|
}
|
||||||
|
return model.Safe().Ctx(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transaction wraps the transaction logic using function f.
|
// Transaction wraps the transaction logic using function f.
|
||||||
|
|||||||
@ -8,20 +8,15 @@ import (
|
|||||||
"for-gendao-test/pkg/dao/internal"
|
"for-gendao-test/pkg/dao/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// internalTableUserDao is an internal type for wrapping the internal DAO implementation.
|
|
||||||
type internalTableUserDao = *internal.TableUserDao
|
|
||||||
|
|
||||||
// tableUserDao is the data access object for the table table_user.
|
// tableUserDao is the data access object for the table table_user.
|
||||||
// You can define custom methods on it to extend its functionality as needed.
|
// You can define custom methods on it to extend its functionality as needed.
|
||||||
type tableUserDao struct {
|
type tableUserDao struct {
|
||||||
internalTableUserDao
|
*internal.TableUserDao
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// TableUser is a globally accessible object for table table_user operations.
|
// TableUser is a globally accessible object for table table_user operations.
|
||||||
TableUser = tableUserDao{
|
TableUser = tableUserDao{internal.NewTableUserDao()}
|
||||||
internal.NewTableUserDao(),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Add your custom methods and functionality below.
|
// Add your custom methods and functionality below.
|
||||||
|
|||||||
@ -12,11 +12,11 @@ import (
|
|||||||
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
// TableUser is the golang structure of table table_user for DAO operations like Where/Data.
|
||||||
type TableUser struct {
|
type TableUser struct {
|
||||||
g.Meta `orm:"table:table_user, do:true"`
|
g.Meta `orm:"table:table_user, do:true"`
|
||||||
Id interface{} // User ID
|
Id any // User ID
|
||||||
ParentId interface{} //
|
ParentId any //
|
||||||
Passport interface{} // User Passport
|
Passport any // User Passport
|
||||||
PassWord interface{} // User Password
|
PassWord any // User Password
|
||||||
Nickname2 interface{} // User Nickname
|
Nickname2 any // User Nickname
|
||||||
CreateAt *gtime.Time // Created Time
|
CreateAt *gtime.Time // Created Time
|
||||||
UpdateAt *gtime.Time // Updated Time
|
UpdateAt *gtime.Time // Updated Time
|
||||||
}
|
}
|
||||||
|
|||||||
23
cmd/gf/internal/cmd/testdata/issue/4330/issue4330_double.proto
vendored
Normal file
23
cmd/gf/internal/cmd/testdata/issue/4330/issue4330_double.proto
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package pbentity;
|
||||||
|
|
||||||
|
option go_package = "github.com/gogf/gf/cmd/gf/v2/internal/cmd/api/pbentity";
|
||||||
|
|
||||||
|
import "google/protobuf/struct.proto";
|
||||||
|
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
|
||||||
|
double Score = 5; // Total score amount.
|
||||||
|
google.protobuf.Value Data = 6; // User Data
|
||||||
|
google.protobuf.Timestamp CreateAt = 7; // Created Time
|
||||||
|
google.protobuf.Timestamp UpdateAt = 8; // Updated Time
|
||||||
|
}
|
||||||
23
cmd/gf/internal/cmd/testdata/issue/4330/issue4330_string.proto
vendored
Normal file
23
cmd/gf/internal/cmd/testdata/issue/4330/issue4330_string.proto
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package pbentity;
|
||||||
|
|
||||||
|
option go_package = "github.com/gogf/gf/cmd/gf/v2/internal/cmd/api/pbentity";
|
||||||
|
|
||||||
|
import "google/protobuf/struct.proto";
|
||||||
|
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.Value Data = 6; // User Data
|
||||||
|
google.protobuf.Timestamp CreateAt = 7; // Created Time
|
||||||
|
google.protobuf.Timestamp UpdateAt = 8; // Updated Time
|
||||||
|
}
|
||||||
@ -45,7 +45,7 @@ import (
|
|||||||
|
|
||||||
"{ImportPath}"
|
"{ImportPath}"
|
||||||
)
|
)
|
||||||
|
{MethodComment}
|
||||||
func (c *{CtrlName}) {MethodName}(ctx context.Context, req *{Version}.{MethodName}Req) (res *{Version}.{MethodName}Res, err error) {
|
func (c *{CtrlName}) {MethodName}(ctx context.Context, req *{Version}.{MethodName}Req) (res *{Version}.{MethodName}Res, err error) {
|
||||||
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
||||||
}
|
}
|
||||||
@ -66,7 +66,7 @@ import (
|
|||||||
`
|
`
|
||||||
|
|
||||||
const TemplateGenCtrlControllerMethodFuncMerge = `
|
const TemplateGenCtrlControllerMethodFuncMerge = `
|
||||||
|
{MethodComment}
|
||||||
func (c *{CtrlName}) {MethodName}(ctx context.Context, req *{Version}.{MethodName}Req) (res *{Version}.{MethodName}Res, err error) {
|
func (c *{CtrlName}) {MethodName}(ctx context.Context, req *{Version}.{MethodName}Req) (res *{Version}.{MethodName}Res, err error) {
|
||||||
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
return nil, gerror.NewCode(gcode.CodeNotImplemented)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,7 +81,7 @@ func (i *implementer) {ImplementerName}() {Module}.I{ImplementerName} {
|
|||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
const TemplateGenCtrlSdkImplementerFunc = `
|
const TemplateGenCtrlSdkImplementerFunc = `{MethodComment}
|
||||||
func (i *implementer{ImplementerName}) {MethodName}(ctx context.Context, req *{Version}.{MethodName}Req) (res *{Version}.{MethodName}Res, err error) {
|
func (i *implementer{ImplementerName}) {MethodName}(ctx context.Context, req *{Version}.{MethodName}Req) (res *{Version}.{MethodName}Res, err error) {
|
||||||
err = i.Request(ctx, req, &res)
|
err = i.Request(ctx, req, &res)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -11,35 +11,54 @@ const TemplateGenDaoIndexContent = `
|
|||||||
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
|
// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
|
||||||
// =================================================================================
|
// =================================================================================
|
||||||
|
|
||||||
package {TplPackageName}
|
package {{.TplPackageName}}
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"{TplImportPrefix}/internal"
|
"{{.TplImportPrefix}}/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// internal{TplTableNameCamelCase}Dao is an internal type for wrapping the internal DAO implementation.
|
// {{.TplTableNameCamelLowerCase}}Dao is the data access object for the table {{.TplTableName}}.
|
||||||
type internal{TplTableNameCamelCase}Dao = *internal.{TplTableNameCamelCase}Dao
|
|
||||||
|
|
||||||
// {TplTableNameCamelLowerCase}Dao is the data access object for the table {TplTableName}.
|
|
||||||
// You can define custom methods on it to extend its functionality as needed.
|
// You can define custom methods on it to extend its functionality as needed.
|
||||||
type {TplTableNameCamelLowerCase}Dao struct {
|
type {{.TplTableNameCamelLowerCase}}Dao struct {
|
||||||
internal{TplTableNameCamelCase}Dao
|
*internal.{{.TplTableNameCamelCase}}Dao
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// {TplTableNameCamelCase} is a globally accessible object for table {TplTableName} operations.
|
// {{.TplTableNameCamelCase}} is a globally accessible object for table {{.TplTableName}} operations.
|
||||||
{TplTableNameCamelCase} = {TplTableNameCamelLowerCase}Dao{
|
{{.TplTableNameCamelCase}} = {{.TplTableNameCamelLowerCase}}Dao{
|
||||||
internal.New{TplTableNameCamelCase}Dao(),
|
{{- if .TplTableSharding -}}
|
||||||
|
internal.New{{.TplTableNameCamelCase}}Dao({{.TplTableNameCamelLowerCase}}ShardingHandler),
|
||||||
|
{{- else -}}
|
||||||
|
internal.New{{.TplTableNameCamelCase}}Dao(),
|
||||||
|
{{- end -}}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
{{if .TplTableSharding -}}
|
||||||
|
// {{.TplTableNameCamelLowerCase}}ShardingHandler is the handler for sharding operations.
|
||||||
|
// You can fill this sharding handler with your custom implementation.
|
||||||
|
func {{.TplTableNameCamelLowerCase}}ShardingHandler(m *gdb.Model) *gdb.Model {
|
||||||
|
m = m.Sharding(gdb.ShardingConfig{
|
||||||
|
Table: gdb.ShardingTableConfig{
|
||||||
|
Enable: true,
|
||||||
|
Prefix: "{{.TplTableShardingPrefix}}",
|
||||||
|
// Replace Rule field with your custom sharding rule.
|
||||||
|
// Or you can use "&gdb.DefaultShardingRule{}" for default sharding rule.
|
||||||
|
Rule: nil,
|
||||||
|
},
|
||||||
|
Schema: gdb.ShardingSchemaConfig{},
|
||||||
|
})
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
{{- end}}
|
||||||
|
|
||||||
// Add your custom methods and functionality below.
|
// Add your custom methods and functionality below.
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
const TemplateGenDaoInternalContent = `
|
const TemplateGenDaoInternalContent = `
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. {TplCreatedAtDatetimeStr}
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. {{.TplCreatedAtDatetimeStr}}
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
package internal
|
package internal
|
||||||
@ -51,55 +70,61 @@ import (
|
|||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
)
|
)
|
||||||
|
|
||||||
// {TplTableNameCamelCase}Dao is the data access object for the table {TplTableName}.
|
// {{.TplTableNameCamelCase}}Dao is the data access object for the table {{.TplTableName}}.
|
||||||
type {TplTableNameCamelCase}Dao struct {
|
type {{.TplTableNameCamelCase}}Dao struct {
|
||||||
table string // table is the underlying table name of the DAO.
|
table string // table is the underlying table name of the DAO.
|
||||||
group string // group is the database configuration group name of the current DAO.
|
group string // group is the database configuration group name of the current DAO.
|
||||||
columns {TplTableNameCamelCase}Columns // columns contains all the column names of Table for convenient usage.
|
columns {{.TplTableNameCamelCase}}Columns // columns contains all the column names of Table for convenient usage.
|
||||||
|
handlers []gdb.ModelHandler // handlers for customized model modification.
|
||||||
}
|
}
|
||||||
|
|
||||||
// {TplTableNameCamelCase}Columns defines and stores column names for the table {TplTableName}.
|
// {{.TplTableNameCamelCase}}Columns defines and stores column names for the table {{.TplTableName}}.
|
||||||
type {TplTableNameCamelCase}Columns struct {
|
type {{.TplTableNameCamelCase}}Columns struct {
|
||||||
{TplColumnDefine}
|
{{.TplColumnDefine}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// {TplTableNameCamelLowerCase}Columns holds the columns for the table {TplTableName}.
|
// {{.TplTableNameCamelLowerCase}}Columns holds the columns for the table {{.TplTableName}}.
|
||||||
var {TplTableNameCamelLowerCase}Columns = {TplTableNameCamelCase}Columns{
|
var {{.TplTableNameCamelLowerCase}}Columns = {{.TplTableNameCamelCase}}Columns{
|
||||||
{TplColumnNames}
|
{{.TplColumnNames}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// New{TplTableNameCamelCase}Dao creates and returns a new DAO object for table data access.
|
// New{{.TplTableNameCamelCase}}Dao creates and returns a new DAO object for table data access.
|
||||||
func New{TplTableNameCamelCase}Dao() *{TplTableNameCamelCase}Dao {
|
func New{{.TplTableNameCamelCase}}Dao(handlers ...gdb.ModelHandler) *{{.TplTableNameCamelCase}}Dao {
|
||||||
return &{TplTableNameCamelCase}Dao{
|
return &{{.TplTableNameCamelCase}}Dao{
|
||||||
group: "{TplGroupName}",
|
group: "{{.TplGroupName}}",
|
||||||
table: "{TplTableName}",
|
table: "{{.TplTableName}}",
|
||||||
columns: {TplTableNameCamelLowerCase}Columns,
|
columns: {{.TplTableNameCamelLowerCase}}Columns,
|
||||||
|
handlers: handlers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DB retrieves and returns the underlying raw database management object of the current DAO.
|
// DB retrieves and returns the underlying raw database management object of the current DAO.
|
||||||
func (dao *{TplTableNameCamelCase}Dao) DB() gdb.DB {
|
func (dao *{{.TplTableNameCamelCase}}Dao) DB() gdb.DB {
|
||||||
return g.DB(dao.group)
|
return g.DB(dao.group)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Table returns the table name of the current DAO.
|
// Table returns the table name of the current DAO.
|
||||||
func (dao *{TplTableNameCamelCase}Dao) Table() string {
|
func (dao *{{.TplTableNameCamelCase}}Dao) Table() string {
|
||||||
return dao.table
|
return dao.table
|
||||||
}
|
}
|
||||||
|
|
||||||
// Columns returns all column names of the current DAO.
|
// Columns returns all column names of the current DAO.
|
||||||
func (dao *{TplTableNameCamelCase}Dao) Columns() {TplTableNameCamelCase}Columns {
|
func (dao *{{.TplTableNameCamelCase}}Dao) Columns() {{.TplTableNameCamelCase}}Columns {
|
||||||
return dao.columns
|
return dao.columns
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group returns the database configuration group name of the current DAO.
|
// Group returns the database configuration group name of the current DAO.
|
||||||
func (dao *{TplTableNameCamelCase}Dao) Group() string {
|
func (dao *{{.TplTableNameCamelCase}}Dao) Group() string {
|
||||||
return dao.group
|
return dao.group
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
|
||||||
func (dao *{TplTableNameCamelCase}Dao) Ctx(ctx context.Context) *gdb.Model {
|
func (dao *{{.TplTableNameCamelCase}}Dao) Ctx(ctx context.Context) *gdb.Model {
|
||||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx)
|
model := dao.DB().Model(dao.table)
|
||||||
|
for _, handler := range dao.handlers {
|
||||||
|
model = handler(model)
|
||||||
|
}
|
||||||
|
return model.Safe().Ctx(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transaction wraps the transaction logic using function f.
|
// Transaction wraps the transaction logic using function f.
|
||||||
@ -108,7 +133,7 @@ func (dao *{TplTableNameCamelCase}Dao) Ctx(ctx context.Context) *gdb.Model {
|
|||||||
//
|
//
|
||||||
// Note: Do not commit or roll back the transaction in function f,
|
// Note: Do not commit or roll back the transaction in function f,
|
||||||
// as it is automatically handled by this function.
|
// as it is automatically handled by this function.
|
||||||
func (dao *{TplTableNameCamelCase}Dao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
func (dao *{{.TplTableNameCamelCase}}Dao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
|
||||||
return dao.Ctx(ctx).Transaction(ctx, f)
|
return dao.Ctx(ctx).Transaction(ctx, f)
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|||||||
@ -8,13 +8,13 @@ package consts
|
|||||||
|
|
||||||
const TemplateGenDaoDoContent = `
|
const TemplateGenDaoDoContent = `
|
||||||
// =================================================================================
|
// =================================================================================
|
||||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. {TplCreatedAtDatetimeStr}
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. {{.TplCreatedAtDatetimeStr}}
|
||||||
// =================================================================================
|
// =================================================================================
|
||||||
|
|
||||||
package {TplPackageName}
|
package {{.TplPackageName}}
|
||||||
|
|
||||||
{TplPackageImports}
|
{{.TplPackageImports}}
|
||||||
|
|
||||||
// {TplTableNameCamelCase} is the golang structure of table {TplTableName} for DAO operations like Where/Data.
|
// {{.TplTableNameCamelCase}} is the golang structure of table {{.TplTableName}} for DAO operations like Where/Data.
|
||||||
{TplStructDefine}
|
{{.TplStructDefine}}
|
||||||
`
|
`
|
||||||
|
|||||||
@ -8,13 +8,13 @@ package consts
|
|||||||
|
|
||||||
const TemplateGenDaoEntityContent = `
|
const TemplateGenDaoEntityContent = `
|
||||||
// =================================================================================
|
// =================================================================================
|
||||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. {TplCreatedAtDatetimeStr}
|
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. {{.TplCreatedAtDatetimeStr}}
|
||||||
// =================================================================================
|
// =================================================================================
|
||||||
|
|
||||||
package {TplPackageName}
|
package {{.TplPackageName}}
|
||||||
|
|
||||||
{TplPackageImports}
|
{{.TplPackageImports}}
|
||||||
|
|
||||||
// {TplTableNameCamelCase} is the golang structure for table {TplTableName}.
|
// {{.TplTableNameCamelCase}} is the golang structure for table {{.TplTableName}}.
|
||||||
{TplStructDefine}
|
{{.TplStructDefine}}
|
||||||
`
|
`
|
||||||
|
|||||||
@ -162,8 +162,14 @@ func (s serviceInstall) getGoPathBin() string {
|
|||||||
func (s serviceInstall) getAvailablePaths() []serviceInstallAvailablePath {
|
func (s serviceInstall) getAvailablePaths() []serviceInstallAvailablePath {
|
||||||
var (
|
var (
|
||||||
folderPaths []serviceInstallAvailablePath
|
folderPaths []serviceInstallAvailablePath
|
||||||
binaryFileName = "gf" + gfile.Ext(gfile.SelfPath())
|
binaryFileName = "gf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Windows binary file name suffix.
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
binaryFileName += ".exe"
|
||||||
|
}
|
||||||
|
|
||||||
// $GOPATH/bin
|
// $GOPATH/bin
|
||||||
if goPathBin := s.getGoPathBin(); goPathBin != "" {
|
if goPathBin := s.getGoPathBin(); goPathBin != "" {
|
||||||
folderPaths = s.checkAndAppendToAvailablePath(
|
folderPaths = s.checkAndAppendToAvailablePath(
|
||||||
|
|||||||
@ -51,26 +51,26 @@ func SetHeaderPrint(enabled bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Print(v ...interface{}) {
|
func Print(v ...any) {
|
||||||
logger.Print(ctx, v...)
|
logger.Print(ctx, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Printf(format string, v ...interface{}) {
|
func Printf(format string, v ...any) {
|
||||||
logger.Printf(ctx, format, v...)
|
logger.Printf(ctx, format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fatal(v ...interface{}) {
|
func Fatal(v ...any) {
|
||||||
logger.Fatal(ctx, v...)
|
logger.Fatal(ctx, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fatalf(format string, v ...interface{}) {
|
func Fatalf(format string, v ...any) {
|
||||||
logger.Fatalf(ctx, format, v...)
|
logger.Fatalf(ctx, format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debug(v ...interface{}) {
|
func Debug(v ...any) {
|
||||||
logger.Debug(ctx, v...)
|
logger.Debug(ctx, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debugf(format string, v ...interface{}) {
|
func Debugf(format string, v ...any) {
|
||||||
logger.Debugf(ctx, format, v...)
|
logger.Debugf(ctx, format, v...)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,12 +12,13 @@ import (
|
|||||||
|
|
||||||
"golang.org/x/tools/imports"
|
"golang.org/x/tools/imports"
|
||||||
|
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
|
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/gogf/gf/v2/os/gproc"
|
"github.com/gogf/gf/v2/os/gproc"
|
||||||
"github.com/gogf/gf/v2/text/gregex"
|
"github.com/gogf/gf/v2/text/gregex"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
|
||||||
|
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoFmt formats the source file and adds or removes import statements as necessary.
|
// GoFmt formats the source file and adds or removes import statements as necessary.
|
||||||
|
|||||||
@ -7,13 +7,13 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/schollz/progressbar/v3"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
|
||||||
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
|
||||||
@ -34,26 +34,16 @@ func HTTPDownloadFileWithPercent(url string, localSaveFilePath string) error {
|
|||||||
}
|
}
|
||||||
defer headResp.Body.Close()
|
defer headResp.Body.Close()
|
||||||
|
|
||||||
size, err := strconv.Atoi(headResp.Header.Get("Content-Length"))
|
|
||||||
if err != nil {
|
|
||||||
return gerror.Wrap(err, "retrieve Content-Length failed")
|
|
||||||
}
|
|
||||||
doneCh := make(chan int64)
|
|
||||||
|
|
||||||
go doPrintDownloadPercent(doneCh, localSaveFilePath, int64(size))
|
|
||||||
|
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return gerror.Wrapf(err, `download "%s" to "%s" failed`, url, localSaveFilePath)
|
return gerror.Wrapf(err, `download "%s" to "%s" failed`, url, localSaveFilePath)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
wroteBytesCount, err := io.Copy(out, resp.Body)
|
bar := progressbar.NewOptions(int(resp.ContentLength), progressbar.OptionShowBytes(true), progressbar.OptionShowCount())
|
||||||
if err != nil {
|
writer := io.MultiWriter(out, bar)
|
||||||
return gerror.Wrapf(err, `download "%s" to "%s" failed`, url, localSaveFilePath)
|
_, err = io.Copy(writer, resp.Body)
|
||||||
}
|
|
||||||
|
|
||||||
doneCh <- wroteBytesCount
|
|
||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
if elapsed > time.Minute {
|
if elapsed > time.Minute {
|
||||||
mlog.Printf(`download completed in %.0fm`, float64(elapsed)/float64(time.Minute))
|
mlog.Printf(`download completed in %.0fm`, float64(elapsed)/float64(time.Minute))
|
||||||
@ -63,45 +53,3 @@ func HTTPDownloadFileWithPercent(url string, localSaveFilePath string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func doPrintDownloadPercent(doneCh chan int64, localSaveFilePath string, total int64) {
|
|
||||||
var (
|
|
||||||
stop = false
|
|
||||||
lastPercentFmt string
|
|
||||||
)
|
|
||||||
file, err := os.Open(localSaveFilePath)
|
|
||||||
if err != nil {
|
|
||||||
mlog.Fatal(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-doneCh:
|
|
||||||
stop = true
|
|
||||||
|
|
||||||
default:
|
|
||||||
fi, err := file.Stat()
|
|
||||||
if err != nil {
|
|
||||||
mlog.Fatal(err)
|
|
||||||
}
|
|
||||||
size := fi.Size()
|
|
||||||
if size == 0 {
|
|
||||||
size = 1
|
|
||||||
}
|
|
||||||
var (
|
|
||||||
percent = float64(size) / float64(total) * 100
|
|
||||||
percentFmt = fmt.Sprintf(`%.0f`, percent) + "%"
|
|
||||||
)
|
|
||||||
if lastPercentFmt != percentFmt {
|
|
||||||
lastPercentFmt = percentFmt
|
|
||||||
mlog.Print(percentFmt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if stop {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -7,6 +7,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "time/tzdata"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import (
|
|||||||
// when its initialization and cannot be changed then.
|
// when its initialization and cannot be changed then.
|
||||||
type Array struct {
|
type Array struct {
|
||||||
mu rwmutex.RWMutex
|
mu rwmutex.RWMutex
|
||||||
array []interface{}
|
array []any
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates and returns an empty array.
|
// New creates and returns an empty array.
|
||||||
@ -49,7 +49,7 @@ func NewArray(safe ...bool) *Array {
|
|||||||
func NewArraySize(size int, cap int, safe ...bool) *Array {
|
func NewArraySize(size int, cap int, safe ...bool) *Array {
|
||||||
return &Array{
|
return &Array{
|
||||||
mu: rwmutex.Create(safe...),
|
mu: rwmutex.Create(safe...),
|
||||||
array: make([]interface{}, size, cap),
|
array: make([]any, size, cap),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ func NewArrayRange(start, end, step int, safe ...bool) *Array {
|
|||||||
if step == 0 {
|
if step == 0 {
|
||||||
panic(fmt.Sprintf(`invalid step value: %d`, step))
|
panic(fmt.Sprintf(`invalid step value: %d`, step))
|
||||||
}
|
}
|
||||||
slice := make([]interface{}, 0)
|
slice := make([]any, 0)
|
||||||
index := 0
|
index := 0
|
||||||
for i := start; i <= end; i += step {
|
for i := start; i <= end; i += step {
|
||||||
slice = append(slice, i)
|
slice = append(slice, i)
|
||||||
@ -70,20 +70,20 @@ func NewArrayRange(start, end, step int, safe ...bool) *Array {
|
|||||||
|
|
||||||
// NewFrom is alias of NewArrayFrom.
|
// NewFrom is alias of NewArrayFrom.
|
||||||
// See NewArrayFrom.
|
// See NewArrayFrom.
|
||||||
func NewFrom(array []interface{}, safe ...bool) *Array {
|
func NewFrom(array []any, safe ...bool) *Array {
|
||||||
return NewArrayFrom(array, safe...)
|
return NewArrayFrom(array, safe...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFromCopy is alias of NewArrayFromCopy.
|
// NewFromCopy is alias of NewArrayFromCopy.
|
||||||
// See NewArrayFromCopy.
|
// See NewArrayFromCopy.
|
||||||
func NewFromCopy(array []interface{}, safe ...bool) *Array {
|
func NewFromCopy(array []any, safe ...bool) *Array {
|
||||||
return NewArrayFromCopy(array, safe...)
|
return NewArrayFromCopy(array, safe...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewArrayFrom creates and returns an array with given slice `array`.
|
// NewArrayFrom creates and returns an array with given slice `array`.
|
||||||
// The parameter `safe` is used to specify whether using array in concurrent-safety,
|
// The parameter `safe` is used to specify whether using array in concurrent-safety,
|
||||||
// which is false in default.
|
// which is false in default.
|
||||||
func NewArrayFrom(array []interface{}, safe ...bool) *Array {
|
func NewArrayFrom(array []any, safe ...bool) *Array {
|
||||||
return &Array{
|
return &Array{
|
||||||
mu: rwmutex.Create(safe...),
|
mu: rwmutex.Create(safe...),
|
||||||
array: array,
|
array: array,
|
||||||
@ -93,8 +93,8 @@ func NewArrayFrom(array []interface{}, safe ...bool) *Array {
|
|||||||
// NewArrayFromCopy creates and returns an array from a copy of given slice `array`.
|
// NewArrayFromCopy creates and returns an array from a copy of given slice `array`.
|
||||||
// The parameter `safe` is used to specify whether using array in concurrent-safety,
|
// The parameter `safe` is used to specify whether using array in concurrent-safety,
|
||||||
// which is false in default.
|
// which is false in default.
|
||||||
func NewArrayFromCopy(array []interface{}, safe ...bool) *Array {
|
func NewArrayFromCopy(array []any, safe ...bool) *Array {
|
||||||
newArray := make([]interface{}, len(array))
|
newArray := make([]any, len(array))
|
||||||
copy(newArray, array)
|
copy(newArray, array)
|
||||||
return &Array{
|
return &Array{
|
||||||
mu: rwmutex.Create(safe...),
|
mu: rwmutex.Create(safe...),
|
||||||
@ -104,14 +104,14 @@ func NewArrayFromCopy(array []interface{}, safe ...bool) *Array {
|
|||||||
|
|
||||||
// At returns the value by the specified index.
|
// At returns the value by the specified index.
|
||||||
// If the given `index` is out of range of the array, it returns `nil`.
|
// If the given `index` is out of range of the array, it returns `nil`.
|
||||||
func (a *Array) At(index int) (value interface{}) {
|
func (a *Array) At(index int) (value any) {
|
||||||
value, _ = a.Get(index)
|
value, _ = a.Get(index)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the value by the specified index.
|
// Get returns the value by the specified index.
|
||||||
// If the given `index` is out of range of the array, the `found` is false.
|
// If the given `index` is out of range of the array, the `found` is false.
|
||||||
func (a *Array) Get(index int) (value interface{}, found bool) {
|
func (a *Array) Get(index int) (value any, found bool) {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
if index < 0 || index >= len(a.array) {
|
if index < 0 || index >= len(a.array) {
|
||||||
@ -121,7 +121,7 @@ func (a *Array) Get(index int) (value interface{}, found bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set sets value to specified index.
|
// Set sets value to specified index.
|
||||||
func (a *Array) Set(index int, value interface{}) error {
|
func (a *Array) Set(index int, value any) error {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if index < 0 || index >= len(a.array) {
|
if index < 0 || index >= len(a.array) {
|
||||||
@ -132,7 +132,7 @@ func (a *Array) Set(index int, value interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetArray sets the underlying slice array with the given `array`.
|
// SetArray sets the underlying slice array with the given `array`.
|
||||||
func (a *Array) SetArray(array []interface{}) *Array {
|
func (a *Array) SetArray(array []any) *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
a.array = array
|
a.array = array
|
||||||
@ -140,7 +140,7 @@ func (a *Array) SetArray(array []interface{}) *Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Replace replaces the array items by given `array` from the beginning of array.
|
// Replace replaces the array items by given `array` from the beginning of array.
|
||||||
func (a *Array) Replace(array []interface{}) *Array {
|
func (a *Array) Replace(array []any) *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
max := len(array)
|
max := len(array)
|
||||||
@ -164,7 +164,7 @@ func (a *Array) Sum() (sum int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SortFunc sorts the array by custom function `less`.
|
// SortFunc sorts the array by custom function `less`.
|
||||||
func (a *Array) SortFunc(less func(v1, v2 interface{}) bool) *Array {
|
func (a *Array) SortFunc(less func(v1, v2 any) bool) *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
sort.Slice(a.array, func(i, j int) bool {
|
sort.Slice(a.array, func(i, j int) bool {
|
||||||
@ -174,26 +174,26 @@ func (a *Array) SortFunc(less func(v1, v2 interface{}) bool) *Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InsertBefore inserts the `values` to the front of `index`.
|
// InsertBefore inserts the `values` to the front of `index`.
|
||||||
func (a *Array) InsertBefore(index int, values ...interface{}) error {
|
func (a *Array) InsertBefore(index int, values ...any) error {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if index < 0 || index >= len(a.array) {
|
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([]interface{}{}, a.array[index:]...)
|
rear := append([]any{}, a.array[index:]...)
|
||||||
a.array = append(a.array[0:index], values...)
|
a.array = append(a.array[0:index], values...)
|
||||||
a.array = append(a.array, rear...)
|
a.array = append(a.array, rear...)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertAfter inserts the `values` to the back of `index`.
|
// InsertAfter inserts the `values` to the back of `index`.
|
||||||
func (a *Array) InsertAfter(index int, values ...interface{}) error {
|
func (a *Array) InsertAfter(index int, values ...any) error {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if index < 0 || index >= len(a.array) {
|
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([]interface{}{}, a.array[index+1:]...)
|
rear := append([]any{}, a.array[index+1:]...)
|
||||||
a.array = append(a.array[0:index+1], values...)
|
a.array = append(a.array[0:index+1], values...)
|
||||||
a.array = append(a.array, rear...)
|
a.array = append(a.array, rear...)
|
||||||
return nil
|
return nil
|
||||||
@ -201,14 +201,14 @@ func (a *Array) InsertAfter(index int, values ...interface{}) error {
|
|||||||
|
|
||||||
// Remove removes an item by index.
|
// Remove removes an item by index.
|
||||||
// If the given `index` is out of range of the array, the `found` is false.
|
// If the given `index` is out of range of the array, the `found` is false.
|
||||||
func (a *Array) Remove(index int) (value interface{}, found bool) {
|
func (a *Array) Remove(index int) (value any, found bool) {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
return a.doRemoveWithoutLock(index)
|
return a.doRemoveWithoutLock(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
// doRemoveWithoutLock removes an item by index without lock.
|
// doRemoveWithoutLock removes an item by index without lock.
|
||||||
func (a *Array) doRemoveWithoutLock(index int) (value interface{}, found bool) {
|
func (a *Array) doRemoveWithoutLock(index int) (value any, found bool) {
|
||||||
if index < 0 || index >= len(a.array) {
|
if index < 0 || index >= len(a.array) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -232,7 +232,7 @@ func (a *Array) doRemoveWithoutLock(index int) (value interface{}, found bool) {
|
|||||||
|
|
||||||
// RemoveValue removes an item by value.
|
// RemoveValue removes an item by value.
|
||||||
// It returns true if value is found in the array, or else false if not found.
|
// It returns true if value is found in the array, or else false if not found.
|
||||||
func (a *Array) RemoveValue(value interface{}) bool {
|
func (a *Array) RemoveValue(value any) bool {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if i := a.doSearchWithoutLock(value); i != -1 {
|
if i := a.doSearchWithoutLock(value); i != -1 {
|
||||||
@ -243,7 +243,7 @@ func (a *Array) RemoveValue(value interface{}) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveValues removes multiple items by `values`.
|
// RemoveValues removes multiple items by `values`.
|
||||||
func (a *Array) RemoveValues(values ...interface{}) {
|
func (a *Array) RemoveValues(values ...any) {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
@ -254,7 +254,7 @@ func (a *Array) RemoveValues(values ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PushLeft pushes one or multiple items to the beginning of array.
|
// PushLeft pushes one or multiple items to the beginning of array.
|
||||||
func (a *Array) PushLeft(value ...interface{}) *Array {
|
func (a *Array) PushLeft(value ...any) *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
a.array = append(value, a.array...)
|
a.array = append(value, a.array...)
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
@ -263,7 +263,7 @@ func (a *Array) PushLeft(value ...interface{}) *Array {
|
|||||||
|
|
||||||
// PushRight pushes one or multiple items to the end of array.
|
// PushRight pushes one or multiple items to the end of array.
|
||||||
// It equals to Append.
|
// It equals to Append.
|
||||||
func (a *Array) PushRight(value ...interface{}) *Array {
|
func (a *Array) PushRight(value ...any) *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
a.array = append(a.array, value...)
|
a.array = append(a.array, value...)
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
@ -272,14 +272,14 @@ func (a *Array) PushRight(value ...interface{}) *Array {
|
|||||||
|
|
||||||
// PopRand randomly pops and return an item out of array.
|
// PopRand randomly pops and return an item out of array.
|
||||||
// Note that if the array is empty, the `found` is false.
|
// Note that if the array is empty, the `found` is false.
|
||||||
func (a *Array) PopRand() (value interface{}, found bool) {
|
func (a *Array) PopRand() (value any, found bool) {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
return a.doRemoveWithoutLock(grand.Intn(len(a.array)))
|
return a.doRemoveWithoutLock(grand.Intn(len(a.array)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// PopRands randomly pops and returns `size` items out of array.
|
// PopRands randomly pops and returns `size` items out of array.
|
||||||
func (a *Array) PopRands(size int) []interface{} {
|
func (a *Array) PopRands(size int) []any {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if size <= 0 || len(a.array) == 0 {
|
if size <= 0 || len(a.array) == 0 {
|
||||||
@ -288,7 +288,7 @@ func (a *Array) PopRands(size int) []interface{} {
|
|||||||
if size >= len(a.array) {
|
if size >= len(a.array) {
|
||||||
size = len(a.array)
|
size = len(a.array)
|
||||||
}
|
}
|
||||||
array := make([]interface{}, size)
|
array := make([]any, size)
|
||||||
for i := 0; i < size; i++ {
|
for i := 0; i < size; i++ {
|
||||||
array[i], _ = a.doRemoveWithoutLock(grand.Intn(len(a.array)))
|
array[i], _ = a.doRemoveWithoutLock(grand.Intn(len(a.array)))
|
||||||
}
|
}
|
||||||
@ -297,7 +297,7 @@ func (a *Array) PopRands(size int) []interface{} {
|
|||||||
|
|
||||||
// PopLeft pops and returns an item from the beginning of array.
|
// PopLeft pops and returns an item from the beginning of array.
|
||||||
// Note that if the array is empty, the `found` is false.
|
// Note that if the array is empty, the `found` is false.
|
||||||
func (a *Array) PopLeft() (value interface{}, found bool) {
|
func (a *Array) PopLeft() (value any, found bool) {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if len(a.array) == 0 {
|
if len(a.array) == 0 {
|
||||||
@ -310,7 +310,7 @@ func (a *Array) PopLeft() (value interface{}, found bool) {
|
|||||||
|
|
||||||
// PopRight pops and returns an item from the end of array.
|
// PopRight pops and returns an item from the end of array.
|
||||||
// Note that if the array is empty, the `found` is false.
|
// Note that if the array is empty, the `found` is false.
|
||||||
func (a *Array) PopRight() (value interface{}, found bool) {
|
func (a *Array) PopRight() (value any, found bool) {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
index := len(a.array) - 1
|
index := len(a.array) - 1
|
||||||
@ -323,7 +323,7 @@ func (a *Array) PopRight() (value interface{}, found bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PopLefts pops and returns `size` items from the beginning of array.
|
// PopLefts pops and returns `size` items from the beginning of array.
|
||||||
func (a *Array) PopLefts(size int) []interface{} {
|
func (a *Array) PopLefts(size int) []any {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if size <= 0 || len(a.array) == 0 {
|
if size <= 0 || len(a.array) == 0 {
|
||||||
@ -340,7 +340,7 @@ func (a *Array) PopLefts(size int) []interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PopRights pops and returns `size` items from the end of array.
|
// PopRights pops and returns `size` items from the end of array.
|
||||||
func (a *Array) PopRights(size int) []interface{} {
|
func (a *Array) PopRights(size int) []any {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if size <= 0 || len(a.array) == 0 {
|
if size <= 0 || len(a.array) == 0 {
|
||||||
@ -364,7 +364,7 @@ func (a *Array) PopRights(size int) []interface{} {
|
|||||||
// If `end` is negative, then the offset will start from the end of array.
|
// If `end` is negative, then the offset will start from the end of array.
|
||||||
// If `end` is omitted, then the sequence will have everything from start up
|
// If `end` is omitted, then the sequence will have everything from start up
|
||||||
// until the end of the array.
|
// until the end of the array.
|
||||||
func (a *Array) Range(start int, end ...int) []interface{} {
|
func (a *Array) Range(start int, end ...int) []any {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
offsetEnd := len(a.array)
|
offsetEnd := len(a.array)
|
||||||
@ -377,9 +377,9 @@ func (a *Array) Range(start int, end ...int) []interface{} {
|
|||||||
if start < 0 {
|
if start < 0 {
|
||||||
start = 0
|
start = 0
|
||||||
}
|
}
|
||||||
array := ([]interface{})(nil)
|
array := ([]any)(nil)
|
||||||
if a.mu.IsSafe() {
|
if a.mu.IsSafe() {
|
||||||
array = make([]interface{}, offsetEnd-start)
|
array = make([]any, offsetEnd-start)
|
||||||
copy(array, a.array[start:offsetEnd])
|
copy(array, a.array[start:offsetEnd])
|
||||||
} else {
|
} else {
|
||||||
array = a.array[start:offsetEnd]
|
array = a.array[start:offsetEnd]
|
||||||
@ -400,7 +400,7 @@ func (a *Array) Range(start int, end ...int) []interface{} {
|
|||||||
// If it is omitted, then the sequence will have everything from offset up until the end of the array.
|
// If it is omitted, then the sequence will have everything from offset up until the end of the array.
|
||||||
//
|
//
|
||||||
// Any possibility crossing the left border of array, it will fail.
|
// Any possibility crossing the left border of array, it will fail.
|
||||||
func (a *Array) SubSlice(offset int, length ...int) []interface{} {
|
func (a *Array) SubSlice(offset int, length ...int) []any {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
size := len(a.array)
|
size := len(a.array)
|
||||||
@ -429,7 +429,7 @@ func (a *Array) SubSlice(offset int, length ...int) []interface{} {
|
|||||||
size = len(a.array) - offset
|
size = len(a.array) - offset
|
||||||
}
|
}
|
||||||
if a.mu.IsSafe() {
|
if a.mu.IsSafe() {
|
||||||
s := make([]interface{}, size)
|
s := make([]any, size)
|
||||||
copy(s, a.array[offset:])
|
copy(s, a.array[offset:])
|
||||||
return s
|
return s
|
||||||
} else {
|
} else {
|
||||||
@ -438,7 +438,7 @@ func (a *Array) SubSlice(offset int, length ...int) []interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Append is alias of PushRight, please See PushRight.
|
// Append is alias of PushRight, please See PushRight.
|
||||||
func (a *Array) Append(value ...interface{}) *Array {
|
func (a *Array) Append(value ...any) *Array {
|
||||||
a.PushRight(value...)
|
a.PushRight(value...)
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
@ -454,11 +454,11 @@ func (a *Array) Len() int {
|
|||||||
// Slice returns the underlying data of array.
|
// Slice returns the underlying data of array.
|
||||||
// Note that, if it's in concurrent-safe usage, it returns a copy of underlying data,
|
// Note that, if it's in concurrent-safe usage, it returns a copy of underlying data,
|
||||||
// or else a pointer to the underlying data.
|
// or else a pointer to the underlying data.
|
||||||
func (a *Array) Slice() []interface{} {
|
func (a *Array) Slice() []any {
|
||||||
if a.mu.IsSafe() {
|
if a.mu.IsSafe() {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
array := make([]interface{}, len(a.array))
|
array := make([]any, len(a.array))
|
||||||
copy(array, a.array)
|
copy(array, a.array)
|
||||||
return array
|
return array
|
||||||
} else {
|
} else {
|
||||||
@ -466,15 +466,15 @@ func (a *Array) Slice() []interface{} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interfaces returns current array as []interface{}.
|
// Interfaces returns current array as []any.
|
||||||
func (a *Array) Interfaces() []interface{} {
|
func (a *Array) Interfaces() []any {
|
||||||
return a.Slice()
|
return a.Slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clone returns a new array, which is a copy of current array.
|
// Clone returns a new array, which is a copy of current array.
|
||||||
func (a *Array) Clone() (newArray *Array) {
|
func (a *Array) Clone() (newArray *Array) {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
array := make([]interface{}, len(a.array))
|
array := make([]any, len(a.array))
|
||||||
copy(array, a.array)
|
copy(array, a.array)
|
||||||
a.mu.RUnlock()
|
a.mu.RUnlock()
|
||||||
return NewArrayFrom(array, a.mu.IsSafe())
|
return NewArrayFrom(array, a.mu.IsSafe())
|
||||||
@ -484,26 +484,26 @@ func (a *Array) Clone() (newArray *Array) {
|
|||||||
func (a *Array) Clear() *Array {
|
func (a *Array) Clear() *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
if len(a.array) > 0 {
|
if len(a.array) > 0 {
|
||||||
a.array = make([]interface{}, 0)
|
a.array = make([]any, 0)
|
||||||
}
|
}
|
||||||
a.mu.Unlock()
|
a.mu.Unlock()
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contains checks whether a value exists in the array.
|
// Contains checks whether a value exists in the array.
|
||||||
func (a *Array) Contains(value interface{}) bool {
|
func (a *Array) Contains(value any) bool {
|
||||||
return a.Search(value) != -1
|
return a.Search(value) != -1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search searches array by `value`, returns the index of `value`,
|
// Search searches array by `value`, returns the index of `value`,
|
||||||
// or returns -1 if not exists.
|
// or returns -1 if not exists.
|
||||||
func (a *Array) Search(value interface{}) int {
|
func (a *Array) Search(value any) int {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
return a.doSearchWithoutLock(value)
|
return a.doSearchWithoutLock(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Array) doSearchWithoutLock(value interface{}) int {
|
func (a *Array) doSearchWithoutLock(value any) int {
|
||||||
if len(a.array) == 0 {
|
if len(a.array) == 0 {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
@ -527,9 +527,9 @@ func (a *Array) Unique() *Array {
|
|||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
ok bool
|
ok bool
|
||||||
temp interface{}
|
temp any
|
||||||
uniqueSet = make(map[interface{}]struct{})
|
uniqueSet = make(map[any]struct{})
|
||||||
uniqueArray = make([]interface{}, 0, len(a.array))
|
uniqueArray = make([]any, 0, len(a.array))
|
||||||
)
|
)
|
||||||
for i := 0; i < len(a.array); i++ {
|
for i := 0; i < len(a.array); i++ {
|
||||||
temp = a.array[i]
|
temp = a.array[i]
|
||||||
@ -544,7 +544,7 @@ func (a *Array) Unique() *Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LockFunc locks writing by callback function `f`.
|
// LockFunc locks writing by callback function `f`.
|
||||||
func (a *Array) LockFunc(f func(array []interface{})) *Array {
|
func (a *Array) LockFunc(f func(array []any)) *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
f(a.array)
|
f(a.array)
|
||||||
@ -552,7 +552,7 @@ func (a *Array) LockFunc(f func(array []interface{})) *Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RLockFunc locks reading by callback function `f`.
|
// RLockFunc locks reading by callback function `f`.
|
||||||
func (a *Array) RLockFunc(f func(array []interface{})) *Array {
|
func (a *Array) RLockFunc(f func(array []any)) *Array {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
f(a.array)
|
f(a.array)
|
||||||
@ -563,13 +563,13 @@ func (a *Array) RLockFunc(f func(array []interface{})) *Array {
|
|||||||
// The parameter `array` can be any garray or slice type.
|
// The parameter `array` can be any garray or slice type.
|
||||||
// The difference between Merge and Append is Append supports only specified slice type,
|
// The difference between Merge and Append is Append supports only specified slice type,
|
||||||
// but Merge supports more parameter types.
|
// but Merge supports more parameter types.
|
||||||
func (a *Array) Merge(array interface{}) *Array {
|
func (a *Array) Merge(array any) *Array {
|
||||||
return a.Append(gconv.Interfaces(array)...)
|
return a.Append(gconv.Interfaces(array)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill fills an array with num entries of the value `value`,
|
// Fill fills an array with num entries of the value `value`,
|
||||||
// keys starting at the `startIndex` parameter.
|
// keys starting at the `startIndex` parameter.
|
||||||
func (a *Array) Fill(startIndex int, num int, value interface{}) error {
|
func (a *Array) Fill(startIndex int, num int, value any) error {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if startIndex < 0 || startIndex > len(a.array) {
|
if startIndex < 0 || startIndex > len(a.array) {
|
||||||
@ -588,7 +588,7 @@ func (a *Array) Fill(startIndex int, num int, value interface{}) error {
|
|||||||
// Chunk splits an array into multiple arrays,
|
// Chunk splits an array into multiple arrays,
|
||||||
// the size of each array is determined by `size`.
|
// the size of each array is determined by `size`.
|
||||||
// The last chunk may contain less than size elements.
|
// The last chunk may contain less than size elements.
|
||||||
func (a *Array) Chunk(size int) [][]interface{} {
|
func (a *Array) Chunk(size int) [][]any {
|
||||||
if size < 1 {
|
if size < 1 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -596,7 +596,7 @@ func (a *Array) Chunk(size int) [][]interface{} {
|
|||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
length := len(a.array)
|
length := len(a.array)
|
||||||
chunks := int(math.Ceil(float64(length) / float64(size)))
|
chunks := int(math.Ceil(float64(length) / float64(size)))
|
||||||
var n [][]interface{}
|
var n [][]any
|
||||||
for i, end := 0, 0; chunks > 0; chunks-- {
|
for i, end := 0, 0; chunks > 0; chunks-- {
|
||||||
end = (i + 1) * size
|
end = (i + 1) * size
|
||||||
if end > length {
|
if end > length {
|
||||||
@ -612,7 +612,7 @@ func (a *Array) Chunk(size int) [][]interface{} {
|
|||||||
// If size is positive then the array is padded on the right, or negative on the left.
|
// If size is positive then the array is padded on the right, or negative on the left.
|
||||||
// If the absolute value of `size` is less than or equal to the length of the array
|
// If the absolute value of `size` is less than or equal to the length of the array
|
||||||
// then no padding takes place.
|
// then no padding takes place.
|
||||||
func (a *Array) Pad(size int, val interface{}) *Array {
|
func (a *Array) Pad(size int, val any) *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
if size == 0 || (size > 0 && size < len(a.array)) || (size < 0 && size > -len(a.array)) {
|
if size == 0 || (size > 0 && size < len(a.array)) || (size < 0 && size > -len(a.array)) {
|
||||||
@ -623,7 +623,7 @@ func (a *Array) Pad(size int, val interface{}) *Array {
|
|||||||
n = -size
|
n = -size
|
||||||
}
|
}
|
||||||
n -= len(a.array)
|
n -= len(a.array)
|
||||||
tmp := make([]interface{}, n)
|
tmp := make([]any, n)
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
tmp[i] = val
|
tmp[i] = val
|
||||||
}
|
}
|
||||||
@ -636,7 +636,7 @@ func (a *Array) Pad(size int, val interface{}) *Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rand randomly returns one item from array(no deleting).
|
// Rand randomly returns one item from array(no deleting).
|
||||||
func (a *Array) Rand() (value interface{}, found bool) {
|
func (a *Array) Rand() (value any, found bool) {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
if len(a.array) == 0 {
|
if len(a.array) == 0 {
|
||||||
@ -646,13 +646,13 @@ func (a *Array) Rand() (value interface{}, found bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rands randomly returns `size` items from array(no deleting).
|
// Rands randomly returns `size` items from array(no deleting).
|
||||||
func (a *Array) Rands(size int) []interface{} {
|
func (a *Array) Rands(size int) []any {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
if size <= 0 || len(a.array) == 0 {
|
if size <= 0 || len(a.array) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
array := make([]interface{}, size)
|
array := make([]any, size)
|
||||||
for i := 0; i < size; i++ {
|
for i := 0; i < size; i++ {
|
||||||
array[i] = a.array[grand.Intn(len(a.array))]
|
array[i] = a.array[grand.Intn(len(a.array))]
|
||||||
}
|
}
|
||||||
@ -697,8 +697,8 @@ func (a *Array) Join(glue string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CountValues counts the number of occurrences of all values in the array.
|
// CountValues counts the number of occurrences of all values in the array.
|
||||||
func (a *Array) CountValues() map[interface{}]int {
|
func (a *Array) CountValues() map[any]int {
|
||||||
m := make(map[interface{}]int)
|
m := make(map[any]int)
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
for _, v := range a.array {
|
for _, v := range a.array {
|
||||||
@ -708,13 +708,13 @@ func (a *Array) CountValues() map[interface{}]int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterator is alias of IteratorAsc.
|
// Iterator is alias of IteratorAsc.
|
||||||
func (a *Array) Iterator(f func(k int, v interface{}) bool) {
|
func (a *Array) Iterator(f func(k int, v any) bool) {
|
||||||
a.IteratorAsc(f)
|
a.IteratorAsc(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IteratorAsc iterates the array readonly in ascending order with given callback function `f`.
|
// IteratorAsc iterates the array readonly in ascending order with given callback function `f`.
|
||||||
// If `f` returns true, then it continues iterating; or false to stop.
|
// If `f` returns true, then it continues iterating; or false to stop.
|
||||||
func (a *Array) IteratorAsc(f func(k int, v interface{}) bool) {
|
func (a *Array) IteratorAsc(f func(k int, v any) bool) {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
for k, v := range a.array {
|
for k, v := range a.array {
|
||||||
@ -726,7 +726,7 @@ func (a *Array) IteratorAsc(f func(k int, v interface{}) bool) {
|
|||||||
|
|
||||||
// IteratorDesc iterates the array readonly in descending order with given callback function `f`.
|
// IteratorDesc iterates the array readonly in descending order with given callback function `f`.
|
||||||
// If `f` returns true, then it continues iterating; or false to stop.
|
// If `f` returns true, then it continues iterating; or false to stop.
|
||||||
func (a *Array) IteratorDesc(f func(k int, v interface{}) bool) {
|
func (a *Array) IteratorDesc(f func(k int, v any) bool) {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
for i := len(a.array) - 1; i >= 0; i-- {
|
for i := len(a.array) - 1; i >= 0; i-- {
|
||||||
@ -772,7 +772,7 @@ func (a Array) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
// UnmarshalJSON implements the interface UnmarshalJSON for json.Unmarshal.
|
||||||
func (a *Array) UnmarshalJSON(b []byte) error {
|
func (a *Array) UnmarshalJSON(b []byte) error {
|
||||||
if a.array == nil {
|
if a.array == nil {
|
||||||
a.array = make([]interface{}, 0)
|
a.array = make([]any, 0)
|
||||||
}
|
}
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
@ -783,7 +783,7 @@ func (a *Array) UnmarshalJSON(b []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalValue is an interface implement which sets any type of value for array.
|
// UnmarshalValue is an interface implement which sets any type of value for array.
|
||||||
func (a *Array) UnmarshalValue(value interface{}) error {
|
func (a *Array) UnmarshalValue(value any) error {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@ -798,7 +798,7 @@ func (a *Array) UnmarshalValue(value interface{}) error {
|
|||||||
// Filter iterates array and filters elements using custom callback function.
|
// Filter iterates array and filters elements using custom callback function.
|
||||||
// It removes the element from array if callback function `filter` returns true,
|
// It removes the element from array if callback function `filter` returns true,
|
||||||
// it or else does nothing and continues iterating.
|
// it or else does nothing and continues iterating.
|
||||||
func (a *Array) Filter(filter func(index int, value interface{}) bool) *Array {
|
func (a *Array) Filter(filter func(index int, value any) bool) *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
for i := 0; i < len(a.array); {
|
for i := 0; i < len(a.array); {
|
||||||
@ -841,7 +841,7 @@ func (a *Array) FilterEmpty() *Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Walk applies a user supplied function `f` to every item of array.
|
// Walk applies a user supplied function `f` to every item of array.
|
||||||
func (a *Array) Walk(f func(value interface{}) interface{}) *Array {
|
func (a *Array) Walk(f func(value any) any) *Array {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
for i, v := range a.array {
|
for i, v := range a.array {
|
||||||
@ -856,13 +856,13 @@ func (a *Array) IsEmpty() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy implements interface for deep copy of current type.
|
// DeepCopy implements interface for deep copy of current type.
|
||||||
func (a *Array) DeepCopy() interface{} {
|
func (a *Array) DeepCopy() any {
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
newSlice := make([]interface{}, len(a.array))
|
newSlice := make([]any, len(a.array))
|
||||||
for i, v := range a.array {
|
for i, v := range a.array {
|
||||||
newSlice[i] = deepcopy.Copy(v)
|
newSlice[i] = deepcopy.Copy(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -478,11 +478,11 @@ func (a *IntArray) Slice() []int {
|
|||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interfaces returns current array as []interface{}.
|
// Interfaces returns current array as []any.
|
||||||
func (a *IntArray) Interfaces() []interface{} {
|
func (a *IntArray) Interfaces() []any {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
array := make([]interface{}, len(a.array))
|
array := make([]any, len(a.array))
|
||||||
for k, v := range a.array {
|
for k, v := range a.array {
|
||||||
array[k] = v
|
array[k] = v
|
||||||
}
|
}
|
||||||
@ -581,7 +581,7 @@ func (a *IntArray) RLockFunc(f func(array []int)) *IntArray {
|
|||||||
// The parameter `array` can be any garray or slice type.
|
// The parameter `array` can be any garray or slice type.
|
||||||
// The difference between Merge and Append is Append supports only specified slice type,
|
// The difference between Merge and Append is Append supports only specified slice type,
|
||||||
// but Merge supports more parameter types.
|
// but Merge supports more parameter types.
|
||||||
func (a *IntArray) Merge(array interface{}) *IntArray {
|
func (a *IntArray) Merge(array any) *IntArray {
|
||||||
return a.Append(gconv.Ints(array)...)
|
return a.Append(gconv.Ints(array)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -788,7 +788,7 @@ func (a *IntArray) UnmarshalJSON(b []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalValue is an interface implement which sets any type of value for array.
|
// UnmarshalValue is an interface implement which sets any type of value for array.
|
||||||
func (a *IntArray) UnmarshalValue(value interface{}) error {
|
func (a *IntArray) UnmarshalValue(value any) error {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@ -846,7 +846,7 @@ func (a *IntArray) IsEmpty() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy implements interface for deep copy of current type.
|
// DeepCopy implements interface for deep copy of current type.
|
||||||
func (a *IntArray) DeepCopy() interface{} {
|
func (a *IntArray) DeepCopy() any {
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -454,11 +454,11 @@ func (a *StrArray) Slice() []string {
|
|||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interfaces returns current array as []interface{}.
|
// Interfaces returns current array as []any.
|
||||||
func (a *StrArray) Interfaces() []interface{} {
|
func (a *StrArray) Interfaces() []any {
|
||||||
a.mu.RLock()
|
a.mu.RLock()
|
||||||
defer a.mu.RUnlock()
|
defer a.mu.RUnlock()
|
||||||
array := make([]interface{}, len(a.array))
|
array := make([]any, len(a.array))
|
||||||
for k, v := range a.array {
|
for k, v := range a.array {
|
||||||
array[k] = v
|
array[k] = v
|
||||||
}
|
}
|
||||||
@ -573,7 +573,7 @@ func (a *StrArray) RLockFunc(f func(array []string)) *StrArray {
|
|||||||
// The parameter `array` can be any garray or slice type.
|
// The parameter `array` can be any garray or slice type.
|
||||||
// The difference between Merge and Append is Append supports only specified slice type,
|
// The difference between Merge and Append is Append supports only specified slice type,
|
||||||
// but Merge supports more parameter types.
|
// but Merge supports more parameter types.
|
||||||
func (a *StrArray) Merge(array interface{}) *StrArray {
|
func (a *StrArray) Merge(array any) *StrArray {
|
||||||
return a.Append(gconv.Strings(array)...)
|
return a.Append(gconv.Strings(array)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -787,7 +787,7 @@ func (a *StrArray) UnmarshalJSON(b []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalValue is an interface implement which sets any type of value for array.
|
// UnmarshalValue is an interface implement which sets any type of value for array.
|
||||||
func (a *StrArray) UnmarshalValue(value interface{}) error {
|
func (a *StrArray) UnmarshalValue(value any) error {
|
||||||
a.mu.Lock()
|
a.mu.Lock()
|
||||||
defer a.mu.Unlock()
|
defer a.mu.Unlock()
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
@ -845,7 +845,7 @@ func (a *StrArray) IsEmpty() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy implements interface for deep copy of current type.
|
// DeepCopy implements interface for deep copy of current type.
|
||||||
func (a *StrArray) DeepCopy() interface{} {
|
func (a *StrArray) DeepCopy() any {
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user