Compare commits

...

12 Commits

Author SHA1 Message Date
60d8283971 fix router parameters handling by auto url decoding (#2262)
improve router parameters handling by auto url decoding
2022-11-04 15:03:27 +08:00
ad90bc2809 version.go updates (#2259) 2022-11-04 11:33:31 +08:00
a1b9eca7b6 fix issue #2244 (#2257)
* fix issue #2244

* ut update for package gtime

* golangci updates
2022-11-03 21:17:28 +08:00
c4a5b8ca94 fix issue 1915 and repeated link instance key for package gdb (#2250)
* fix issue #1915

* fix issue in repeated link instance key

* add configuration item Namespace for package gdb

* up

* up

* fix: pgsql list table names (#2255)

Co-authored-by: Gin <qinyuguang@gmail.com>
2022-11-03 20:22:36 +08:00
ab79134309 add schema name in debug logging content; add master-slave ut case for package gdb (#2249)
* add schema name in debug logging content; add master-slave ut case for package gdb

* add schema name in debug logging content; add master-slave ut case for package gdb
2022-11-02 21:55:58 +08:00
63c3e8396b attach and export real handler for request (#2220)
* attach and export real handler for request

* add note

* rename HandlerParsedItem to HandlerItemParsed

Co-authored-by: John Guo <john@johng.cn>
2022-11-01 20:17:59 +08:00
1793bf0863 add golangci feature to guarantee codes quality (#2229) 2022-11-01 20:12:21 +08:00
Gin
8e0e87877a feat: add gcfg.Adapter implements using nacos service (#2232)
* feat: add `gcfg.Adapter` implements using nacos service

* Update gf.yml

* Update gf.yml

Co-authored-by: John Guo <john@johng.cn>
2022-10-26 18:45:35 +08:00
425b31c6fd improve nil receiver handling for package gtime (#2226)
* improve nil receiver handling for package gtime

* CI updates

* CI updates
2022-10-26 18:37:40 +08:00
4da469325d fix gen dao oracle entity bug (#2219)
Co-authored-by: John Guo <john@johng.cn>
2022-10-26 18:37:06 +08:00
33fdde6afd opt: parameter verification of optimized handler methods (#2224) 2022-10-20 19:36:01 +08:00
ee6103418b auto creating error with code in ghttp.MiddlewareHandlerResponse when there's no 200 http status code (#2223) 2022-10-20 15:50:17 +08:00
286 changed files with 2238 additions and 823 deletions

View File

@ -141,6 +141,15 @@ jobs:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Start Apollo Containers
run: docker-compose -f ".github/workflows/apollo/docker-compose.yml" up -d --build
- name: Start Nacos Containers
run: docker-compose -f ".github/workflows/nacos/docker-compose.yml" up -d --build
- name: Start Redis Cluster Containers
run: docker-compose -f ".github/workflows/redis/docker-compose.yml" up -d --build
- name: Start Minikube - name: Start Minikube
uses: medyagh/setup-minikube@master uses: medyagh/setup-minikube@master
@ -161,24 +170,21 @@ jobs:
restore-keys: | restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}- ${{ runner.os }}-go-${{ matrix.go-version }}-
- name: Start redis cluster containers
run: docker-compose -f ".github/workflows/redis/docker-compose.yml" up -d --build
- name: Start apollo containers
run: docker-compose -f ".github/workflows/apollo/docker-compose.yml" up -d --build
- name: Before Script - name: Before Script
run: bash .github/workflows/before_script.sh run: bash .github/workflows/before_script.sh
- name: Build & Test - name: Build & Test
run: bash .github/workflows/build_and_test.sh run: bash .github/workflows/build_and_test.sh
- 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
- name: Stop apollo containers - name: Stop Apollo Containers
run: docker-compose -f ".github/workflows/apollo/docker-compose.yml" down run: docker-compose -f ".github/workflows/apollo/docker-compose.yml" down
- name: Stop Nacos Containers
run: docker-compose -f ".github/workflows/nacos/docker-compose.yml" down
- name: Report Coverage - name: Report Coverage
uses: codecov/codecov-action@v2 uses: codecov/codecov-action@v2
with: with:

50
.github/workflows/golangci-lint.yml vendored Normal file
View File

@ -0,0 +1,50 @@
# Tencent is pleased to support the open source community by making Polaris available.
#
# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
name: GolangCI-Lint
on:
push:
branches:
- master
- develop
- personal/**
- feature/**
- enhance/**
- fix/**
pull_request:
branches:
- master
- develop
- personal/**
- feature/**
- enhance/**
- fix/**
jobs:
golangci:
strategy:
matrix:
go-version: [1.15.x,1.16.x,1.17.x,1.18.x]
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.3.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
args: --timeout 3m0s

View File

@ -0,0 +1,40 @@
version: "3.8"
services:
nacos:
image: loads/nacos-server:v2.1.2
container_name: nacos
env_file:
- ./env/nacos.env
ports:
- "8848:8848"
- "9848:9848"
- "9555:9555"
healthcheck:
test: [ "CMD", "curl" ,"http://localhost:8848/nacos" ]
interval: 5s
timeout: 3s
retries: 10
depends_on:
mysql:
condition: service_healthy
mysql:
build:
context: .
dockerfile: ./image/mysql/Dockerfile
container_name: mysql
env_file:
- ./env/mysql.env
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
interval: 5s
timeout: 3s
retries: 10
initializer:
image: loads/curl:latest
depends_on:
nacos:
condition: service_healthy
command: [ "sh", "-c", "curl -X POST 'http://nacos:8848/nacos/v1/cs/configs?dataId=config.toml&group=test&content=%5Bserver%5D%0A%09address%3D%22%3A8000%22'" ]

4
.github/workflows/nacos/env/mysql.env vendored Normal file
View File

@ -0,0 +1,4 @@
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=nacos_devtest
MYSQL_USER=nacos
MYSQL_PASSWORD=nacos

9
.github/workflows/nacos/env/nacos.env vendored Normal file
View File

@ -0,0 +1,9 @@
PREFER_HOST_MODE=hostname
MODE=standalone
SPRING_DATASOURCE_PLATFORM=mysql
MYSQL_SERVICE_HOST=mysql
MYSQL_SERVICE_DB_NAME=nacos_devtest
MYSQL_SERVICE_PORT=3306
MYSQL_SERVICE_USER=nacos
MYSQL_SERVICE_PASSWORD=nacos
MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true

View File

@ -0,0 +1,5 @@
FROM loads/mysql:5.7
ADD https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql /docker-entrypoint-initdb.d/nacos-mysql.sql
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/nacos-mysql.sql
EXPOSE 3306
CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]

View File

@ -2,31 +2,56 @@
## with their default values. ## with their default values.
# See https://github.com/golangci/golangci-lint#config-file # See https://github.com/golangci/golangci-lint#config-file
run: # See https://golangci-lint.run/usage/configuration/
issues-exit-code: 1 #Default
tests: true #Default
# Options for analysis running.
run:
# Exit code when at least one issue was found.
# Default: 1
issues-exit-code: 2
# Include test files or not.
# Default: true
tests: false
# Which dirs to skip: issues from them won't be reported.
# Can use regexp here: `generated.*`, regexp is applied on full path.
# Default value is empty list,
# but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work on Windows.
skip-dirs: []
# Which files to skip: they will be analyzed, but issues from them won't be reported.
# Default value is empty list,
# but there is no need to include all autogenerated files,
# we confidently recognize autogenerated files.
# If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work on Windows.
skip-files: []
# Main linters configurations.
# See https://golangci-lint.run/usage/linters
linters: linters:
# Disable everything by default so upgrades to not include new "default # Disable all default enabled linters.
# enabled" linters.
disable-all: true disable-all: true
# Specifically enable linters we want to use. # Custom enable linters we want to use.
enable: enable:
- deadcode - 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.
- gofmt - funlen # Tool for detection of long functions
- goimports - goconst # Finds repeated strings that could be replaced by a constant
- gosimple - gocritic # Provides diagnostics that check for bugs, performance and style issues.
- govet - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- godot - gosimple # Linter for Go source code that specializes in simplifying code
- ineffassign - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- misspell - misspell # Finds commonly misspelled English words in comments
- revive - nolintlint # Reports ill-formed or insufficient nolint directives
- staticcheck - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
- structcheck - staticcheck # It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary.
- typecheck - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- unused - usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library.
- varcheck - whitespace # Tool for detection of leading and trailing whitespace
issues: issues:
@ -41,26 +66,218 @@ issues:
text: "exported func.*returns unexported type.*which can be annoying to use" text: "exported func.*returns unexported type.*which can be annoying to use"
linters: linters:
- revive - revive
# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
text: "unnecessaryDefer:"
# https://golangci-lint.run/usage/linters
linters-settings: linters-settings:
# https://golangci-lint.run/usage/linters/#misspell
misspell: misspell:
locale: US locale: US
ignore-words: ignore-words:
- cancelled - cancelled
goimports:
local-prefixes: github.com/gogf/gf # https://golangci-lint.run/usage/linters/#revive
godot: # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
# Comments to be checked: `declarations`, `toplevel`, or `all`. revive:
# Default: declarations ignore-generated-header: true
scope: toplevel severity: error
exclude: rules:
# Exclude sentence fragments for lists. - name: atomic
- '^[ ]*[-•]' - name: line-length-limit
# Exclude sentences prefixing a list. severity: error
- ':$' arguments: [ 380 ]
# Check that each sentence ends with a period. - name: unhandled-error
# Default: true severity: warning
period: false disabled: true
# Check that each sentence starts with a capital letter. arguments: []
- name: var-naming
severity: warning
disabled: true
arguments:
# AllowList
- [ "ID","URL","IP","HTTP","JSON","API","UID","Id","Api","Uid","Http","Json","Ip","Url" ]
# DenyList
- [ "VM" ]
- name: string-format
severity: warning
disabled: false
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
- name: function-result-limit
severity: warning
disabled: false
arguments: [ 4 ]
# https://golangci-lint.run/usage/linters/#funlen
funlen:
# Checks the number of lines in a function.
# If lower than 0, disable the check.
# Default: 60
lines: 330
# Checks the number of statements in a function.
# If lower than 0, disable the check.
# Default: 40
statements: -1
# https://golangci-lint.run/usage/linters/#goconst
goconst:
# Minimal length of string constant.
# Default: 3
min-len: 2
# Minimum occurrences of constant string count to trigger issue.
# Default: 3
# For subsequent optimization, the value is reduced.
min-occurrences: 30
# Ignore test files.
# Default: false # Default: false
capital: false ignore-tests: true
# Look for existing constants matching the values.
# Default: true
match-constant: false
# 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:
# Select the Go version to target.
# Default: 1.13
# Deprecated: use the global `run.go` instead.
go: "1.15"
# 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:
# Select the Go version to target.
# Default: "1.13"
# Deprecated: use the global `run.go` instead.
go: "1.15"
# SAxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
# Default: ["*"]
checks: [ "all","-SA1019","-SA4015","-SA1029","-SA1016","-SA9003","-SA4006","-SA6003" ]
# https://golangci-lint.run/usage/linters/#gofmt
gofmt:
# Simplify code: gofmt with `-s` option.
# Default: true
simplify: true
# Apply the rewrite rules to the source before reformatting.
# https://pkg.go.dev/cmd/gofmt
# Default: []
rewrite-rules:
# - pattern: 'interface{}'
# replacement: 'any'
# - pattern: 'a[b:len(a)]'
# replacement: 'a[b:]'

View File

@ -11,3 +11,6 @@ tidy:
cd -; \ cd -; \
done done
.PHONY: lint
lint:
golangci-lint run

View File

@ -4,11 +4,12 @@ import (
"context" "context"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/service"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd" "github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/util/gtag" "github.com/gogf/gf/v2/util/gtag"
"github.com/gogf/gf/cmd/gf/v2/internal/service"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
var ( var (
@ -38,6 +39,7 @@ type cGFInput struct {
Version bool `short:"v" name:"version" brief:"show version information of current binary" orphan:"true"` Version bool `short:"v" name:"version" brief:"show version information of current binary" orphan:"true"`
Debug bool `short:"d" name:"debug" brief:"show internal detailed debugging information" orphan:"true"` Debug bool `short:"d" name:"debug" brief:"show internal detailed debugging information" orphan:"true"`
} }
type cGFOutput struct{} type cGFOutput struct{}
func (c cGF) Index(ctx context.Context, in cGFInput) (out *cGFOutput, err error) { func (c cGF) Index(ctx context.Context, in cGFInput) (out *cGFOutput, err error) {

View File

@ -9,7 +9,6 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/encoding/gbase64" "github.com/gogf/gf/v2/encoding/gbase64"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd" "github.com/gogf/gf/v2/os/gcmd"
@ -20,6 +19,8 @@ import (
"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/v2/util/gtag" "github.com/gogf/gf/v2/util/gtag"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
var ( var (
@ -124,6 +125,7 @@ type cBuildInput struct {
PackDst string `short:"pd" name:"packDst" brief:"temporary go file path for pack, this go file will be automatically removed after built" d:"internal/packed/build_pack_data.go"` PackDst string `short:"pd" name:"packDst" brief:"temporary go file path for pack, this go file will be automatically removed after built" d:"internal/packed/build_pack_data.go"`
ExitWhenError bool `short:"ew" name:"exitWhenError" brief:"exit building when any error occurs, default is false" orphan:"true"` ExitWhenError bool `short:"ew" name:"exitWhenError" brief:"exit building when any error occurs, default is false" orphan:"true"`
} }
type cBuildOutput struct{} type cBuildOutput struct{}
func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, err error) { func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, err error) {

View File

@ -5,12 +5,13 @@ import (
"fmt" "fmt"
"runtime" "runtime"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"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/text/gstr" "github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gtag" "github.com/gogf/gf/v2/util/gtag"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
var ( var (
@ -77,6 +78,7 @@ type cDockerInput struct {
Push bool `name:"push" short:"p" brief:"{cDockerPushBrief}" orphan:"true"` Push bool `name:"push" short:"p" brief:"{cDockerPushBrief}" orphan:"true"`
Extra string `name:"extra" short:"e" brief:"{cDockerExtraBrief}"` Extra string `name:"extra" short:"e" brief:"{cDockerExtraBrief}"`
} }
type cDockerOutput struct{} type cDockerOutput struct{}
func (c cDocker) Index(ctx context.Context, in cDockerInput) (out *cDockerOutput, err error) { func (c cDocker) Index(ctx context.Context, in cDockerInput) (out *cDockerOutput, err error) {

View File

@ -4,12 +4,13 @@ import (
"bytes" "bytes"
"context" "context"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"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"
"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/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
var ( var (
@ -23,6 +24,7 @@ type cEnv struct {
type cEnvInput struct { type cEnvInput struct {
g.Meta `name:"env"` g.Meta `name:"env"`
} }
type cEnvOutput struct{} type cEnvOutput struct{}
func (c cEnv) Index(ctx context.Context, in cEnvInput) (out *cEnvOutput, err error) { func (c cEnv) Index(ctx context.Context, in cEnvInput) (out *cEnvOutput, err error) {

View File

@ -5,7 +5,6 @@ import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2" _ "github.com/gogf/gf/contrib/drivers/mysql/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"
//_ "github.com/gogf/gf/contrib/drivers/oracle/v2"
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao" "github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao"
) )

View File

@ -6,8 +6,6 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"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"
@ -17,6 +15,9 @@ import (
"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/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
type ( type (

View File

@ -5,14 +5,15 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd" "github.com/gogf/gf/v2/os/gcmd"
"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/gres" "github.com/gogf/gf/v2/os/gres"
"github.com/gogf/gf/v2/util/gtag" "github.com/gogf/gf/v2/util/gtag"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
var ( var (
@ -52,6 +53,7 @@ type cInitInput struct {
Mono bool `name:"mono" short:"m" brief:"initialize a mono-repo instead a single-repo" orphan:"true"` Mono bool `name:"mono" short:"m" brief:"initialize a mono-repo instead a single-repo" orphan:"true"`
Update bool `name:"update" short:"u" brief:"update to the latest goframe version" orphan:"true"` Update bool `name:"update" short:"u" brief:"update to the latest goframe version" orphan:"true"`
} }
type cInitOutput struct{} type cInitOutput struct{}
func (c cInit) Index(ctx context.Context, in cInitInput) (out *cInitOutput, err error) { func (c cInit) Index(ctx context.Context, in cInitInput) (out *cInitOutput, err error) {

View File

@ -3,8 +3,9 @@ package cmd
import ( import (
"context" "context"
"github.com/gogf/gf/cmd/gf/v2/internal/service"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/cmd/gf/v2/internal/service"
) )
var ( var (
@ -18,6 +19,7 @@ type cInstall struct {
type cInstallInput struct { type cInstallInput struct {
g.Meta `name:"install"` g.Meta `name:"install"`
} }
type cInstallOutput struct{} type cInstallOutput struct{}
func (c cInstall) Index(ctx context.Context, in cInstallInput) (out *cInstallOutput, err error) { func (c cInstall) Index(ctx context.Context, in cInstallInput) (out *cInstallOutput, err error) {

View File

@ -4,13 +4,14 @@ import (
"context" "context"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd" "github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gres" "github.com/gogf/gf/v2/os/gres"
"github.com/gogf/gf/v2/util/gtag" "github.com/gogf/gf/v2/util/gtag"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
var ( var (
@ -63,6 +64,7 @@ type cPackInput struct {
Prefix string `name:"prefix" short:"p" brief:"{cPackPrefixBrief}"` Prefix string `name:"prefix" short:"p" brief:"{cPackPrefixBrief}"`
KeepPath bool `name:"keepPath" short:"k" brief:"{cPackKeepPathBrief}" orphan:"true"` KeepPath bool `name:"keepPath" short:"k" brief:"{cPackKeepPathBrief}" orphan:"true"`
} }
type cPackOutput struct{} type cPackOutput struct{}
func (c cPack) Index(ctx context.Context, in cPackInput) (out *cPackOutput, err error) { func (c cPack) Index(ctx context.Context, in cPackInput) (out *cPackOutput, err error) {

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"runtime" "runtime"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"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"
"github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gfile"
@ -14,6 +13,8 @@ import (
"github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/os/gtimer" "github.com/gogf/gf/v2/os/gtimer"
"github.com/gogf/gf/v2/util/gtag" "github.com/gogf/gf/v2/util/gtag"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
var ( var (

View File

@ -3,7 +3,6 @@ package cmd
import ( import (
"context" "context"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
@ -11,6 +10,8 @@ import (
"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/v2/util/gtag"
"github.com/gogf/gf/v2/util/gutil" "github.com/gogf/gf/v2/util/gutil"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
var ( var (

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2" "github.com/gogf/gf/v2"
"github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
@ -12,6 +11,8 @@ import (
"github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gfile"
"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/utility/mlog"
) )
var ( var (
@ -25,6 +26,7 @@ type cVersion struct {
type cVersionInput struct { type cVersionInput struct {
g.Meta `name:"version"` g.Meta `name:"version"`
} }
type cVersionOutput struct{} type cVersionOutput struct{}
func (c cVersion) Index(ctx context.Context, in cVersionInput) (*cVersionOutput, error) { func (c cVersion) Index(ctx context.Context, in cVersionInput) (*cVersionOutput, error) {

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/container/garray"
"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"
@ -14,6 +13,8 @@ import (
"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/v2/util/gtag" "github.com/gogf/gf/v2/util/gtag"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
const ( const (

View File

@ -3,9 +3,10 @@ package gendao
import ( import (
"context" "context"
"github.com/gogf/gf/v2/os/gfile"
"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"
"github.com/gogf/gf/v2/os/gfile"
) )
func doClear(ctx context.Context, dirPath string) { func doClear(ctx context.Context, dirPath string) {

View File

@ -6,15 +6,16 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"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/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/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/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
) )
func generateDao(ctx context.Context, in CGenDaoInternalInput) { func generateDao(ctx context.Context, in CGenDaoInternalInput) {

View File

@ -5,13 +5,14 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"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/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/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"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
) )
func generateDo(ctx context.Context, in CGenDaoInternalInput) { func generateDo(ctx context.Context, in CGenDaoInternalInput) {

View File

@ -4,12 +4,13 @@ import (
"context" "context"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"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/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/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"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
) )
func generateEntity(ctx context.Context, in CGenDaoInternalInput) { func generateEntity(ctx context.Context, in CGenDaoInternalInput) {

View File

@ -4,8 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"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/gset" "github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
@ -16,6 +14,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 (

View File

@ -3,14 +3,15 @@ package genservice
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"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/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/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"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
) )
type generateServiceFilesInput struct { type generateServiceFilesInput struct {

View File

@ -5,8 +5,6 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/container/garray"
"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"
@ -15,6 +13,9 @@ import (
"github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gfile"
"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/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
var ( var (

View File

@ -1,11 +1,12 @@
package utils package utils
import ( import (
"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/text/gstr" "github.com/gogf/gf/v2/text/gstr"
"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"
) )
// 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.

View File

@ -2,16 +2,17 @@ package main
import ( import (
_ "github.com/gogf/gf/cmd/gf/v2/internal/packed" _ "github.com/gogf/gf/cmd/gf/v2/internal/packed"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcfg" "github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/cmd/gf/v2/internal/cmd"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/os/gcmd" "github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gfile" "github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/cmd/gf/v2/internal/cmd"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
) )
const ( const (

View File

@ -9,7 +9,6 @@
package garray_test package garray_test
import ( import (
"github.com/gogf/gf/v2/text/gstr"
"testing" "testing"
"time" "time"
@ -17,6 +16,7 @@ import (
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/json" "github.com/gogf/gf/v2/internal/json"
"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/util/gconv" "github.com/gogf/gf/v2/util/gconv"
) )

View File

@ -407,7 +407,6 @@ func (l *List) Removes(es []*Element) {
for _, e := range es { for _, e := range es {
l.list.Remove(e) l.list.Remove(e)
} }
return
} }
// RemoveAll removes all elements from list `l`. // RemoveAll removes all elements from list `l`.

View File

@ -157,7 +157,7 @@ func (m *AnyAnyMap) Search(key interface{}) (value interface{}, found bool) {
func (m *AnyAnyMap) Get(key interface{}) (value interface{}) { func (m *AnyAnyMap) Get(key interface{}) (value interface{}) {
m.mu.RLock() m.mu.RLock()
if m.data != nil { if m.data != nil {
value, _ = m.data[key] value = m.data[key]
} }
m.mu.RUnlock() m.mu.RUnlock()
return return

View File

@ -157,7 +157,7 @@ func (m *IntAnyMap) Search(key int) (value interface{}, found bool) {
func (m *IntAnyMap) Get(key int) (value interface{}) { func (m *IntAnyMap) Get(key int) (value interface{}) {
m.mu.RLock() m.mu.RLock()
if m.data != nil { if m.data != nil {
value, _ = m.data[key] value = m.data[key]
} }
m.mu.RUnlock() m.mu.RUnlock()
return return

View File

@ -143,7 +143,7 @@ func (m *IntIntMap) Search(key int) (value int, found bool) {
func (m *IntIntMap) Get(key int) (value int) { func (m *IntIntMap) Get(key int) (value int) {
m.mu.RLock() m.mu.RLock()
if m.data != nil { if m.data != nil {
value, _ = m.data[key] value = m.data[key]
} }
m.mu.RUnlock() m.mu.RUnlock()
return return

View File

@ -143,7 +143,7 @@ func (m *IntStrMap) Search(key int) (value string, found bool) {
func (m *IntStrMap) Get(key int) (value string) { func (m *IntStrMap) Get(key int) (value string) {
m.mu.RLock() m.mu.RLock()
if m.data != nil { if m.data != nil {
value, _ = m.data[key] value = m.data[key]
} }
m.mu.RUnlock() m.mu.RUnlock()
return return

View File

@ -152,7 +152,7 @@ func (m *StrAnyMap) Search(key string) (value interface{}, found bool) {
func (m *StrAnyMap) Get(key string) (value interface{}) { func (m *StrAnyMap) Get(key string) (value interface{}) {
m.mu.RLock() m.mu.RLock()
if m.data != nil { if m.data != nil {
value, _ = m.data[key] value = m.data[key]
} }
m.mu.RUnlock() m.mu.RUnlock()
return return

View File

@ -144,7 +144,7 @@ func (m *StrIntMap) Search(key string) (value int, found bool) {
func (m *StrIntMap) Get(key string) (value int) { func (m *StrIntMap) Get(key string) (value int) {
m.mu.RLock() m.mu.RLock()
if m.data != nil { if m.data != nil {
value, _ = m.data[key] value = m.data[key]
} }
m.mu.RUnlock() m.mu.RUnlock()
return return

View File

@ -144,7 +144,7 @@ func (m *StrStrMap) Search(key string) (value string, found bool) {
func (m *StrStrMap) Get(key string) (value string) { func (m *StrStrMap) Get(key string) (value string) {
m.mu.RLock() m.mu.RLock()
if m.data != nil { if m.data != nil {
value, _ = m.data[key] value = m.data[key]
} }
m.mu.RUnlock() m.mu.RUnlock()
return return

View File

@ -101,6 +101,7 @@ func Test_Map_Basic(t *testing.T) {
t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"})
}) })
} }
func Test_Map_Set_Fun(t *testing.T) { func Test_Map_Set_Fun(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
m := gmap.New() m := gmap.New()
@ -123,6 +124,7 @@ func Test_Map_Batch(t *testing.T) {
t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"})
}) })
} }
func Test_Map_Iterator(t *testing.T) { func Test_Map_Iterator(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
expect := map[interface{}]interface{}{1: 1, "key1": "val1"} expect := map[interface{}]interface{}{1: 1, "key1": "val1"}
@ -175,6 +177,7 @@ func Test_Map_Clone(t *testing.T) {
t.AssertIN("key1", m.Keys()) t.AssertIN("key1", m.Keys())
}) })
} }
func Test_Map_Basic_Merge(t *testing.T) { func Test_Map_Basic_Merge(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
m1 := gmap.New() m1 := gmap.New()

View File

@ -16,7 +16,9 @@ import (
) )
var hashMap = gmap.New(true) var hashMap = gmap.New(true)
var listMap = gmap.NewListMap(true) var listMap = gmap.NewListMap(true)
var treeMap = gmap.NewTreeMap(gutil.ComparatorInt, true) var treeMap = gmap.NewTreeMap(gutil.ComparatorInt, true)
func Benchmark_HashMap_Set(b *testing.B) { func Benchmark_HashMap_Set(b *testing.B) {

View File

@ -16,11 +16,17 @@ import (
) )
var anyAnyMap = gmap.NewAnyAnyMap(true) var anyAnyMap = gmap.NewAnyAnyMap(true)
var intIntMap = gmap.NewIntIntMap(true) var intIntMap = gmap.NewIntIntMap(true)
var intAnyMap = gmap.NewIntAnyMap(true) var intAnyMap = gmap.NewIntAnyMap(true)
var intStrMap = gmap.NewIntStrMap(true) var intStrMap = gmap.NewIntStrMap(true)
var strIntMap = gmap.NewStrIntMap(true) var strIntMap = gmap.NewStrIntMap(true)
var strAnyMap = gmap.NewStrAnyMap(true) var strAnyMap = gmap.NewStrAnyMap(true)
var strStrMap = gmap.NewStrStrMap(true) var strStrMap = gmap.NewStrStrMap(true)
func Benchmark_IntIntMap_Set(b *testing.B) { func Benchmark_IntIntMap_Set(b *testing.B) {

View File

@ -16,6 +16,7 @@ import (
) )
var gm = gmap.NewIntIntMap(true) var gm = gmap.NewIntIntMap(true)
var sm = sync.Map{} var sm = sync.Map{}
func Benchmark_GMapSet(b *testing.B) { func Benchmark_GMapSet(b *testing.B) {

View File

@ -16,11 +16,17 @@ import (
) )
var anyAnyMapUnsafe = gmap.New() var anyAnyMapUnsafe = gmap.New()
var intIntMapUnsafe = gmap.NewIntIntMap() var intIntMapUnsafe = gmap.NewIntIntMap()
var intAnyMapUnsafe = gmap.NewIntAnyMap() var intAnyMapUnsafe = gmap.NewIntAnyMap()
var intStrMapUnsafe = gmap.NewIntStrMap() var intStrMapUnsafe = gmap.NewIntStrMap()
var strIntMapUnsafe = gmap.NewStrIntMap() var strIntMapUnsafe = gmap.NewStrIntMap()
var strAnyMapUnsafe = gmap.NewStrAnyMap() var strAnyMapUnsafe = gmap.NewStrAnyMap()
var strStrMapUnsafe = gmap.NewStrStrMap() var strStrMapUnsafe = gmap.NewStrStrMap()
// Writing benchmarks. // Writing benchmarks.

View File

@ -8,11 +8,11 @@ package gmap_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/util/gconv"
) )
func ExampleAnyAnyMap_Iterator() { func ExampleAnyAnyMap_Iterator() {

View File

@ -8,6 +8,7 @@ package gmap_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/json" "github.com/gogf/gf/v2/internal/json"

View File

@ -8,6 +8,7 @@ package gmap_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/json" "github.com/gogf/gf/v2/internal/json"

View File

@ -8,11 +8,11 @@ package gmap_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/util/gconv"
) )
func ExampleStrAnyMap_Iterator() { func ExampleStrAnyMap_Iterator() {

View File

@ -8,6 +8,7 @@ package gmap_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/json" "github.com/gogf/gf/v2/internal/json"

View File

@ -8,12 +8,11 @@ package gmap_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/util/gconv"
) )
func ExampleStrStrMap_Iterator() { func ExampleStrStrMap_Iterator() {

View File

@ -9,9 +9,8 @@ package gmap_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/util/gutil"
"github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/util/gutil"
) )
func ExampleNew() { func ExampleNew() {

View File

@ -117,6 +117,7 @@ func Test_IntAnyMap_Batch(t *testing.T) {
t.Assert(m.Map(), map[int]interface{}{3: 3}) t.Assert(m.Map(), map[int]interface{}{3: 3})
}) })
} }
func Test_IntAnyMap_Iterator(t *testing.T) { func Test_IntAnyMap_Iterator(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
expect := map[int]interface{}{1: 1, 2: "2"} expect := map[int]interface{}{1: 1, 2: "2"}
@ -154,6 +155,7 @@ func Test_IntAnyMap_Lock(t *testing.T) {
}) })
}) })
} }
func Test_IntAnyMap_Clone(t *testing.T) { func Test_IntAnyMap_Clone(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
// clone 方法是深克隆 // clone 方法是深克隆
@ -169,6 +171,7 @@ func Test_IntAnyMap_Clone(t *testing.T) {
t.AssertIN(2, m.Keys()) t.AssertIN(2, m.Keys())
}) })
} }
func Test_IntAnyMap_Merge(t *testing.T) { func Test_IntAnyMap_Merge(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
m1 := gmap.NewIntAnyMap() m1 := gmap.NewIntAnyMap()

View File

@ -152,6 +152,7 @@ func Test_IntStrMap_Batch(t *testing.T) {
t.Assert(m.Map(), map[int]interface{}{3: "c"}) t.Assert(m.Map(), map[int]interface{}{3: "c"})
}) })
} }
func Test_IntStrMap_Iterator(t *testing.T) { func Test_IntStrMap_Iterator(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
expect := map[int]string{1: "a", 2: "b"} expect := map[int]string{1: "a", 2: "b"}
@ -204,6 +205,7 @@ func Test_IntStrMap_Clone(t *testing.T) {
t.AssertIN(2, m.Keys()) t.AssertIN(2, m.Keys())
}) })
} }
func Test_IntStrMap_Merge(t *testing.T) { func Test_IntStrMap_Merge(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
m1 := gmap.NewIntStrMap() m1 := gmap.NewIntStrMap()

View File

@ -146,6 +146,7 @@ func Test_StrAnyMap_Lock(t *testing.T) {
}) })
}) })
} }
func Test_StrAnyMap_Clone(t *testing.T) { func Test_StrAnyMap_Clone(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
// clone 方法是深克隆 // clone 方法是深克隆
@ -161,6 +162,7 @@ func Test_StrAnyMap_Clone(t *testing.T) {
t.AssertIN("b", m.Keys()) t.AssertIN("b", m.Keys())
}) })
} }
func Test_StrAnyMap_Merge(t *testing.T) { func Test_StrAnyMap_Merge(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
m1 := gmap.NewStrAnyMap() m1 := gmap.NewStrAnyMap()

View File

@ -117,6 +117,7 @@ func Test_StrIntMap_Batch(t *testing.T) {
t.Assert(m.Map(), map[string]int{"c": 3}) t.Assert(m.Map(), map[string]int{"c": 3})
}) })
} }
func Test_StrIntMap_Iterator(t *testing.T) { func Test_StrIntMap_Iterator(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
expect := map[string]int{"a": 1, "b": 2} expect := map[string]int{"a": 1, "b": 2}
@ -170,6 +171,7 @@ func Test_StrIntMap_Clone(t *testing.T) {
t.AssertIN("b", m.Keys()) t.AssertIN("b", m.Keys())
}) })
} }
func Test_StrIntMap_Merge(t *testing.T) { func Test_StrIntMap_Merge(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
m1 := gmap.NewStrIntMap() m1 := gmap.NewStrIntMap()

View File

@ -116,6 +116,7 @@ func Test_StrStrMap_Batch(t *testing.T) {
t.Assert(m.Map(), map[string]string{"c": "c"}) t.Assert(m.Map(), map[string]string{"c": "c"})
}) })
} }
func Test_StrStrMap_Iterator(t *testing.T) { func Test_StrStrMap_Iterator(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
expect := map[string]string{"a": "a", "b": "b"} expect := map[string]string{"a": "a", "b": "b"}
@ -153,6 +154,7 @@ func Test_StrStrMap_Lock(t *testing.T) {
}) })
}) })
} }
func Test_StrStrMap_Clone(t *testing.T) { func Test_StrStrMap_Clone(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
// clone 方法是深克隆 // clone 方法是深克隆
@ -168,6 +170,7 @@ func Test_StrStrMap_Clone(t *testing.T) {
t.AssertIN("b", m.Keys()) t.AssertIN("b", m.Keys())
}) })
} }
func Test_StrStrMap_Merge(t *testing.T) { func Test_StrStrMap_Merge(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
m1 := gmap.NewStrStrMap() m1 := gmap.NewStrStrMap()

View File

@ -106,6 +106,7 @@ func Test_ListMap_Batch(t *testing.T) {
t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"})
}) })
} }
func Test_ListMap_Iterator(t *testing.T) { func Test_ListMap_Iterator(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
expect := map[interface{}]interface{}{1: 1, "key1": "val1"} expect := map[interface{}]interface{}{1: 1, "key1": "val1"}

View File

@ -107,6 +107,7 @@ func Test_TreeMap_Batch(t *testing.T) {
t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"}) t.Assert(m.Map(), map[interface{}]interface{}{"key2": "val2", "key3": "val3"})
}) })
} }
func Test_TreeMap_Iterator(t *testing.T) { func Test_TreeMap_Iterator(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
expect := map[interface{}]interface{}{1: 1, "key1": "val1"} expect := map[interface{}]interface{}{1: 1, "key1": "val1"}

View File

@ -97,7 +97,6 @@ func (p *Pool) Clear() {
} else { } else {
p.list.RemoveAll() p.list.RemoveAll()
} }
} }
// Get picks and returns an item from pool. If the pool is empty and NewFunc is defined, // Get picks and returns an item from pool. If the pool is empty and NewFunc is defined,

View File

@ -17,6 +17,7 @@ import (
) )
var pool = gpool.New(time.Hour, nil) var pool = gpool.New(time.Hour, nil)
var syncp = sync.Pool{} var syncp = sync.Pool{}
func BenchmarkGPoolPut(b *testing.B) { func BenchmarkGPoolPut(b *testing.B) {

View File

@ -9,8 +9,9 @@ package gpool_test
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/gogf/gf/v2/container/gpool"
"time" "time"
"github.com/gogf/gf/v2/container/gpool"
) )
func ExampleNew() { func ExampleNew() {

View File

@ -21,6 +21,7 @@ var nf gpool.NewFunc = func() (i interface{}, e error) {
} }
var assertIndex int = 0 var assertIndex int = 0
var ef gpool.ExpireFunc = func(i interface{}) { var ef gpool.ExpireFunc = func(i interface{}) {
assertIndex++ assertIndex++
gtest.Assert(i, assertIndex) gtest.Assert(i, assertIndex)

View File

@ -15,7 +15,6 @@
// 3. Support dynamic queue size(unlimited queue size); // 3. Support dynamic queue size(unlimited queue size);
// //
// 4. Blocking when reading data from queue; // 4. Blocking when reading data from queue;
//
package gqueue package gqueue
import ( import (

View File

@ -15,9 +15,13 @@ import (
) )
var bn = 20000000 var bn = 20000000
var length = 1000000 var length = 1000000
var qstatic = gqueue.New(length) var qstatic = gqueue.New(length)
var qdynamic = gqueue.New() var qdynamic = gqueue.New()
var cany = make(chan interface{}, length) var cany = make(chan interface{}, length)
func Benchmark_Gqueue_StaticPushAndPop(b *testing.B) { func Benchmark_Gqueue_StaticPushAndPop(b *testing.B) {

View File

@ -153,7 +153,6 @@ func (r *Ring) Next() *Ring {
// them creates a single ring with the elements of s inserted // them creates a single ring with the elements of s inserted
// after r. The result points to the element following the // after r. The result points to the element following the
// last element of s after insertion. // last element of s after insertion.
//
func (r *Ring) Link(s *Ring) *Ring { func (r *Ring) Link(s *Ring) *Ring {
r.mu.Lock() r.mu.Lock()
s.mu.Lock() s.mu.Lock()
@ -168,7 +167,6 @@ func (r *Ring) Link(s *Ring) *Ring {
// Unlink removes n % r.Len() elements from the ring r, starting // Unlink removes n % r.Len() elements from the ring r, starting
// at r.Next(). If n % r.Len() == 0, r remains unchanged. // at r.Next(). If n % r.Len() == 0, r remains unchanged.
// The result is the removed sub-ring. r must not be empty. // The result is the removed sub-ring. r must not be empty.
//
func (r *Ring) Unlink(n int) *Ring { func (r *Ring) Unlink(n int) *Ring {
r.mu.Lock() r.mu.Lock()
resultRing := r.ring.Unlink(n) resultRing := r.ring.Unlink(n)

View File

@ -15,6 +15,7 @@ import (
) )
var length = 10000 var length = 10000
var ringObject = gring.New(length, true) var ringObject = gring.New(length, true)
func BenchmarkRing_Put(b *testing.B) { func BenchmarkRing_Put(b *testing.B) {

View File

@ -43,6 +43,7 @@ func TestRing_Val(t *testing.T) {
r.Set(&Student{3, "jack", true}) r.Set(&Student{3, "jack", true})
}) })
} }
func TestRing_CapLen(t *testing.T) { func TestRing_CapLen(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
r := gring.New(10) r := gring.New(10)

View File

@ -55,7 +55,7 @@ func NewFrom(items interface{}, safe ...bool) *Set {
func (set *Set) Iterator(f func(v interface{}) bool) { func (set *Set) Iterator(f func(v interface{}) bool) {
set.mu.RLock() set.mu.RLock()
defer set.mu.RUnlock() defer set.mu.RUnlock()
for k, _ := range set.data { for k := range set.data {
if !f(k) { if !f(k) {
break break
} }
@ -211,7 +211,7 @@ func (set *Set) Join(glue string) string {
i = 0 i = 0
buffer = bytes.NewBuffer(nil) buffer = bytes.NewBuffer(nil)
) )
for k, _ := range set.data { for k := range set.data {
buffer.WriteString(gconv.String(k)) buffer.WriteString(gconv.String(k))
if i != l-1 { if i != l-1 {
buffer.WriteString(glue) buffer.WriteString(glue)
@ -229,13 +229,13 @@ func (set *Set) String() string {
set.mu.RLock() set.mu.RLock()
defer set.mu.RUnlock() defer set.mu.RUnlock()
var ( var (
s = "" s string
l = len(set.data) l = len(set.data)
i = 0 i = 0
buffer = bytes.NewBuffer(nil) buffer = bytes.NewBuffer(nil)
) )
buffer.WriteByte('[') buffer.WriteByte('[')
for k, _ := range set.data { for k := range set.data {
s = gconv.String(k) s = gconv.String(k)
if gstr.IsNumeric(s) { if gstr.IsNumeric(s) {
buffer.WriteString(s) buffer.WriteString(s)
@ -416,7 +416,7 @@ func (set *Set) Merge(others ...*Set) *Set {
func (set *Set) Sum() (sum int) { func (set *Set) Sum() (sum int) {
set.mu.RLock() set.mu.RLock()
defer set.mu.RUnlock() defer set.mu.RUnlock()
for k, _ := range set.data { for k := range set.data {
sum += gconv.Int(k) sum += gconv.Int(k)
} }
return return
@ -426,7 +426,7 @@ func (set *Set) Sum() (sum int) {
func (set *Set) Pop() interface{} { func (set *Set) Pop() interface{} {
set.mu.Lock() set.mu.Lock()
defer set.mu.Unlock() defer set.mu.Unlock()
for k, _ := range set.data { for k := range set.data {
delete(set.data, k) delete(set.data, k)
return k return k
} }
@ -446,7 +446,7 @@ func (set *Set) Pops(size int) []interface{} {
} }
index := 0 index := 0
array := make([]interface{}, size) array := make([]interface{}, size)
for k, _ := range set.data { for k := range set.data {
delete(set.data, k) delete(set.data, k)
array[index] = k array[index] = k
index++ index++
@ -519,7 +519,7 @@ func (set *Set) DeepCopy() interface{} {
set.mu.RLock() set.mu.RLock()
defer set.mu.RUnlock() defer set.mu.RUnlock()
data := make([]interface{}, 0) data := make([]interface{}, 0)
for k, _ := range set.data { for k := range set.data {
data = append(data, k) data = append(data, k)
} }
return NewFrom(data, set.mu.IsSafe()) return NewFrom(data, set.mu.IsSafe())

View File

@ -47,7 +47,7 @@ func NewIntSetFrom(items []int, safe ...bool) *IntSet {
func (set *IntSet) Iterator(f func(v int) bool) { func (set *IntSet) Iterator(f func(v int) bool) {
set.mu.RLock() set.mu.RLock()
defer set.mu.RUnlock() defer set.mu.RUnlock()
for k, _ := range set.data { for k := range set.data {
if !f(k) { if !f(k) {
break break
} }
@ -172,7 +172,7 @@ func (set *IntSet) Slice() []int {
i = 0 i = 0
ret = make([]int, len(set.data)) ret = make([]int, len(set.data))
) )
for k, _ := range set.data { for k := range set.data {
ret[i] = k ret[i] = k
i++ i++
} }
@ -192,7 +192,7 @@ func (set *IntSet) Join(glue string) string {
i = 0 i = 0
buffer = bytes.NewBuffer(nil) buffer = bytes.NewBuffer(nil)
) )
for k, _ := range set.data { for k := range set.data {
buffer.WriteString(gconv.String(k)) buffer.WriteString(gconv.String(k))
if i != l-1 { if i != l-1 {
buffer.WriteString(glue) buffer.WriteString(glue)
@ -375,7 +375,7 @@ func (set *IntSet) Merge(others ...*IntSet) *IntSet {
func (set *IntSet) Sum() (sum int) { func (set *IntSet) Sum() (sum int) {
set.mu.RLock() set.mu.RLock()
defer set.mu.RUnlock() defer set.mu.RUnlock()
for k, _ := range set.data { for k := range set.data {
sum += k sum += k
} }
return return
@ -385,7 +385,7 @@ func (set *IntSet) Sum() (sum int) {
func (set *IntSet) Pop() int { func (set *IntSet) Pop() int {
set.mu.Lock() set.mu.Lock()
defer set.mu.Unlock() defer set.mu.Unlock()
for k, _ := range set.data { for k := range set.data {
delete(set.data, k) delete(set.data, k)
return k return k
} }
@ -405,7 +405,7 @@ func (set *IntSet) Pops(size int) []int {
} }
index := 0 index := 0
array := make([]int, size) array := make([]int, size)
for k, _ := range set.data { for k := range set.data {
delete(set.data, k) delete(set.data, k)
array[index] = k array[index] = k
index++ index++

View File

@ -49,7 +49,7 @@ func NewStrSetFrom(items []string, safe ...bool) *StrSet {
func (set *StrSet) Iterator(f func(v string) bool) { func (set *StrSet) Iterator(f func(v string) bool) {
set.mu.RLock() set.mu.RLock()
defer set.mu.RUnlock() defer set.mu.RUnlock()
for k, _ := range set.data { for k := range set.data {
if !f(k) { if !f(k) {
break break
} }
@ -146,7 +146,7 @@ func (set *StrSet) Contains(item string) bool {
func (set *StrSet) ContainsI(item string) bool { func (set *StrSet) ContainsI(item string) bool {
set.mu.RLock() set.mu.RLock()
defer set.mu.RUnlock() defer set.mu.RUnlock()
for k, _ := range set.data { for k := range set.data {
if strings.EqualFold(k, item) { if strings.EqualFold(k, item) {
return true return true
} }
@ -206,7 +206,7 @@ func (set *StrSet) Join(glue string) string {
i = 0 i = 0
buffer = bytes.NewBuffer(nil) buffer = bytes.NewBuffer(nil)
) )
for k, _ := range set.data { for k := range set.data {
buffer.WriteString(k) buffer.WriteString(k)
if i != l-1 { if i != l-1 {
buffer.WriteString(glue) buffer.WriteString(glue)
@ -229,7 +229,7 @@ func (set *StrSet) String() string {
buffer = bytes.NewBuffer(nil) buffer = bytes.NewBuffer(nil)
) )
buffer.WriteByte('[') buffer.WriteByte('[')
for k, _ := range set.data { for k := range set.data {
buffer.WriteString(`"` + gstr.QuoteMeta(k, `"\`) + `"`) buffer.WriteString(`"` + gstr.QuoteMeta(k, `"\`) + `"`)
if i != l-1 { if i != l-1 {
buffer.WriteByte(',') buffer.WriteByte(',')
@ -405,7 +405,7 @@ func (set *StrSet) Merge(others ...*StrSet) *StrSet {
func (set *StrSet) Sum() (sum int) { func (set *StrSet) Sum() (sum int) {
set.mu.RLock() set.mu.RLock()
defer set.mu.RUnlock() defer set.mu.RUnlock()
for k, _ := range set.data { for k := range set.data {
sum += gconv.Int(k) sum += gconv.Int(k)
} }
return return
@ -415,7 +415,7 @@ func (set *StrSet) Sum() (sum int) {
func (set *StrSet) Pop() string { func (set *StrSet) Pop() string {
set.mu.Lock() set.mu.Lock()
defer set.mu.Unlock() defer set.mu.Unlock()
for k, _ := range set.data { for k := range set.data {
delete(set.data, k) delete(set.data, k)
return k return k
} }
@ -435,7 +435,7 @@ func (set *StrSet) Pops(size int) []string {
} }
index := 0 index := 0
array := make([]string, size) array := make([]string, size)
for k, _ := range set.data { for k := range set.data {
delete(set.data, k) delete(set.data, k)
array[index] = k array[index] = k
index++ index++

View File

@ -16,10 +16,15 @@ import (
) )
var intSet = gset.NewIntSet(true) var intSet = gset.NewIntSet(true)
var anySet = gset.NewSet(true) var anySet = gset.NewSet(true)
var strSet = gset.NewStrSet(true) var strSet = gset.NewStrSet(true)
var intSetUnsafe = gset.NewIntSet() var intSetUnsafe = gset.NewIntSet()
var anySetUnsafe = gset.NewSet() var anySetUnsafe = gset.NewSet()
var strSetUnsafe = gset.NewStrSet() var strSetUnsafe = gset.NewStrSet()
func Benchmark_IntSet_Add(b *testing.B) { func Benchmark_IntSet_Add(b *testing.B) {

View File

@ -56,6 +56,7 @@ func Test_AVLTree_Basic(t *testing.T) {
t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"}) t.Assert(m2.Map(), map[interface{}]interface{}{1: 1, "key1": "val1"})
}) })
} }
func Test_AVLTree_Set_Fun(t *testing.T) { func Test_AVLTree_Set_Fun(t *testing.T) {
//GetOrSetFunc lock or unlock //GetOrSetFunc lock or unlock
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {

View File

@ -8,6 +8,7 @@ package gtree_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/container/gtree" "github.com/gogf/gf/v2/container/gtree"
"github.com/gogf/gf/v2/internal/json" "github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/gconv"

View File

@ -8,6 +8,7 @@ package gtree_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/container/gtree" "github.com/gogf/gf/v2/container/gtree"
"github.com/gogf/gf/v2/internal/json" "github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/gconv"

View File

@ -8,6 +8,7 @@ package gtree_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/container/gtree" "github.com/gogf/gf/v2/container/gtree"
"github.com/gogf/gf/v2/internal/json" "github.com/gogf/gf/v2/internal/json"
"github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/gconv"

View File

@ -8,6 +8,7 @@ package gtree_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/container/gtree" "github.com/gogf/gf/v2/container/gtree"
"github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/gutil" "github.com/gogf/gf/v2/util/gutil"

View File

@ -58,6 +58,7 @@ func Test_Uint64(t *testing.T) {
t.AssertNil(copyVal) t.AssertNil(copyVal)
}) })
} }
func Test_Uint64_JSON(t *testing.T) { func Test_Uint64_JSON(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
i := gtype.NewUint64(math.MaxUint64) i := gtype.NewUint64(math.MaxUint64)

View File

@ -55,6 +55,7 @@ func Test_Val(t *testing.T) {
t.Assert(objOne.Val(), nil) t.Assert(objOne.Val(), nil)
}) })
} }
func Test_Interface(t *testing.T) { func Test_Interface(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
objOne := gvar.New(1, true) objOne := gvar.New(1, true)
@ -66,6 +67,7 @@ func Test_Interface(t *testing.T) {
t.Assert(objTwoOld, 1) t.Assert(objTwoOld, 1)
}) })
} }
func Test_IsNil(t *testing.T) { func Test_IsNil(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
objOne := gvar.New(nil, true) objOne := gvar.New(nil, true)
@ -102,6 +104,7 @@ func Test_String(t *testing.T) {
}) })
} }
func Test_Bool(t *testing.T) { func Test_Bool(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var ok bool = true var ok bool = true
@ -204,6 +207,7 @@ func Test_Uint64(t *testing.T) {
}) })
} }
func Test_Float32(t *testing.T) { func Test_Float32(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var num float32 = 1.1 var num float32 = 1.1

View File

@ -13,7 +13,6 @@ import (
"github.com/apolloconfig/agollo/v4" "github.com/apolloconfig/agollo/v4"
apolloConfig "github.com/apolloconfig/agollo/v4/env/config" apolloConfig "github.com/apolloconfig/agollo/v4/env/config"
"github.com/apolloconfig/agollo/v4/storage" "github.com/apolloconfig/agollo/v4/storage"
"github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"

View File

@ -9,11 +9,12 @@ package apollo_test
import ( import (
"testing" "testing"
"github.com/gogf/gf/contrib/config/apollo/v2"
"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"
"github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/guid" "github.com/gogf/gf/v2/util/guid"
"github.com/gogf/gf/contrib/config/apollo/v2"
) )
var ( var (

View File

@ -0,0 +1,92 @@
# nacos
Package `nacos` implements GoFrame `gcfg.Adapter` using nacos service.
# Installation
```
go get -u github.com/gogf/gf/contrib/config/nacos/v2
```
# Usage
## Create a custom boot package
If you wish using configuration from nacos globally,
it is strongly recommended creating a custom boot package in very top import,
which sets the Adapter of default configuration instance before any other package boots.
```go
package boot
import (
"github.com/gogf/gf/contrib/config/nacos/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
)
func init() {
var (
ctx = gctx.GetInitCtx()
serverConfig = constant.ServerConfig{
IpAddr: "localhost",
Port: 8848,
}
clientConfig = constant.ClientConfig{
CacheDir: "/tmp/nacos",
LogDir: "/tmp/nacos",
}
configParam = vo.ConfigParam{
DataId: "config.toml",
Group: "test",
}
)
// Create anacosClient that implements gcfg.Adapter.
adapter, err := nacos.New(ctx, nacos.Config{
ServerConfigs: []constant.ServerConfig{serverConfig},
ClientConfig: clientConfig,
ConfigParam: configParam,
})
if err != nil {
g.Log().Fatalf(ctx, `%+v`, err)
}
// Change the adapter of default configuration instance.
g.Cfg().SetAdapter(adapter)
}
```
## Import boot package in top of main
It is strongly recommended import your boot package in top of your `main.go`.
Note the top `import`: `_ "github.com/gogf/gf/example/config/nacos/boot"` .
```go
package main
import (
_ "github.com/gogf/gf/example/config/nacos/boot"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
var ctx = gctx.GetInitCtx()
// Available checks.
g.Dump(g.Cfg().Available(ctx))
// All key-value configurations.
g.Dump(g.Cfg().Data(ctx))
// Retrieve certain value by key.
g.Dump(g.Cfg().MustGet(ctx, "server.address"))
}
```
## License
`GoFrame nacos` is licensed under the [MIT License](../../../LICENSE), 100% free and open-source, forever.

View File

@ -0,0 +1,10 @@
module github.com/gogf/gf/contrib/config/nacos/v2
go 1.15
require (
github.com/gogf/gf/v2 v2.2.1
github.com/nacos-group/nacos-sdk-go v1.1.2
)
replace github.com/gogf/gf/v2 => ../../../

242
contrib/config/nacos/go.sum Normal file
View File

@ -0,0 +1,242 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 h1:zOVTBdCKFd9JbCKz9/nt+FovbjPFmb7mUnp8nH9fQBA=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDHxfTGEciD+yhvOU/5s1Rfk=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E=
github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
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/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/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 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
github.com/grokify/html-strip-tags-go v0.0.1/go.mod h1:2Su6romC5/1VXOQMaWL2yb618ARB8iVo6/DR99A6d78=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/nacos-group/nacos-sdk-go v1.1.2 h1:lWTpf5SXLetQetS7p31eGic/ncqsnn0Zbau1i3eC25Y=
github.com/nacos-group/nacos-sdk-go v1.1.2/go.mod h1:I8Vj4M8ZLpBk7EY2A8RXQE1SbfCA7b56TJBPIFTrUYE=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ=
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM=
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
go.opentelemetry.io/otel/sdk v1.7.0 h1:4OmStpcKVOfvDOgCt7UriAPtKolwIhxpnSNI/yK+1B0=
go.opentelemetry.io/otel/sdk v1.7.0/go.mod h1:uTEOTwaqIVuTGiJN7ii13Ibp75wJmYUDe374q6cZwUU=
go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o=
go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU=
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/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/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/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-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/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-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/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-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
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.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2 h1:GLw7MR8AfAG2GmGcmVgObFOHXYypgGjnGno25RDwn3Y=
golang.org/x/text v0.3.8-0.20211105212822-18b340fc7af2/go.mod h1:EFNZuWvGYxIRUEX+K8UmCFwYmZjqcrnq15ZuVldZkZ0=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/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-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk=
gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=

View File

@ -0,0 +1,137 @@
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
// Package nacos implements gcfg.Adapter using nacos service.
package nacos
import (
"context"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcfg"
"github.com/nacos-group/nacos-sdk-go/clients"
"github.com/nacos-group/nacos-sdk-go/clients/config_client"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
)
// Config is the configuration object for nacos client.
type Config struct {
ServerConfigs []constant.ServerConfig `v:"required"` // See constant.ServerConfig
ClientConfig constant.ClientConfig `v:"required"` // See constant.ClientConfig
ConfigParam vo.ConfigParam `v:"required"` // See vo.ConfigParam
Watch bool // Watch watches remote configuration updates, which updates local configuration in memory immediately when remote configuration changes.
}
// Client implements gcfg.Adapter implementing using nacos service.
type Client struct {
config Config // Config object when created.
client config_client.IConfigClient // Nacos config client.
value *g.Var // Configmap content cached. It is `*gjson.Json` value internally.
}
// New creates and returns gcfg.Adapter implementing using nacos service.
func New(ctx context.Context, config Config) (adapter gcfg.Adapter, err error) {
// Data validation.
err = g.Validator().Data(config).Run(ctx)
if err != nil {
return nil, err
}
client := &Client{
config: config,
value: g.NewVar(nil, true),
}
client.client, err = clients.CreateConfigClient(map[string]interface{}{
"serverConfigs": config.ServerConfigs,
"clientConfig": config.ClientConfig,
})
if err != nil {
return nil, gerror.Wrapf(err, `create nacos client failed with config: %+v`, config)
}
err = client.addWatcher()
if err != nil {
return nil, err
}
return client, nil
}
// Available checks and returns the backend configuration service is available.
// The optional parameter `resource` specifies certain configuration resource.
//
// Note that this function does not return error as it just does simply check for
// backend configuration service.
func (c *Client) Available(ctx context.Context, resource ...string) (ok bool) {
if len(resource) == 0 && !c.value.IsNil() {
return true
}
_, err := c.client.GetConfig(c.config.ConfigParam)
return err == nil
}
// Get retrieves and returns value by specified `pattern` in current resource.
// Pattern like:
// "x.y.z" for map item.
// "x.0.y" for slice item.
func (c *Client) Get(ctx context.Context, pattern string) (value interface{}, err error) {
if c.value.IsNil() {
if err = c.updateLocalValue(); err != nil {
return nil, err
}
}
return c.value.Val().(*gjson.Json).Get(pattern).Val(), nil
}
// Data retrieves and returns all configuration data in current resource as map.
// Note that this function may lead lots of memory usage if configuration data is too large,
// you can implement this function if necessary.
func (c *Client) Data(ctx context.Context) (data map[string]interface{}, err error) {
if c.value.IsNil() {
if err = c.updateLocalValue(); err != nil {
return nil, err
}
}
return c.value.Val().(*gjson.Json).Map(), nil
}
func (c *Client) updateLocalValue() (err error) {
content, err := c.client.GetConfig(c.config.ConfigParam)
if err != nil {
return gerror.Wrap(err, `retrieve config from nacos failed`)
}
return c.doUpdate(content)
}
func (c *Client) doUpdate(content string) (err error) {
var j *gjson.Json
if j, err = gjson.LoadContent(content); err != nil {
return gerror.Wrap(err, `parse config map item from nacos failed`)
}
c.value.Set(j)
return nil
}
func (c *Client) addWatcher() error {
if !c.config.Watch {
return nil
}
c.config.ConfigParam.OnChange = func(namespace, group, dataId, data string) {
c.doUpdate(data)
}
if err := c.client.ListenConfig(c.config.ConfigParam); err != nil {
return gerror.Wrap(err, `watch config from namespace failed`)
}
return nil
}

View File

@ -0,0 +1,59 @@
// Copyright 2019 gf Author(https://github.com/gogf/gf). 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 nacos_test
import (
"testing"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/guid"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
"github.com/gogf/gf/contrib/config/nacos/v2"
)
var (
ctx = gctx.GetInitCtx()
serverConfig = constant.ServerConfig{
IpAddr: "localhost",
Port: 8848,
}
clientConfig = constant.ClientConfig{
CacheDir: "/tmp/nacos",
LogDir: "/tmp/nacos",
}
configParam = vo.ConfigParam{
DataId: "config.toml",
Group: "test",
}
)
func TestNacos(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
adapter, err := nacos.New(ctx, nacos.Config{
ServerConfigs: []constant.ServerConfig{serverConfig},
ClientConfig: clientConfig,
ConfigParam: configParam,
})
t.AssertNil(err)
config := g.Cfg(guid.S())
config.SetAdapter(adapter)
t.Assert(config.Available(ctx), true)
v, err := config.Get(ctx, `server.address`)
t.AssertNil(err)
t.Assert(v.String(), ":8000")
m, err := config.Data(ctx)
t.AssertNil(err)
t.AssertGT(len(m), 0)
})
}

View File

@ -10,15 +10,14 @@ package polaris
import ( import (
"context" "context"
"github.com/polarismesh/polaris-go"
"github.com/polarismesh/polaris-go/api"
"github.com/polarismesh/polaris-go/pkg/model"
"github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcfg" "github.com/gogf/gf/v2/os/gcfg"
"github.com/gogf/gf/v2/text/gstr" "github.com/gogf/gf/v2/text/gstr"
"github.com/polarismesh/polaris-go"
"github.com/polarismesh/polaris-go/api"
"github.com/polarismesh/polaris-go/pkg/model"
) )
// LogDir sets the log directory for polaris. // LogDir sets the log directory for polaris.

View File

@ -18,17 +18,16 @@ import (
"time" "time"
"github.com/ClickHouse/clickhouse-go/v2" "github.com/ClickHouse/clickhouse-go/v2"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/util/gutil"
"github.com/google/uuid"
"github.com/shopspring/decimal"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/text/gregex" "github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/gutil"
"github.com/google/uuid"
"github.com/shopspring/decimal"
) )
// Driver is the driver for postgresql database. // Driver is the driver for postgresql database.

View File

@ -12,9 +12,6 @@ import (
"testing" "testing"
"time" "time"
"github.com/google/uuid"
"github.com/shopspring/decimal"
"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/gtime" "github.com/gogf/gf/v2/os/gtime"
@ -22,6 +19,8 @@ import (
"github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand" "github.com/gogf/gf/v2/util/grand"
"github.com/gogf/gf/v2/util/guid" "github.com/gogf/gf/v2/util/guid"
"github.com/google/uuid"
"github.com/shopspring/decimal"
) )
const ( const (

View File

@ -20,13 +20,12 @@ import (
"strings" "strings"
_ "github.com/denisenkom/go-mssqldb" _ "github.com/denisenkom/go-mssqldb"
"github.com/gogf/gf/v2/util/gutil"
"github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/errors/gerror"
"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/v2/util/gutil"
) )
// Driver is the driver for SQL server database. // Driver is the driver for SQL server database.

View File

@ -9,6 +9,9 @@ package mssql_test
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"testing"
"time"
"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/database/gdb" "github.com/gogf/gf/v2/database/gdb"
@ -17,8 +20,6 @@ import (
"github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/guid" "github.com/gogf/gf/v2/util/guid"
"github.com/gogf/gf/v2/util/gutil" "github.com/gogf/gf/v2/util/gutil"
"testing"
"time"
) )
func TestPage(t *testing.T) { func TestPage(t *testing.T) {

View File

@ -14,13 +14,12 @@ import (
"net/url" "net/url"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gutil"
"github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/text/gregex" "github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/util/gutil"
) )
// Driver is the driver for mysql database. // Driver is the driver for mysql database.

View File

@ -11,7 +11,6 @@ import (
"testing" "testing"
"github.com/go-sql-driver/mysql" "github.com/go-sql-driver/mysql"
"github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/test/gtest" "github.com/gogf/gf/v2/test/gtest"
) )

View File

@ -0,0 +1,100 @@
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package mysql_test
import (
"fmt"
"testing"
"github.com/gogf/gf/v2/container/garray"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/guid"
)
func Test_Master_Slave(t *testing.T) {
var err error
gtest.C(t, func(t *gtest.T) {
_, err = db.Exec(ctx, "CREATE DATABASE IF NOT EXISTS `master` CHARACTER SET UTF8")
t.AssertNil(err)
_, err = db.Exec(ctx, "CREATE DATABASE IF NOT EXISTS `slave` CHARACTER SET UTF8")
t.AssertNil(err)
})
defer func() {
_, _ = db.Exec(ctx, "DROP DATABASE `master`")
_, _ = db.Exec(ctx, "DROP DATABASE `slave`")
}()
var (
configKey = guid.S()
configGroup = gdb.ConfigGroup{
gdb.ConfigNode{
Host: "127.0.0.1",
Port: "3306",
User: "root",
Pass: "12345678",
Name: "master",
Type: "mysql",
Role: "master",
Debug: true,
Weight: 100,
},
gdb.ConfigNode{
Host: "127.0.0.1",
Port: "3306",
User: "root",
Pass: "12345678",
Name: "slave",
Type: "mysql",
Role: "slave",
Debug: true,
Weight: 100,
},
}
)
gdb.SetConfigGroup(configKey, configGroup)
masterSlaveDB := g.DB(configKey)
gtest.C(t, func(t *gtest.T) {
table := "table_" + guid.S()
createTableWithDb(masterSlaveDB.Schema("master"), table)
createTableWithDb(masterSlaveDB.Schema("slave"), table)
defer dropTableWithDb(masterSlaveDB.Schema("master"), table)
defer dropTableWithDb(masterSlaveDB.Schema("slave"), table)
// Data insert to master.
array := garray.New(true)
for i := 1; i <= TableSize; i++ {
array.Append(g.Map{
"id": i,
"passport": fmt.Sprintf(`user_%d`, i),
"password": fmt.Sprintf(`pass_%d`, i),
"nickname": fmt.Sprintf(`name_%d`, i),
"create_time": gtime.NewFromStr(CreateTime).String(),
})
}
_, err = masterSlaveDB.Model(table).Data(array).Insert()
t.AssertNil(err)
var count int
// Auto slave.
count, err = masterSlaveDB.Model(table).Count()
t.AssertNil(err)
t.Assert(count, 0)
// slave.
count, err = masterSlaveDB.Model(table).Slave().Count()
t.AssertNil(err)
t.Assert(count, 0)
// master.
count, err = masterSlaveDB.Model(table).Master().Count()
t.AssertNil(err)
t.Assert(count, TableSize)
})
}

View File

@ -220,11 +220,12 @@ func (d *Driver) TableFields(
useSchema = gutil.GetOrDefaultStr(d.GetSchema(), schema...) useSchema = gutil.GetOrDefaultStr(d.GetSchema(), schema...)
structureSql = fmt.Sprintf(` structureSql = fmt.Sprintf(`
SELECT SELECT
COLUMN_NAME AS FIELD, COLUMN_NAME AS FIELD,
CASE DATA_TYPE CASE
WHEN 'NUMBER' THEN DATA_TYPE||'('||DATA_PRECISION||','||DATA_SCALE||')' WHEN (DATA_TYPE='NUMBER' AND NVL(DATA_SCALE,0)=0) THEN 'INT'||'('||DATA_PRECISION||','||DATA_SCALE||')'
WHEN 'FLOAT' THEN DATA_TYPE||'('||DATA_PRECISION||','||DATA_SCALE||')' WHEN (DATA_TYPE='NUMBER' AND NVL(DATA_SCALE,0)>0) THEN 'FLOAT'||'('||DATA_PRECISION||','||DATA_SCALE||')'
ELSE DATA_TYPE||'('||DATA_LENGTH||')' END AS TYPE,NULLABLE WHEN DATA_TYPE='FLOAT' THEN DATA_TYPE||'('||DATA_PRECISION||','||DATA_SCALE||')'
ELSE DATA_TYPE||'('||DATA_LENGTH||')' END AS TYPE,NULLABLE
FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '%s' ORDER BY COLUMN_ID`, FROM USER_TAB_COLUMNS WHERE TABLE_NAME = '%s' ORDER BY COLUMN_ID`,
strings.ToUpper(table), strings.ToUpper(table),
) )

View File

@ -119,6 +119,7 @@ func createTable(table ...string) (name string) {
PASSWORD CHAR(32) NOT NULL, PASSWORD CHAR(32) NOT NULL,
NICKNAME VARCHAR(45) NOT NULL, NICKNAME VARCHAR(45) NOT NULL,
CREATE_TIME varchar(45), CREATE_TIME varchar(45),
SALARY NUMBER(18,2),
PRIMARY KEY (ID)) PRIMARY KEY (ID))
`, name)); err != nil { `, name)); err != nil {
gtest.Fatal(err) gtest.Fatal(err)
@ -158,7 +159,7 @@ func dropTable(table string) {
if count == 0 { if count == 0 {
return return
} }
if _, err := db.Exec(ctx, fmt.Sprintf("DROP TABLE %s", table)); err != nil { if _, err = db.Exec(ctx, fmt.Sprintf("DROP TABLE %s", table)); err != nil {
gtest.Fatal(err) gtest.Fatal(err)
} }
} }

View File

@ -8,6 +8,7 @@ package oracle_test
import ( import (
"fmt" "fmt"
"github.com/gogf/gf/v2/util/gconv"
"strings" "strings"
"testing" "testing"
@ -62,10 +63,11 @@ func TestTableFields(t *testing.T) {
createTable("t_user") createTable("t_user")
defer dropTable("t_user") defer dropTable("t_user")
var expect = map[string][]interface{}{ var expect = map[string][]interface{}{
"ID": {"NUMBER(10,0)", false}, "ID": {"INT(10,0)", false},
"PASSPORT": {"VARCHAR2(45)", false}, "PASSPORT": {"VARCHAR2(45)", false},
"PASSWORD": {"CHAR(32)", false}, "PASSWORD": {"CHAR(32)", false},
"NICKNAME": {"VARCHAR2(45)", false}, "NICKNAME": {"VARCHAR2(45)", false},
"SALARY": {"FLOAT(18,2)", true},
"CREATE_TIME": {"VARCHAR2(45)", true}, "CREATE_TIME": {"VARCHAR2(45)", true},
} }
@ -114,6 +116,7 @@ func TestDoInsert(t *testing.T) {
"PASSPORT": fmt.Sprintf(`t%d`, i), "PASSPORT": fmt.Sprintf(`t%d`, i),
"PASSWORD": fmt.Sprintf(`p%d`, i), "PASSWORD": fmt.Sprintf(`p%d`, i),
"NICKNAME": fmt.Sprintf(`T%d`, i), "NICKNAME": fmt.Sprintf(`T%d`, i),
"SALARY": gconv.Float64(i * 500),
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
} }
_, err := db.Insert(ctx, "t_user", data) _, err := db.Insert(ctx, "t_user", data)
@ -131,6 +134,7 @@ func TestDoInsert(t *testing.T) {
"PASSPORT": fmt.Sprintf(`t%d`, i), "PASSPORT": fmt.Sprintf(`t%d`, i),
"PASSWORD": fmt.Sprintf(`p%d`, i), "PASSWORD": fmt.Sprintf(`p%d`, i),
"NICKNAME": fmt.Sprintf(`T%d`, i), "NICKNAME": fmt.Sprintf(`T%d`, i),
"SALARY": gconv.Float64(i * 450),
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
} }
_, err := db.Save(ctx, "t_user", data, 10) _, err := db.Save(ctx, "t_user", data, 10)
@ -186,6 +190,7 @@ func Test_DB_Insert(t *testing.T) {
"PASSPORT": "t1", "PASSPORT": "t1",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "T1", "NICKNAME": "T1",
"SALARY": 2551.15,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}) })
t.AssertNil(err) t.AssertNil(err)
@ -196,6 +201,7 @@ func Test_DB_Insert(t *testing.T) {
"PASSPORT": "t2", "PASSPORT": "t2",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "name_2", "NICKNAME": "name_2",
"SALARY": "2552.25",
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}) })
t.AssertNil(err) t.AssertNil(err)
@ -204,11 +210,12 @@ func Test_DB_Insert(t *testing.T) {
// struct // struct
type User struct { type User struct {
Id int `gconv:"ID"` Id int `gconv:"ID"`
Passport string `json:"PASSPORT"` Passport string `json:"PASSPORT"`
Password string `gconv:"PASSWORD"` Password string `gconv:"PASSWORD"`
Nickname string `gconv:"NICKNAME"` Nickname string `gconv:"NICKNAME"`
CreateTime string `json:"CREATE_TIME"` Salary float64 `gconv:"SALARY"`
CreateTime string `json:"CREATE_TIME"`
} }
timeStr := gtime.Now().String() timeStr := gtime.Now().String()
result, err = db.Insert(ctx, table, User{ result, err = db.Insert(ctx, table, User{
@ -216,6 +223,7 @@ func Test_DB_Insert(t *testing.T) {
Passport: "user_3", Passport: "user_3",
Password: "25d55ad283aa400af464c76d713c07ad", Password: "25d55ad283aa400af464c76d713c07ad",
Nickname: "name_3", Nickname: "name_3",
Salary: 2553.35,
CreateTime: timeStr, CreateTime: timeStr,
}) })
t.AssertNil(err) t.AssertNil(err)
@ -229,6 +237,7 @@ func Test_DB_Insert(t *testing.T) {
t.Assert(one["PASSPORT"].String(), "user_3") t.Assert(one["PASSPORT"].String(), "user_3")
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d713c07ad") t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d713c07ad")
t.Assert(one["NICKNAME"].String(), "name_3") t.Assert(one["NICKNAME"].String(), "name_3")
t.Assert(one["SALARY"].Float64(), 2553.35)
t.Assert(one["CREATE_TIME"].GTime().String(), timeStr) t.Assert(one["CREATE_TIME"].GTime().String(), timeStr)
// *struct // *struct
@ -238,6 +247,7 @@ func Test_DB_Insert(t *testing.T) {
Passport: "t4", Passport: "t4",
Password: "25d55ad283aa400af464c76d713c07ad", Password: "25d55ad283aa400af464c76d713c07ad",
Nickname: "name_4", Nickname: "name_4",
Salary: 2554.35,
CreateTime: timeStr, CreateTime: timeStr,
}) })
t.AssertNil(err) t.AssertNil(err)
@ -250,6 +260,7 @@ func Test_DB_Insert(t *testing.T) {
t.Assert(one["PASSPORT"].String(), "t4") t.Assert(one["PASSPORT"].String(), "t4")
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d713c07ad") t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d713c07ad")
t.Assert(one["NICKNAME"].String(), "name_4") t.Assert(one["NICKNAME"].String(), "name_4")
t.Assert(one["SALARY"].Float64(), 2554.35)
t.Assert(one["CREATE_TIME"].GTime().String(), timeStr) t.Assert(one["CREATE_TIME"].GTime().String(), timeStr)
// batch with Insert // batch with Insert
@ -260,6 +271,7 @@ func Test_DB_Insert(t *testing.T) {
"PASSPORT": "t200", "PASSPORT": "t200",
"PASSWORD": "25d55ad283aa400af464c76d71qw07ad", "PASSWORD": "25d55ad283aa400af464c76d71qw07ad",
"NICKNAME": "T200", "NICKNAME": "T200",
"SALARY": 2556.35,
"CREATE_TIME": timeStr, "CREATE_TIME": timeStr,
}, },
g.Map{ g.Map{
@ -267,6 +279,7 @@ func Test_DB_Insert(t *testing.T) {
"PASSPORT": "t300", "PASSPORT": "t300",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "T300", "NICKNAME": "T300",
"SALARY": 2557.35,
"CREATE_TIME": timeStr, "CREATE_TIME": timeStr,
}, },
}) })
@ -280,6 +293,7 @@ func Test_DB_Insert(t *testing.T) {
t.Assert(one["PASSPORT"].String(), "t200") t.Assert(one["PASSPORT"].String(), "t200")
t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d71qw07ad") t.Assert(one["PASSWORD"].String(), "25d55ad283aa400af464c76d71qw07ad")
t.Assert(one["NICKNAME"].String(), "T200") t.Assert(one["NICKNAME"].String(), "T200")
t.Assert(one["SALARY"].Float64(), 2556.35)
t.Assert(one["CREATE_TIME"].GTime().String(), timeStr) t.Assert(one["CREATE_TIME"].GTime().String(), timeStr)
}) })
} }
@ -294,6 +308,7 @@ func Test_DB_BatchInsert(t *testing.T) {
"PASSPORT": "t2", "PASSPORT": "t2",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "name_2", "NICKNAME": "name_2",
"SALARY": 2652.35,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}, },
{ {
@ -301,6 +316,7 @@ func Test_DB_BatchInsert(t *testing.T) {
"PASSPORT": "user_3", "PASSPORT": "user_3",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "name_3", "NICKNAME": "name_3",
"SALARY": 2653.35,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}, },
}, 1) }, 1)
@ -320,6 +336,7 @@ func Test_DB_BatchInsert(t *testing.T) {
"PASSPORT": "t2", "PASSPORT": "t2",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "name_2", "NICKNAME": "name_2",
"SALARY": 2652.35,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}, },
g.Map{ g.Map{
@ -327,6 +344,7 @@ func Test_DB_BatchInsert(t *testing.T) {
"PASSPORT": "user_3", "PASSPORT": "user_3",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "name_3", "NICKNAME": "name_3",
"SALARY": 2653.35,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}, },
}, 1) }, 1)
@ -344,6 +362,7 @@ func Test_DB_BatchInsert(t *testing.T) {
"PASSPORT": "t1", "PASSPORT": "t1",
"PASSWORD": "p1", "PASSWORD": "p1",
"NICKNAME": "T1", "NICKNAME": "T1",
"SALARY": 2765.35,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}) })
t.AssertNil(err) t.AssertNil(err)
@ -363,6 +382,7 @@ func Test_DB_BatchInsert_Struct(t *testing.T) {
Passport string `c:"PASSPORT"` Passport string `c:"PASSPORT"`
Password string `c:"PASSWORD"` Password string `c:"PASSWORD"`
NickName string `c:"NICKNAME"` NickName string `c:"NICKNAME"`
Salary float64 `c:"SALARY"`
CreateTime *gtime.Time `c:"CREATE_TIME"` CreateTime *gtime.Time `c:"CREATE_TIME"`
} }
user := &User{ user := &User{
@ -370,6 +390,7 @@ func Test_DB_BatchInsert_Struct(t *testing.T) {
Passport: "t1", Passport: "t1",
Password: "p1", Password: "p1",
NickName: "T1", NickName: "T1",
Salary: 2761.35,
CreateTime: gtime.Now(), CreateTime: gtime.Now(),
} }
result, err := db.Insert(ctx, table, user) result, err := db.Insert(ctx, table, user)
@ -386,6 +407,9 @@ func Test_DB_Update(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
result, err := db.Update(ctx, table, "password='987654321'", "id=3") result, err := db.Update(ctx, table, "password='987654321'", "id=3")
t.AssertNil(err) t.AssertNil(err)
result, err = db.Update(ctx, table, "salary=2675.13", "id=3")
t.AssertNil(err)
n, _ := result.RowsAffected() n, _ := result.RowsAffected()
t.Assert(n, 1) t.Assert(n, 1)
@ -395,6 +419,7 @@ func Test_DB_Update(t *testing.T) {
t.Assert(one["PASSPORT"].String(), "user_3") t.Assert(one["PASSPORT"].String(), "user_3")
t.Assert(strings.TrimSpace(one["PASSWORD"].String()), "987654321") t.Assert(strings.TrimSpace(one["PASSWORD"].String()), "987654321")
t.Assert(one["NICKNAME"].String(), "name_3") t.Assert(one["NICKNAME"].String(), "name_3")
t.Assert(one["SALARY"].String(), "2675.13")
}) })
} }
@ -487,6 +512,7 @@ func Test_DB_GetStruct(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime gtime.Time CreateTime gtime.Time
} }
user := new(User) user := new(User)
@ -500,6 +526,7 @@ func Test_DB_GetStruct(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
user := new(User) user := new(User)
@ -518,6 +545,7 @@ func Test_DB_GetStructs(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime gtime.Time CreateTime gtime.Time
} }
var users []User var users []User
@ -538,6 +566,7 @@ func Test_DB_GetStructs(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
var users []User var users []User
@ -562,6 +591,7 @@ func Test_DB_GetScan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime gtime.Time CreateTime gtime.Time
} }
user := new(User) user := new(User)
@ -575,6 +605,7 @@ func Test_DB_GetScan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime gtime.Time CreateTime gtime.Time
} }
var user *User var user *User
@ -588,6 +619,7 @@ func Test_DB_GetScan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
user := new(User) user := new(User)
@ -602,6 +634,7 @@ func Test_DB_GetScan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime gtime.Time CreateTime gtime.Time
} }
var users []User var users []User
@ -622,6 +655,7 @@ func Test_DB_GetScan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
var users []User var users []User

View File

@ -171,6 +171,7 @@ func Test_Model_Insert(t *testing.T) {
"PASSPORT": "t1", "PASSPORT": "t1",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "name_1", "NICKNAME": "name_1",
"SALARY": 2675.11,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}).Insert() }).Insert()
t.AssertNil(err) t.AssertNil(err)
@ -181,6 +182,7 @@ func Test_Model_Insert(t *testing.T) {
"PASSPORT": "t2", "PASSPORT": "t2",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "name_2", "NICKNAME": "name_2",
"SALARY": 2675.12,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}).Insert() }).Insert()
t.AssertNil(err) t.AssertNil(err)
@ -191,6 +193,7 @@ func Test_Model_Insert(t *testing.T) {
Passport string `json:"PASSPORT"` Passport string `json:"PASSPORT"`
Password string `gconv:"PASSWORD"` Password string `gconv:"PASSWORD"`
Nickname string `gconv:"NICKNAME"` Nickname string `gconv:"NICKNAME"`
Salary float64 `gconv:"SALARY"`
CreateTime *gtime.Time `json:"CREATE_TIME"` CreateTime *gtime.Time `json:"CREATE_TIME"`
} }
// Model inserting. // Model inserting.
@ -200,6 +203,7 @@ func Test_Model_Insert(t *testing.T) {
Passport: "t3", Passport: "t3",
Password: "25d55ad283aa400af464c76d713c07ad", Password: "25d55ad283aa400af464c76d713c07ad",
Nickname: "name_3", Nickname: "name_3",
Salary: 2675.13,
CreateTime: gtime.Now(), CreateTime: gtime.Now(),
}).Insert() }).Insert()
t.AssertNil(err) t.AssertNil(err)
@ -214,6 +218,7 @@ func Test_Model_Insert(t *testing.T) {
Passport: "t4", Passport: "t4",
Password: "25d55ad283aa400af464c76d713c07ad", Password: "25d55ad283aa400af464c76d713c07ad",
Nickname: "T4", Nickname: "T4",
Salary: 2675.14,
CreateTime: gtime.Now(), CreateTime: gtime.Now(),
}).Insert() }).Insert()
t.AssertNil(err) t.AssertNil(err)
@ -238,6 +243,7 @@ func Test_Model_Insert_Time(t *testing.T) {
"PASSPORT": "t1", "PASSPORT": "t1",
"PASSWORD": "p1", "PASSWORD": "p1",
"NICKNAME": "n1", "NICKNAME": "n1",
"SALARY": 2675.11,
"CREATE_TIME": "2020-10-10 20:09:18", "CREATE_TIME": "2020-10-10 20:09:18",
} }
_, err := db.Model(table).Data(data).Insert() _, err := db.Model(table).Data(data).Insert()
@ -248,6 +254,7 @@ func Test_Model_Insert_Time(t *testing.T) {
t.Assert(one["PASSPORT"].String(), data["PASSPORT"]) t.Assert(one["PASSPORT"].String(), data["PASSPORT"])
t.Assert(one["CREATE_TIME"].String(), "2020-10-10 20:09:18") t.Assert(one["CREATE_TIME"].String(), "2020-10-10 20:09:18")
t.Assert(one["NICKNAME"].String(), data["NICKNAME"]) t.Assert(one["NICKNAME"].String(), data["NICKNAME"])
t.Assert(one["SALARY"].Float64(), data["SALARY"])
}) })
} }
@ -263,6 +270,7 @@ func Test_Model_Batch(t *testing.T) {
"PASSPORT": "t2", "PASSPORT": "t2",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "name_2", "NICKNAME": "name_2",
"SALARY": 2675.12,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}, },
{ {
@ -271,6 +279,7 @@ func Test_Model_Batch(t *testing.T) {
"PASSPORT": "t3", "PASSPORT": "t3",
"PASSWORD": "25d55ad283aa400af464c76d713c07ad", "PASSWORD": "25d55ad283aa400af464c76d713c07ad",
"NICKNAME": "name_3", "NICKNAME": "name_3",
"SALARY": 2675.13,
"CREATE_TIME": gtime.Now().String(), "CREATE_TIME": gtime.Now().String(),
}, },
}).Batch(1).Insert() }).Batch(1).Insert()
@ -439,6 +448,7 @@ func Test_Model_Select(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime gtime.Time CreateTime gtime.Time
} }
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -458,6 +468,7 @@ func Test_Model_Struct(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime gtime.Time CreateTime gtime.Time
} }
user := new(User) user := new(User)
@ -471,6 +482,7 @@ func Test_Model_Struct(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
user := new(User) user := new(User)
@ -485,6 +497,7 @@ func Test_Model_Struct(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
user := (*User)(nil) user := (*User)(nil)
@ -499,6 +512,7 @@ func Test_Model_Struct(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
user := (*User)(nil) user := (*User)(nil)
@ -515,6 +529,7 @@ func Test_Model_Struct(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
user := new(User) user := new(User)
@ -527,6 +542,7 @@ func Test_Model_Struct(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
var user *User var user *User
@ -545,6 +561,7 @@ func Test_Model_Scan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime gtime.Time CreateTime gtime.Time
} }
user := new(User) user := new(User)
@ -558,6 +575,7 @@ func Test_Model_Scan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
user := new(User) user := new(User)
@ -571,6 +589,7 @@ func Test_Model_Scan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime gtime.Time CreateTime gtime.Time
} }
var users []User var users []User
@ -590,6 +609,7 @@ func Test_Model_Scan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
var users []*User var users []*User
@ -610,6 +630,7 @@ func Test_Model_Scan(t *testing.T) {
Passport string Passport string
Password string Password string
NickName string NickName string
Salary float64
CreateTime *gtime.Time CreateTime *gtime.Time
} }
var ( var (

View File

@ -17,8 +17,6 @@ import (
"fmt" "fmt"
"strings" "strings"
_ "github.com/lib/pq"
"github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gcode" "github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/errors/gerror"
@ -27,6 +25,7 @@ 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/gutil" "github.com/gogf/gf/v2/util/gutil"
_ "github.com/lib/pq"
) )
// Driver is the driver for postgresql database. // Driver is the driver for postgresql database.
@ -36,6 +35,7 @@ type Driver struct {
const ( const (
internalPrimaryKeyInCtx gctx.StrKey = "primary_key" internalPrimaryKeyInCtx gctx.StrKey = "primary_key"
defaultSchema = "public"
) )
func init() { func init() {
@ -223,9 +223,18 @@ func (d *Driver) DoFilter(ctx context.Context, link gdb.Link, sql string, args [
// It's mainly used in cli tool chain for automatically generating the models. // It's mainly used in cli tool chain for automatically generating the models.
func (d *Driver) Tables(ctx context.Context, schema ...string) (tables []string, err error) { func (d *Driver) Tables(ctx context.Context, schema ...string) (tables []string, err error) {
var ( var (
result gdb.Result result gdb.Result
querySchema = gutil.GetOrDefaultStr("public", schema...) usedSchema = gutil.GetOrDefaultStr(d.GetConfig().Namespace, schema...)
query = fmt.Sprintf(` )
if usedSchema == "" {
usedSchema = defaultSchema
}
// DO NOT use `usedSchema` as parameter for function `SlaveLink`.
link, err := d.SlaveLink(schema...)
if err != nil {
return nil, err
}
var query = fmt.Sprintf(`
SELECT SELECT
c.relname c.relname
FROM FROM
@ -236,16 +245,11 @@ WHERE
n.nspname = '%s' n.nspname = '%s'
AND c.relkind IN ('r', 'p') AND c.relkind IN ('r', 'p')
AND c.relpartbound IS NULL AND c.relpartbound IS NULL
AND PG_TABLE_IS_VISIBLE(c.oid)
ORDER BY ORDER BY
c.relname`, c.relname`,
querySchema, usedSchema,
)
) )
link, err := d.SlaveLink(schema...)
if err != nil {
return nil, err
}
query, _ = gregex.ReplaceString(`[\n\r\s]+`, " ", gstr.Trim(query)) query, _ = gregex.ReplaceString(`[\n\r\s]+`, " ", gstr.Trim(query))
result, err = d.DoSelect(ctx, link, query) result, err = d.DoSelect(ctx, link, query)
if err != nil { if err != nil {

View File

@ -277,14 +277,11 @@ func Test_DB_Delete(t *testing.T) {
func Test_DB_Tables(t *testing.T) { func Test_DB_Tables(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
tables := []string{"t_user1", "pop", "haha"} tables := []string{"t_user1", "pop", "haha"}
for _, v := range tables { for _, v := range tables {
createTable(v) createTable(v)
} }
result, err := db.Tables(ctx) result, err := db.Tables(ctx)
gtest.Assert(err, nil) gtest.Assert(err, nil)
for i := 0; i < len(tables); i++ { for i := 0; i < len(tables); i++ {
find := false find := false
for j := 0; j < len(result); j++ { for j := 0; j < len(result); j++ {

View File

@ -7,11 +7,11 @@
package pgsql_test package pgsql_test
import ( import (
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
"context" "context"
"fmt" "fmt"
_ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
"github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/container/garray"
"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"

Some files were not shown because too many files have changed in this diff Show More