mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 20:28:17 +08:00
Merge pull request #1483 from houseme/master
improve code 'if block ends with a return statement, so drop this els…
This commit is contained in:
commit
9b93542e99
@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
)
|
||||
|
||||
@ -15,13 +16,13 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer watch.Close()
|
||||
//添加要监控的对象,文件或文件夹
|
||||
//err = watch.Add("D:\\Workspace\\Go\\GOPATH\\src\\gitee.com\\johng\\gf\\geg\\other\\test.go")
|
||||
// 添加要监控的对象,文件或文件夹
|
||||
// err = watch.Add("D:\\Workspace\\Go\\GOPATH\\src\\gitee.com\\johng\\gf\\geg\\other\\test.go")
|
||||
err = watch.Add("/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/other/test.go")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
//我们另启一个goroutine来处理监控对象的事件
|
||||
// 我们另启一个goroutine来处理监控对象的事件
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
@ -36,6 +37,6 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
//循环
|
||||
// 循环
|
||||
select {}
|
||||
}
|
||||
|
950
.golangci.yml
Normal file
950
.golangci.yml
Normal file
@ -0,0 +1,950 @@
|
||||
# This file contains all available configuration options
|
||||
# with their default values.
|
||||
|
||||
# options for analysis running
|
||||
run:
|
||||
# default concurrency is a available CPU number
|
||||
concurrency: 4
|
||||
|
||||
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
||||
timeout: 5m
|
||||
|
||||
# exit code when at least one issue was found, default is 1
|
||||
issues-exit-code: 1
|
||||
|
||||
# include test files or not, default is true
|
||||
tests: true
|
||||
|
||||
# list of build tags, all linters use it. Default is empty list.
|
||||
build-tags:
|
||||
- mytag
|
||||
|
||||
# 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
|
||||
# from 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:
|
||||
- packed
|
||||
- documentation
|
||||
- docker
|
||||
|
||||
# default is true. Enables skipping of directories:
|
||||
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
|
||||
skip-dirs-use-default: true
|
||||
|
||||
# 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:
|
||||
- ".*\\.my\\.go$"
|
||||
- lib/bad.go
|
||||
|
||||
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
|
||||
# If invoked with -mod=readonly, the go command is disallowed from the implicit
|
||||
# automatic updating of go.mod described above. Instead, it fails when any changes
|
||||
# to go.mod are needed. This setting is most useful to check that go.mod does
|
||||
# not need updates, such as in a continuous integration and testing system.
|
||||
# If invoked with -mod=vendor, the go command assumes that the vendor
|
||||
# directory holds the correct copies of dependencies and ignores
|
||||
# the dependency descriptions in go.mod.
|
||||
#modules-download-mode: release|readonly|vendor
|
||||
|
||||
# Allow multiple parallel golangci-lint instances running.
|
||||
# If false (default) - golangci-lint acquires file lock on start.
|
||||
allow-parallel-runners: true
|
||||
|
||||
|
||||
# output configuration options
|
||||
output:
|
||||
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
|
||||
# default is "colored-line-number"
|
||||
format: colored-line-number
|
||||
|
||||
# print lines of code with issue, default is true
|
||||
print-issued-lines: true
|
||||
|
||||
# print linter name in the end of issue text, default is true
|
||||
print-linter-name: true
|
||||
|
||||
# make issues output unique by line, default is true
|
||||
uniq-by-line: true
|
||||
|
||||
# add a prefix to the output file references; default is no prefix
|
||||
path-prefix: ""
|
||||
|
||||
# sorts results by: filepath, line and column
|
||||
sort-results: true
|
||||
|
||||
|
||||
# all available settings of specific linters
|
||||
linters-settings:
|
||||
bidichk:
|
||||
# The following configurations check for all mentioned invisible unicode
|
||||
# runes. It can be omitted because all runes are enabled by default.
|
||||
left-to-right-embedding: true
|
||||
right-to-left-embedding: true
|
||||
pop-directional-formatting: true
|
||||
left-to-right-override: true
|
||||
right-to-left-override: true
|
||||
left-to-right-isolate: true
|
||||
right-to-left-isolate: true
|
||||
first-strong-isolate: true
|
||||
pop-directional-isolate: true
|
||||
|
||||
cyclop:
|
||||
# the maximal code complexity to report
|
||||
max-complexity: 50
|
||||
# the maximal average package complexity. If it's higher than 0.0 (float) the check is enabled (default 0.0)
|
||||
package-average: 0.0
|
||||
# should ignore tests (default false)
|
||||
skip-tests: false
|
||||
|
||||
dogsled:
|
||||
# checks assignments with too many blank identifiers; default is 2
|
||||
max-blank-identifiers: 2
|
||||
|
||||
dupl:
|
||||
# tokens count to trigger issue, 150 by default
|
||||
threshold: 100
|
||||
|
||||
errcheck:
|
||||
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
check-type-assertions: false
|
||||
|
||||
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
|
||||
# default is false: such cases aren't reported by default.
|
||||
check-blank: false
|
||||
|
||||
# [deprecated] comma-separated list of pairs of the form pkg:regex
|
||||
# the regex is used to ignore names within pkg. (default "fmt:.*").
|
||||
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
|
||||
#ignore: fmt:.*,io/ioutil:^Read.*
|
||||
|
||||
# [deprecated] use exclude-functions instead.
|
||||
# path to a file containing a list of functions to exclude from checking
|
||||
# see https://github.com/kisielk/errcheck#excluding-functions for details
|
||||
# exclude: /path/to/file.txt
|
||||
|
||||
# list of functions to exclude from checking, where each entry is a single function to exclude.
|
||||
# see https://github.com/kisielk/errcheck#excluding-functions for details
|
||||
exclude-functions:
|
||||
- io/ioutil.ReadFile
|
||||
- io.Copy(*bytes.Buffer)
|
||||
- io.Copy(os.Stdout)
|
||||
|
||||
errorlint:
|
||||
# Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats
|
||||
errorf: true
|
||||
# Check for plain type assertions and type switches
|
||||
asserts: true
|
||||
# Check for plain error comparisons
|
||||
comparison: true
|
||||
|
||||
exhaustive:
|
||||
# check switch statements in generated files also
|
||||
check-generated: false
|
||||
# presence of "default" case in switch statements satisfies exhaustiveness,
|
||||
# even if all enum members are not listed
|
||||
default-signifies-exhaustive: false
|
||||
# enum members matching the supplied regex do not have to be listed in
|
||||
# switch statements to satisfy exhaustiveness
|
||||
ignore-enum-members: ""
|
||||
# consider enums only in package scopes, not in inner scopes
|
||||
package-scope-only: false
|
||||
|
||||
exhaustivestruct:
|
||||
# Struct Patterns is list of expressions to match struct packages and names
|
||||
# The struct packages have the form example.com/package.ExampleStruct
|
||||
# The matching patterns can use matching syntax from https://pkg.go.dev/path#Match
|
||||
# If this list is empty, all structs are tested.
|
||||
struct-patterns:
|
||||
- '*.Test'
|
||||
- 'example.com/package.ExampleStruct'
|
||||
- '*.Test2'
|
||||
- '*.Embedded'
|
||||
- '*.External'
|
||||
|
||||
forbidigo:
|
||||
# Forbid the following identifiers (identifiers are written using regexp):
|
||||
forbid:
|
||||
- ^print.*$
|
||||
- 'fmt\.Print.*'
|
||||
- fmt.Println.* # too much log noise
|
||||
- ginkgo\\.F.* # these are used just for local development
|
||||
# Exclude godoc examples from forbidigo checks. Default is true.
|
||||
exclude_godoc_examples: false
|
||||
|
||||
funlen:
|
||||
lines: 150
|
||||
statements: 50
|
||||
|
||||
gci:
|
||||
# put imports beginning with prefix after 3rd-party packages;
|
||||
# only support one prefix
|
||||
# if not set, use goimports.local-prefixes
|
||||
local-prefixes: github.com/gogf/gf
|
||||
|
||||
gocognit:
|
||||
# minimal code complexity to report, 30 by default (but we recommend 10-20)
|
||||
min-complexity: 50
|
||||
|
||||
goconst:
|
||||
# minimal length of string constant, 3 by default
|
||||
min-len: 3
|
||||
# minimum occurrences of constant string count to trigger issue, 3 by default
|
||||
min-occurrences: 3
|
||||
# ignore test files, false by default
|
||||
ignore-tests: false
|
||||
# look for existing constants matching the values, true by default
|
||||
match-constant: true
|
||||
# search also for duplicated numbers, false by default
|
||||
numbers: false
|
||||
# minimum value, only works with goconst.numbers, 3 by default
|
||||
min: 3
|
||||
# maximum value, only works with goconst.numbers, 3 by default
|
||||
max: 3
|
||||
# ignore when constant is not used as function argument, true by default
|
||||
ignore-calls: true
|
||||
|
||||
gocritic:
|
||||
# Which checks should be enabled; can't be combined with 'disabled-checks';
|
||||
# See https://go-critic.github.io/overview#checks-overview
|
||||
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
|
||||
# By default list of stable checks is used.
|
||||
enabled-checks:
|
||||
- nestingReduce
|
||||
- unnamedresult
|
||||
- ruleguard
|
||||
- truncateCmp
|
||||
|
||||
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
|
||||
disabled-checks:
|
||||
- regexpMust
|
||||
- ifElseChain
|
||||
- exitAfterDefer
|
||||
|
||||
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
|
||||
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
|
||||
enabled-tags:
|
||||
- performance
|
||||
disabled-tags:
|
||||
- experimental
|
||||
|
||||
# Settings passed to gocritic.
|
||||
# The settings key is the name of a supported gocritic checker.
|
||||
# The list of supported checkers can be find in https://go-critic.github.io/overview.
|
||||
settings:
|
||||
captLocal: # must be valid enabled check name
|
||||
# whether to restrict checker to params only (default true)
|
||||
paramsOnly: true
|
||||
elseif:
|
||||
# whether to skip balanced if-else pairs (default true)
|
||||
skipBalanced: true
|
||||
hugeParam:
|
||||
# size in bytes that makes the warning trigger (default 80)
|
||||
sizeThreshold: 80
|
||||
nestingReduce:
|
||||
# min number of statements inside a branch to trigger a warning (default 5)
|
||||
bodyWidth: 5
|
||||
rangeExprCopy:
|
||||
# size in bytes that makes the warning trigger (default 512)
|
||||
sizeThreshold: 512
|
||||
# whether to check test functions (default true)
|
||||
skipTestFuncs: true
|
||||
rangeValCopy:
|
||||
# size in bytes that makes the warning trigger (default 128)
|
||||
sizeThreshold: 32
|
||||
# whether to check test functions (default true)
|
||||
skipTestFuncs: true
|
||||
ruleguard:
|
||||
# Enable debug to identify which 'Where' condition was rejected.
|
||||
# The value of the parameter is the name of a function in a ruleguard file.
|
||||
#
|
||||
# When a rule is evaluated:
|
||||
# If:
|
||||
# The Match() clause is accepted; and
|
||||
# One of the conditions in the Where() clause is rejected,
|
||||
# Then:
|
||||
# ruleguard prints the specific Where() condition that was rejected.
|
||||
#
|
||||
# The flag is passed to the ruleguard 'debug-group' argument.
|
||||
debug: 'emptyDecl'
|
||||
# Deprecated, use 'failOn' param.
|
||||
# If set to true, identical to failOn='all', otherwise failOn=''
|
||||
failOnError: false
|
||||
# Determines the behavior when an error occurs while parsing ruleguard files.
|
||||
# If flag is not set, log error and skip rule files that contain an error.
|
||||
# If flag is set, the value must be a comma-separated list of error conditions.
|
||||
# - 'all': fail on all errors.
|
||||
# - 'import': ruleguard rule imports a package that cannot be found.
|
||||
# - 'dsl': gorule file does not comply with the ruleguard DSL.
|
||||
failOn: dsl
|
||||
# Comma-separated list of file paths containing ruleguard rules.
|
||||
# If a path is relative, it is relative to the directory where the golangci-lint command is executed.
|
||||
# The special '${configDir}' variable is substituted with the absolute directory containing the golangci config file.
|
||||
# Glob patterns such as 'rules-*.go' may be specified.
|
||||
rules: '' #${configDir}/ruleguard/rules-*.go,${configDir}/myrule1.go'
|
||||
#tooManyResultsChecker:
|
||||
# maximum number of results (default 5)
|
||||
#maxResults: 10
|
||||
truncateCmp:
|
||||
# whether to skip int/uint/uintptr types (default true)
|
||||
skipArchDependent: true
|
||||
underef:
|
||||
# whether to skip (*x).method() calls where x is a pointer receiver (default true)
|
||||
skipRecvDeref: true
|
||||
unnamedResult:
|
||||
# whether to check exported functions
|
||||
checkExported: true
|
||||
|
||||
gocyclo:
|
||||
# minimal code complexity to report, 30 by default (but we recommend 10-20)
|
||||
min-complexity: 30
|
||||
|
||||
godot:
|
||||
# comments to be checked: `declarations`, `toplevel`, or `all`
|
||||
scope: declarations
|
||||
# list of regexps for excluding particular comment lines from check
|
||||
exclude:
|
||||
# example: exclude comments which contain numbers
|
||||
# - '[0-9]+'
|
||||
# check that each sentence starts with a capital letter
|
||||
capital: false
|
||||
|
||||
godox:
|
||||
# report any comments starting with keywords, this is useful for TODO or FIXME comments that
|
||||
# might be left in the code accidentally and should be resolved before merging
|
||||
keywords: # default keywords are TODO, BUG, and FIXME, these can be overwritten by this setting
|
||||
#- NOTE
|
||||
- BUG
|
||||
- FIXME
|
||||
- OPTIMIZE # marks code that should be optimized before merging
|
||||
- HACK # marks hack-arounds that should be removed before merging
|
||||
|
||||
gofmt:
|
||||
# simplify code: gofmt with `-s` option, true by default
|
||||
simplify: true
|
||||
|
||||
gofumpt:
|
||||
# Select the Go version to target. The default is `1.15`.
|
||||
lang-version: "1.16"
|
||||
|
||||
# Choose whether or not to use the extra rules that are disabled
|
||||
# by default
|
||||
extra-rules: false
|
||||
|
||||
goheader:
|
||||
values:
|
||||
const:
|
||||
# define here const type values in format k:v, for example:
|
||||
# COMPANY: MY COMPANY
|
||||
regexp:
|
||||
# define here regexp type values, for example
|
||||
# AUTHOR: .*@mycompany\.com
|
||||
template: # |-
|
||||
# put here copyright header template for source code files, for example:
|
||||
# Note: {{ YEAR }} is a builtin value that returns the year relative to the current machine time.
|
||||
#
|
||||
# {{ AUTHOR }} {{ COMPANY }} {{ YEAR }}
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at:
|
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
# 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.
|
||||
template-path:
|
||||
# also as alternative of directive 'template' you may put the path to file with the template source
|
||||
|
||||
goimports:
|
||||
# put imports beginning with prefix after 3rd-party packages;
|
||||
# it's a comma-separated list of prefixes
|
||||
local-prefixes: github.com/gogf/gf
|
||||
|
||||
golint:
|
||||
# minimal confidence for issues, default is 0.8
|
||||
min-confidence: 0.9
|
||||
|
||||
gomnd:
|
||||
settings:
|
||||
mnd:
|
||||
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
|
||||
checks: argument,case,condition,operation,return,assign
|
||||
# ignored-numbers: 1000
|
||||
# ignored-files: magic_.*.go
|
||||
# ignored-functions: math.*
|
||||
|
||||
gomoddirectives:
|
||||
# Allow local `replace` directives. Default is false.
|
||||
replace-local: false
|
||||
# List of allowed `replace` directives. Default is empty.
|
||||
replace-allow-list:
|
||||
- launchpad.net/gocheck
|
||||
- github.com/coreos/etcd
|
||||
- google.golang.org/grpc
|
||||
- gitlab.jntmedia.cn/lanren/core
|
||||
# Allow to not explain why the version has been retracted in the `retract` directives. Default is false.
|
||||
retract-allow-no-explanation: false
|
||||
# Forbid the use of the `exclude` directives. Default is false.
|
||||
exclude-forbidden: false
|
||||
|
||||
gomodguard:
|
||||
allowed:
|
||||
modules: # List of allowed modules
|
||||
# - gopkg.in/yaml.v2
|
||||
- gorm.io/gorm
|
||||
- gorm.io/driver/mysql
|
||||
- k8s.io/klog
|
||||
domains: # List of allowed module domains
|
||||
# - golang.org
|
||||
- google.golang.org
|
||||
- gopkg.in
|
||||
- golang.org
|
||||
- github.com
|
||||
- go.uber.org
|
||||
blocked:
|
||||
modules: # List of blocked modules
|
||||
# - github.com/uudashr/go-module: # Blocked module
|
||||
# recommendations: # Recommended modules that should be used instead (Optional)
|
||||
# - golang.org/x/mod
|
||||
# reason: "`mod` is the official go.mod parser library." # Reason why the recommended module should be used (Optional)
|
||||
versions: # List of blocked module version constraints
|
||||
# - github.com/mitchellh/go-homedir: # Blocked module with version constraint
|
||||
# version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
|
||||
# reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional)
|
||||
local_replace_directives: false # Set to true to raise lint issues for packages that are loaded from a local path via replace directive
|
||||
|
||||
gosec:
|
||||
# To select a subset of rules to run.
|
||||
# Available rules: https://github.com/securego/gosec#available-rules
|
||||
includes:
|
||||
- G401
|
||||
- G306
|
||||
- G101
|
||||
# To specify a set of rules to explicitly exclude.
|
||||
# Available rules: https://github.com/securego/gosec#available-rules
|
||||
excludes:
|
||||
- G204
|
||||
# Exclude generated files
|
||||
exclude-generated: true
|
||||
# Filter out the issues with a lower severity than the given value. Valid options are: low, medium, high.
|
||||
severity: "low"
|
||||
# Filter out the issues with a lower confidence than the given value. Valid options are: low, medium, high.
|
||||
confidence: "low"
|
||||
# To specify the configuration of rules.
|
||||
# The configuration of rules is not fully documented by gosec:
|
||||
# https://github.com/securego/gosec#configuration
|
||||
# https://github.com/securego/gosec/blob/569328eade2ccbad4ce2d0f21ee158ab5356a5cf/rules/rulelist.go#L60-L102
|
||||
config:
|
||||
G306: "0600"
|
||||
G101:
|
||||
pattern: "(?i)example"
|
||||
ignore_entropy: false
|
||||
entropy_threshold: "80.0"
|
||||
per_char_threshold: "3.0"
|
||||
truncate: "32"
|
||||
|
||||
gosimple:
|
||||
# Select the Go version to target. The default is '1.13'.
|
||||
go: "1.16"
|
||||
# https://staticcheck.io/docs/options#checks
|
||||
checks: [ "all" ]
|
||||
|
||||
govet:
|
||||
# report about shadowed variables
|
||||
check-shadowing: true
|
||||
|
||||
# settings per analyzer
|
||||
settings:
|
||||
printf: # analyzer name, run `go tool vet help` to see all analyzers
|
||||
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
|
||||
- (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
|
||||
|
||||
# enable or disable analyzers by name
|
||||
# run `go tool vet help` to see all analyzers
|
||||
enable:
|
||||
- atomicalign
|
||||
enable-all: false
|
||||
disable:
|
||||
- shadow
|
||||
disable-all: false
|
||||
|
||||
depguard:
|
||||
list-type: blacklist
|
||||
include-go-root: false
|
||||
packages:
|
||||
- github.com/sirupsen/logrus
|
||||
packages-with-error-message:
|
||||
# specify an error message to output when a blacklisted package is used
|
||||
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
|
||||
|
||||
ifshort:
|
||||
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
|
||||
# Has higher priority than max-decl-chars.
|
||||
max-decl-lines: 1
|
||||
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
|
||||
max-decl-chars: 30
|
||||
|
||||
importas:
|
||||
# if set to `true`, force to use alias.
|
||||
no-unaliased: true
|
||||
# List of aliases
|
||||
alias:
|
||||
# using `servingv1` alias for `knative.dev/serving/pkg/apis/serving/v1` package
|
||||
- pkg: knative.dev/serving/pkg/apis/serving/v1
|
||||
alias: servingv1
|
||||
# using `autoscalingv1alpha1` alias for `knative.dev/serving/pkg/apis/autoscaling/v1alpha1` package
|
||||
- pkg: knative.dev/serving/pkg/apis/autoscaling/v1alpha1
|
||||
alias: autoscalingv1alpha1
|
||||
# You can specify the package path by regular expression,
|
||||
# and alias by regular expression expansion syntax like below.
|
||||
# see https://github.com/julz/importas#use-regular-expression for details
|
||||
- pkg: knative.dev/serving/pkg/apis/(\w+)/(v[\w\d]+)
|
||||
alias: $1$2
|
||||
|
||||
ireturn:
|
||||
# ireturn allows using `allow` and `reject` settings at the same time.
|
||||
# Both settings are lists of the keywords and regular expressions matched to interface or package names.
|
||||
# keywords:
|
||||
# - `empty` for `interface{}`
|
||||
# - `error` for errors
|
||||
# - `stdlib` for standard library
|
||||
# - `anon` for anonymous interfaces
|
||||
|
||||
# By default, it allows using errors, empty interfaces, anonymous interfaces,
|
||||
# and interfaces provided by the standard library.
|
||||
allow:
|
||||
- anon
|
||||
- error
|
||||
- empty
|
||||
- stdlib
|
||||
# You can specify idiomatic endings for interface
|
||||
- (or|er)$
|
||||
|
||||
# Reject patterns
|
||||
# reject:
|
||||
# - github.com\/user\/package\/v4\.Type
|
||||
|
||||
lll:
|
||||
# max line length, lines longer will be reported. Default is 120.
|
||||
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||
line-length: 240
|
||||
# tab width in spaces. Default to 1.
|
||||
tab-width: 4
|
||||
|
||||
makezero:
|
||||
# Allow only slices initialized with a length of zero. Default is false.
|
||||
always: false
|
||||
|
||||
maligned:
|
||||
# print struct with more effective memory layout or not, false by default
|
||||
suggest-new: true
|
||||
|
||||
misspell:
|
||||
# Correct spellings using locale preferences for US or UK.
|
||||
# Default is to use a neutral variety of English.
|
||||
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
|
||||
locale: US
|
||||
ignore-words:
|
||||
- someword
|
||||
|
||||
nakedret:
|
||||
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
|
||||
max-func-lines: 30
|
||||
|
||||
nestif:
|
||||
# minimal complexity of if statements to report, 5 by default
|
||||
min-complexity: 4
|
||||
|
||||
nilnil:
|
||||
# By default, nilnil checks all returned types below.
|
||||
checked-types:
|
||||
- ptr
|
||||
- func
|
||||
- iface
|
||||
- map
|
||||
- chan
|
||||
|
||||
nlreturn:
|
||||
# size of the block (including return statement that is still "OK")
|
||||
# so no return split required.
|
||||
block-size: 1
|
||||
|
||||
nolintlint:
|
||||
# Disable to ensure that all nolint directives actually have an effect. Default is true.
|
||||
allow-unused: true
|
||||
# Disable to ensure that nolint directives don't have a leading space. Default is true.
|
||||
allow-leading-space: true
|
||||
# Exclude following linters from requiring an explanation. Default is [].
|
||||
allow-no-explanation: [ ]
|
||||
# Enable to require an explanation of nonzero length after each nolint directive. Default is false.
|
||||
require-explanation: false
|
||||
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
|
||||
require-specific: true
|
||||
|
||||
prealloc:
|
||||
# XXX: we don't recommend using this linter before doing performance profiling.
|
||||
# For most programs usage of prealloc will be a premature optimization.
|
||||
|
||||
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
|
||||
# True by default.
|
||||
simple: true
|
||||
range-loops: true # Report preallocation suggestions on range loops, true by default
|
||||
for-loops: false # Report preallocation suggestions on for loops, false by default
|
||||
|
||||
promlinter:
|
||||
# Promlinter cannot infer all metrics name in static analysis.
|
||||
# Enable strict mode will also include the errors caused by failing to parse the args.
|
||||
strict: false
|
||||
# Please refer to https://github.com/yeya24/promlinter#usage for detailed usage.
|
||||
disabled-linters:
|
||||
# - "Help"
|
||||
# - "MetricUnits"
|
||||
# - "Counter"
|
||||
# - "HistogramSummaryReserved"
|
||||
# - "MetricTypeInName"
|
||||
# - "ReservedChars"
|
||||
# - "CamelCase"
|
||||
# - "lintUnitAbbreviations"
|
||||
|
||||
predeclared:
|
||||
# comma-separated list of predeclared identifiers to not report on
|
||||
ignore: ""
|
||||
# include method names and field names (i.e., qualified names) in checks
|
||||
q: false
|
||||
|
||||
rowserrcheck:
|
||||
packages:
|
||||
- github.com/jmoiron/sqlx
|
||||
|
||||
revive:
|
||||
# see https://github.com/mgechev/revive#available-rules for details.
|
||||
ignore-generated-header: true
|
||||
severity: warning
|
||||
rules:
|
||||
- name: indent-error-flow
|
||||
severity: warning
|
||||
- name: add-constant
|
||||
severity: warning
|
||||
arguments:
|
||||
- maxLitCount: "3"
|
||||
allowStrs: '""'
|
||||
allowInts: "0,1,2"
|
||||
allowFloats: "0.0,0.,1.0,1.,2.0,2."
|
||||
|
||||
staticcheck:
|
||||
# Select the Go version to target. The default is '1.13'.
|
||||
go: "1.16"
|
||||
# https://staticcheck.io/docs/options#checks
|
||||
checks: [ "all" ]
|
||||
|
||||
stylecheck:
|
||||
# Select the Go version to target. The default is '1.13'.
|
||||
go: "1.16"
|
||||
# https://staticcheck.io/docs/options#checks
|
||||
checks: [ "all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022" ]
|
||||
# https://staticcheck.io/docs/options#dot_import_whitelist
|
||||
dot-import-whitelist:
|
||||
- fmt
|
||||
# https://staticcheck.io/docs/options#initialisms
|
||||
initialisms: [ "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS" ]
|
||||
# https://staticcheck.io/docs/options#http_status_code_whitelist
|
||||
http-status-code-whitelist: [ "200", "400", "404", "500" ]
|
||||
|
||||
tagliatelle:
|
||||
# check the struck tag name case
|
||||
case:
|
||||
# use the struct field name to check the name of the struct tag
|
||||
use-field-name: true
|
||||
rules:
|
||||
# any struct tag type can be used.
|
||||
# support string case: `camel`, `pascal`, `kebab`, `snake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`
|
||||
json: camel
|
||||
yaml: camel
|
||||
xml: camel
|
||||
bson: camel
|
||||
avro: snake
|
||||
mapstructure: kebab
|
||||
|
||||
testpackage:
|
||||
# regexp pattern to skip files
|
||||
skip-regexp: (export|internal)_test\.go
|
||||
|
||||
thelper:
|
||||
# The following configurations enable all checks. It can be omitted because all checks are enabled by default.
|
||||
# You can enable only required checks deleting unnecessary checks.
|
||||
test:
|
||||
first: true
|
||||
name: true
|
||||
begin: true
|
||||
benchmark:
|
||||
first: true
|
||||
name: true
|
||||
begin: true
|
||||
tb:
|
||||
first: true
|
||||
name: true
|
||||
begin: true
|
||||
|
||||
tenv:
|
||||
# The option `all` will run against whole test files (`_test.go`) regardless of method/function signatures.
|
||||
# By default, only methods that take `*testing.T`, `*testing.B`, and `testing.TB` as arguments are checked.
|
||||
all: false
|
||||
|
||||
unparam:
|
||||
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
|
||||
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
|
||||
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
|
||||
# with golangci-lint call it on a directory with the changed file.
|
||||
check-exported: false
|
||||
|
||||
unused:
|
||||
# Select the Go version to target. The default is '1.13'.
|
||||
go: "1.16"
|
||||
|
||||
varnamelen:
|
||||
# The longest distance, in source lines, that is being considered a "small scope." (defaults to 5)
|
||||
# Variables used in at most this many lines will be ignored.
|
||||
max-distance: 5
|
||||
# The minimum length of a variable's name that is considered "long." (defaults to 3)
|
||||
# Variable names that are at least this long will be ignored.
|
||||
min-name-length: 1
|
||||
# Check method receiver names. (defaults to false)
|
||||
check-receiver: false
|
||||
# Check named return values. (defaults to false)
|
||||
check-return: false
|
||||
# Ignore "ok" variables that hold the bool return value of a type assertion. (defaults to false)
|
||||
ignore-type-assert-ok: false
|
||||
# Ignore "ok" variables that hold the bool return value of a map index. (defaults to false)
|
||||
ignore-map-index-ok: false
|
||||
# Ignore "ok" variables that hold the bool return value of a channel receive. (defaults to false)
|
||||
ignore-chan-recv-ok: false
|
||||
# Optional list of variable names that should be ignored completely. (defaults to empty list)
|
||||
ignore-names:
|
||||
- err
|
||||
# Optional list of variable declarations that should be ignored completely. (defaults to empty list)
|
||||
# Entries must be in the form of "<variable name> <type>" or "<variable name> *<type>".
|
||||
ignore-decls:
|
||||
- c echo.Context
|
||||
- t testing.T
|
||||
- f *foo.Bar
|
||||
- e error
|
||||
- i int
|
||||
|
||||
whitespace:
|
||||
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
|
||||
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
|
||||
|
||||
wrapcheck:
|
||||
# An array of strings that specify substrings of signatures to ignore.
|
||||
# If this set, it will override the default set of ignored signatures.
|
||||
# See https://github.com/tomarrell/wrapcheck#configuration for more information.
|
||||
ignoreSigs:
|
||||
- .Errorf(
|
||||
- errors.New(
|
||||
- errors.Unwrap(
|
||||
- .Wrap(
|
||||
- .Wrapf(
|
||||
- .WithMessage(
|
||||
- .WithMessagef(
|
||||
- .WithStack(
|
||||
ignorePackageGlobs:
|
||||
- encoding/*
|
||||
- github.com/pkg/*
|
||||
|
||||
wsl:
|
||||
# See https://github.com/bombsimon/wsl/blob/master/doc/configuration.md for
|
||||
# documentation of available settings. These are the defaults for
|
||||
# `golangci-lint`.
|
||||
allow-assign-and-anything: false
|
||||
allow-assign-and-call: true
|
||||
allow-cuddle-declarations: false
|
||||
allow-multiline-assign: true
|
||||
allow-separated-leading-comment: false
|
||||
allow-trailing-comment: false
|
||||
force-case-trailing-whitespace: 0
|
||||
force-err-cuddling: false
|
||||
force-short-decl-cuddling: false
|
||||
strict-append: true
|
||||
|
||||
# The custom section can be used to define linter plugins to be loaded at runtime.
|
||||
# See README doc for more info.
|
||||
# custom:
|
||||
# Each custom linter should have a unique name.
|
||||
# example:
|
||||
# The path to the plugin *.so. Can be absolute or local. Required for each custom linter
|
||||
# path: /path/to/example.so
|
||||
# The description of the linter. Optional, just for documentation purposes.
|
||||
# description: This is an example usage of a plugin linter.
|
||||
# Intended to point to the repo location of the linter. Optional, just for documentation purposes.
|
||||
# original-url: github.com/golangci/example-linter
|
||||
|
||||
linters:
|
||||
#disable-all: true
|
||||
#enable:
|
||||
# - megacheck
|
||||
# - govet
|
||||
enable-all: true
|
||||
disable:
|
||||
- maligned
|
||||
- prealloc
|
||||
#- tagliatelle
|
||||
#- wrapcheck
|
||||
#- forcetypeassert
|
||||
- goerr113
|
||||
- gomnd
|
||||
- wsl
|
||||
- testpackage
|
||||
- gochecknoglobals
|
||||
- interfacer
|
||||
- maligned
|
||||
- scopelint
|
||||
- gocritic
|
||||
- typecheck
|
||||
# presets:
|
||||
# - bugs
|
||||
# - unused
|
||||
fast: false
|
||||
|
||||
|
||||
issues:
|
||||
# List of regexps of issue texts to exclude, empty list by default.
|
||||
# But independently from this option we use default exclude patterns,
|
||||
# it can be disabled by `exclude-use-default: false`. To list all
|
||||
# excluded by default patterns execute `golangci-lint run --help`
|
||||
exclude:
|
||||
- abcdef
|
||||
- tools/.*
|
||||
- test/.*
|
||||
- third_party/.*
|
||||
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||
exclude-rules:
|
||||
# Exclude some linters from running on tests files.
|
||||
- linters:
|
||||
- revive
|
||||
path: (log/.*)\.go
|
||||
- linters:
|
||||
- wrapcheck
|
||||
path: (cmd/.*|pkg/.*)\.go
|
||||
- linters:
|
||||
- typecheck
|
||||
path: (pkg/storage/.*)\.go
|
||||
|
||||
- path: (cmd/.*|test/.*|tools/.*)\.go
|
||||
linters:
|
||||
- forbidigo
|
||||
- path: (cmd/[a-z]*/.*|store/.*)\.go
|
||||
linters:
|
||||
- dupl
|
||||
- linters:
|
||||
- gocritic
|
||||
text: (hugeParam:|rangeValCopy:)
|
||||
|
||||
- path: (cmd/[a-z]*/.*)\.go
|
||||
linters:
|
||||
- lll
|
||||
|
||||
- path: (validator/.*|code/.*|validator/.*)
|
||||
linters:
|
||||
- gochecknoinits
|
||||
- path: (pkg/app/.*)\.go
|
||||
linters:
|
||||
- gocyclo
|
||||
- errcheck
|
||||
- dupl
|
||||
- gosec
|
||||
|
||||
# Exclude known linters from partially hard-vendored code,
|
||||
# which is impossible to exclude via "nolint" comments.
|
||||
- path: internal/hmac/
|
||||
text: "weak cryptographic primitive"
|
||||
linters:
|
||||
- gosec
|
||||
|
||||
# Exclude some staticcheck messages
|
||||
- linters:
|
||||
- staticcheck
|
||||
text: "SA9003:"
|
||||
|
||||
# Exclude lll issues for long lines with go:generate
|
||||
- linters:
|
||||
- lll
|
||||
source: "^//go:generate "
|
||||
|
||||
# Independently from option `exclude` we use default exclude patterns,
|
||||
# it can be disabled by this option. To list all
|
||||
# excluded by default patterns execute `golangci-lint run --help`.
|
||||
# Default value for this option is true.
|
||||
exclude-use-default: false
|
||||
|
||||
# The default value is false. If set to true exclude and exclude-rules
|
||||
# regular expressions become case sensitive.
|
||||
exclude-case-sensitive: false
|
||||
|
||||
# The list of ids of default excludes to include or disable. By default it's empty.
|
||||
include:
|
||||
- EXC0002 # disable excluding of issues about comments from golint
|
||||
|
||||
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
|
||||
max-issues-per-linter: 0
|
||||
|
||||
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
|
||||
max-same-issues: 0
|
||||
|
||||
# Show only new issues: if there are unstaged changes or untracked files,
|
||||
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
|
||||
# It's a super-useful option for integration of golangci-lint into existing
|
||||
# large codebase. It's not practical to fix all existing issues at the moment
|
||||
# of integration: much better don't allow issues in new code.
|
||||
# Default is false.
|
||||
new: false
|
||||
|
||||
# Show only new issues created after git revision `REV`
|
||||
new-from-rev: REV
|
||||
|
||||
# Show only new issues created in git patch with set file path.
|
||||
# new-from-patch: path/to/patch/file
|
||||
|
||||
# Fix found issues (if it's supported by the linter)
|
||||
fix: true
|
||||
|
||||
severity:
|
||||
# Default value is empty string.
|
||||
# Set the default severity for issues. If severity rules are defined and the issues
|
||||
# do not match or no severity is provided to the rule this will be the default
|
||||
# severity applied. Severities should match the supported severity names of the
|
||||
# selected out format.
|
||||
# - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity
|
||||
# - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#severity
|
||||
# - GitHub: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
|
||||
default-severity: error
|
||||
|
||||
# The default value is false.
|
||||
# If set to true severity-rules regular expressions become case sensitive.
|
||||
case-sensitive: false
|
||||
|
||||
# Default value is empty list.
|
||||
# When a list of severity rules are provided, severity information will be added to lint
|
||||
# issues. Severity rules have the same filtering capability as exclude rules except you
|
||||
# are allowed to specify one matcher per severity rule.
|
||||
# Only affects out formats that support setting severity information.
|
||||
rules:
|
||||
- linters:
|
||||
- dupl
|
||||
severity: info
|
@ -407,9 +407,8 @@ func (a *StrArray) SubSlice(offset int, length ...int) []string {
|
||||
s := make([]string, size)
|
||||
copy(s, a.array[offset:])
|
||||
return s
|
||||
} else {
|
||||
return a.array[offset:end]
|
||||
}
|
||||
return a.array[offset:end]
|
||||
}
|
||||
|
||||
// Append is alias of PushRight,please See PushRight.
|
||||
|
@ -301,7 +301,7 @@ var (
|
||||
// in the field name as it conflicts with "db.table.field" pattern in SOME situations.
|
||||
regularFieldNameWithoutDotRegPattern = `^[\w\-]+$`
|
||||
|
||||
// tableFieldsMap caches the table information retrived from database.
|
||||
// tableFieldsMap caches the table information retrieved from database.
|
||||
tableFieldsMap = gmap.New(true)
|
||||
|
||||
// allDryRun sets dry-run feature for all database connections.
|
||||
@ -429,7 +429,7 @@ func getConfigNodeByGroup(group string, master bool) (*ConfigNode, error) {
|
||||
// Calculation algorithm brief:
|
||||
// 1. If we have 2 nodes, and their weights are both 1, then the weight range is [0, 199];
|
||||
// 2. Node1 weight range is [0, 99], and node2 weight range is [100, 199], ratio is 1:1;
|
||||
// 3. If the random number is 99, it then chooses and returns node1;
|
||||
// 3. If the random number is 99, it then chooses and returns node1;.
|
||||
func getConfigNodeByWeight(cg ConfigGroup) *ConfigNode {
|
||||
if len(cg) < 2 {
|
||||
return &cg[0]
|
||||
|
@ -393,7 +393,7 @@ func (c *Core) DoInsert(ctx context.Context, link Link, table string, list List,
|
||||
onDuplicateStr string // onDuplicateStr is used in "ON DUPLICATE KEY UPDATE" statement.
|
||||
)
|
||||
// Handle the field names and placeholders.
|
||||
for k, _ := range list[0] {
|
||||
for k := range list[0] {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
// Prepare the batch result pointer.
|
||||
@ -448,9 +448,7 @@ func (c *Core) DoInsert(ctx context.Context, link Link, table string, list List,
|
||||
}
|
||||
|
||||
func (c *Core) formatOnDuplicate(columns []string, option DoInsertOption) string {
|
||||
var (
|
||||
onDuplicateStr string
|
||||
)
|
||||
var onDuplicateStr string
|
||||
if option.OnDuplicateStr != "" {
|
||||
onDuplicateStr = option.OnDuplicateStr
|
||||
} else if len(option.OnDuplicateMap) > 0 {
|
||||
@ -505,7 +503,7 @@ func (c *Core) formatOnDuplicate(columns []string, option DoInsertOption) string
|
||||
// "money>? AND name like ?", 99999, "vip_%"
|
||||
// "status IN (?)", g.Slice{1,2,3}
|
||||
// "age IN(?,?)", 18, 50
|
||||
// User{ Id : 1, UserName : "john"}
|
||||
// User{ Id : 1, UserName : "john"}.
|
||||
func (c *Core) Update(ctx context.Context, table string, data interface{}, condition interface{}, args ...interface{}) (sql.Result, error) {
|
||||
return c.Model(table).Ctx(ctx).Data(data).Where(condition, args...).Update()
|
||||
}
|
||||
@ -596,7 +594,7 @@ func (c *Core) DoUpdate(ctx context.Context, link Link, table string, data inter
|
||||
// "money>? AND name like ?", 99999, "vip_%"
|
||||
// "status IN (?)", g.Slice{1,2,3}
|
||||
// "age IN(?,?)", 18, 50
|
||||
// User{ Id : 1, UserName : "john"}
|
||||
// User{ Id : 1, UserName : "john"}.
|
||||
func (c *Core) Delete(ctx context.Context, table string, condition interface{}, args ...interface{}) (result sql.Result, err error) {
|
||||
return c.Model(table).Ctx(ctx).Where(condition, args...).Delete()
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ func (c *Core) convertFieldValueToLocalValue(fieldValue interface{}, fieldType s
|
||||
func (c *Core) mappingAndFilterData(schema, table string, data map[string]interface{}, filter bool) (map[string]interface{}, error) {
|
||||
if fieldsMap, err := c.db.TableFields(c.GetCtx(), c.guessPrimaryTableName(table), schema); err == nil {
|
||||
fieldsKeyMap := make(map[string]interface{}, len(fieldsMap))
|
||||
for k, _ := range fieldsMap {
|
||||
for k := range fieldsMap {
|
||||
fieldsKeyMap[k] = nil
|
||||
}
|
||||
// Automatic data key to table field name mapping.
|
||||
@ -166,7 +166,7 @@ func (c *Core) mappingAndFilterData(schema, table string, data map[string]interf
|
||||
// Data filtering.
|
||||
// It deletes all key-value pairs that has incorrect field name.
|
||||
if filter {
|
||||
for dataKey, _ := range data {
|
||||
for dataKey := range data {
|
||||
if _, ok := fieldsMap[dataKey]; !ok {
|
||||
delete(data, dataKey)
|
||||
}
|
||||
|
@ -11,12 +11,13 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -38,9 +38,7 @@ const (
|
||||
transactionIdForLoggerCtx = "TransactionId"
|
||||
)
|
||||
|
||||
var (
|
||||
transactionIdGenerator = gtype.NewUint64()
|
||||
)
|
||||
var transactionIdGenerator = gtype.NewUint64()
|
||||
|
||||
// Begin starts and returns the transaction object.
|
||||
// You should call Commit or Rollback functions of the transaction object
|
||||
@ -99,9 +97,7 @@ func (c *Core) doBeginCtx(ctx context.Context) (*TX, error) {
|
||||
// Note that, you should not Commit or Rollback the transaction in function `f`
|
||||
// as it is automatically handled by this function.
|
||||
func (c *Core) Transaction(ctx context.Context, f func(ctx context.Context, tx *TX) error) (err error) {
|
||||
var (
|
||||
tx *TX
|
||||
)
|
||||
var tx *TX
|
||||
if ctx == nil {
|
||||
ctx = c.GetCtx()
|
||||
}
|
||||
@ -537,7 +533,7 @@ func (tx *TX) Save(table string, data interface{}, batch ...int) (sql.Result, er
|
||||
// "money>? AND name like ?", 99999, "vip_%"
|
||||
// "status IN (?)", g.Slice{1,2,3}
|
||||
// "age IN(?,?)", 18, 50
|
||||
// User{ Id : 1, UserName : "john"}
|
||||
// User{ Id : 1, UserName : "john"}.
|
||||
func (tx *TX) Update(table string, data interface{}, condition interface{}, args ...interface{}) (sql.Result, error) {
|
||||
return tx.Model(table).Ctx(tx.ctx).Data(data).Where(condition, args...).Update()
|
||||
}
|
||||
@ -552,7 +548,7 @@ func (tx *TX) Update(table string, data interface{}, condition interface{}, args
|
||||
// "money>? AND name like ?", 99999, "vip_%"
|
||||
// "status IN (?)", g.Slice{1,2,3}
|
||||
// "age IN(?,?)", 18, 50
|
||||
// User{ Id : 1, UserName : "john"}
|
||||
// User{ Id : 1, UserName : "john"}.
|
||||
func (tx *TX) Delete(table string, condition interface{}, args ...interface{}) (sql.Result, error) {
|
||||
return tx.Model(table).Ctx(tx.ctx).Where(condition, args...).Delete()
|
||||
}
|
||||
|
@ -128,9 +128,7 @@ func (c *Core) DoExec(ctx context.Context, link Link, sql string, args ...interf
|
||||
result = new(SqlResult)
|
||||
}
|
||||
mTime2 := gtime.TimestampMilli()
|
||||
var (
|
||||
rowsAffected int64
|
||||
)
|
||||
var rowsAffected int64
|
||||
if err == nil {
|
||||
rowsAffected, err = result.RowsAffected()
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"net/url"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
|
@ -267,7 +267,7 @@ func (d *DriverOracle) DoInsert(ctx context.Context, link Link, table string, li
|
||||
listLength = len(list)
|
||||
valueHolder = make([]string, 0)
|
||||
)
|
||||
for k, _ := range list[0] {
|
||||
for k := range list[0] {
|
||||
keys = append(keys, k)
|
||||
valueHolder = append(valueHolder, "?")
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func doQuoteWord(s, charLeft, charRight string) string {
|
||||
// "user u, user_detail ut" => "`user` u,`user_detail` ut"
|
||||
// "user.user u, user.user_detail ut" => "`user`.`user` u,`user`.`user_detail` ut"
|
||||
// "u.id, u.name, u.age" => "`u`.`id`,`u`.`name`,`u`.`age`"
|
||||
// "u.id asc" => "`u`.`id` asc"
|
||||
// "u.id asc" => "`u`.`id` asc".
|
||||
func doQuoteString(s, charLeft, charRight string) string {
|
||||
array1 := gstr.SplitAndTrim(s, ",")
|
||||
for k1, v1 := range array1 {
|
||||
@ -484,9 +484,9 @@ func formatWhere(db DB, in formatWhereInput) (newWhere string, newArgs []interfa
|
||||
|
||||
default:
|
||||
// Usually a string.
|
||||
var (
|
||||
whereStr = gconv.String(in.Where)
|
||||
)
|
||||
|
||||
whereStr := gconv.String(in.Where)
|
||||
|
||||
// Is `whereStr` a field name which composed as a key-value condition?
|
||||
// Eg:
|
||||
// Where("id", 1)
|
||||
@ -514,18 +514,16 @@ func formatWhere(db DB, in formatWhereInput) (newWhere string, newArgs []interfa
|
||||
// Regular string and parameter place holder handling.
|
||||
// Eg:
|
||||
// Where("id in(?) and name=?", g.Slice{1,2,3}, "john")
|
||||
var (
|
||||
i = 0
|
||||
)
|
||||
|
||||
i := 0
|
||||
|
||||
for {
|
||||
if i >= len(in.Args) {
|
||||
break
|
||||
}
|
||||
// Sub query, which is always used along with a string condition.
|
||||
if model, ok := in.Args[i].(*Model); ok {
|
||||
var (
|
||||
index = -1
|
||||
)
|
||||
index := -1
|
||||
whereStr, _ = gregex.ReplaceStringFunc(`(\?)`, whereStr, func(s string) string {
|
||||
index++
|
||||
if i+len(newArgs) == index {
|
||||
@ -836,9 +834,7 @@ func FormatSqlWithArgs(sql string, args []interface{}) string {
|
||||
if v, ok := args[index].(Raw); ok {
|
||||
return gconv.String(v)
|
||||
}
|
||||
var (
|
||||
reflectInfo = utils.OriginValueAndKind(args[index])
|
||||
)
|
||||
reflectInfo := utils.OriginValueAndKind(args[index])
|
||||
if reflectInfo.OriginKind == reflect.Ptr &&
|
||||
(reflectInfo.OriginValue.IsNil() || !reflectInfo.OriginValue.IsValid()) {
|
||||
return "null"
|
||||
|
@ -46,7 +46,7 @@ func (m *Model) Cache(option CacheOption) *Model {
|
||||
// cache feature is enabled.
|
||||
func (m *Model) checkAndRemoveCache() {
|
||||
if m.cacheEnabled && m.cacheOption.Duration < 0 && len(m.cacheOption.Name) > 0 {
|
||||
var ctx = m.GetCtx()
|
||||
ctx := m.GetCtx()
|
||||
_, err := m.db.GetCache().Remove(ctx, m.cacheOption.Name)
|
||||
if err != nil {
|
||||
intlog.Error(ctx, err)
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
// Where("uid", 1).Where("name", "john")
|
||||
// Where("status IN (?)", g.Slice{1,2,3})
|
||||
// Where("age IN(?,?)", 18, 50)
|
||||
// Where(User{ Id : 1, UserName : "john"})
|
||||
// Where(User{ Id : 1, UserName : "john"}).
|
||||
func (m *Model) Where(where interface{}, args ...interface{}) *Model {
|
||||
model := m.getModel()
|
||||
if model.whereHolder == nil {
|
||||
@ -315,9 +315,7 @@ func (m *Model) Page(page, limit int) *Model {
|
||||
//
|
||||
// The parameter `limit1` specifies whether limits querying only one record if m.limit is not set.
|
||||
func (m *Model) formatCondition(limit1 bool, isCountStatement bool) (conditionWhere string, conditionExtra string, conditionArgs []interface{}) {
|
||||
var (
|
||||
autoPrefix = ""
|
||||
)
|
||||
autoPrefix := ""
|
||||
if gstr.Contains(m.tables, " JOIN ") {
|
||||
autoPrefix = m.db.GetCore().QuoteWord(m.tablesInit)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
// Fields("id", "name", "age")
|
||||
// Fields([]string{"id", "name", "age"})
|
||||
// Fields(map[string]interface{}{"id":1, "name":"john", "age":18})
|
||||
// Fields(User{ Id: 1, Name: "john", Age: 18})
|
||||
// Fields(User{ Id: 1, Name: "john", Age: 18}).
|
||||
func (m *Model) Fields(fieldNamesOrMapStruct ...interface{}) *Model {
|
||||
length := len(fieldNamesOrMapStruct)
|
||||
if length == 0 {
|
||||
|
@ -36,7 +36,7 @@ func (m *Model) Batch(batch int) *Model {
|
||||
// Data("uid", 10000)
|
||||
// Data("uid=? AND name=?", 10000, "john")
|
||||
// Data(g.Map{"uid": 10000, "name":"john"})
|
||||
// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
|
||||
// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"}).
|
||||
func (m *Model) Data(data ...interface{}) *Model {
|
||||
model := m.getModel()
|
||||
if len(data) > 1 {
|
||||
@ -69,9 +69,7 @@ func (m *Model) Data(data ...interface{}) *Model {
|
||||
model.data = gutil.MapCopy(value)
|
||||
|
||||
default:
|
||||
var (
|
||||
reflectInfo = utils.OriginValueAndKind(value)
|
||||
)
|
||||
reflectInfo := utils.OriginValueAndKind(value)
|
||||
switch reflectInfo.OriginKind {
|
||||
case reflect.Slice, reflect.Array:
|
||||
if reflectInfo.OriginValue.Len() > 0 {
|
||||
@ -131,7 +129,7 @@ func (m *Model) Data(data ...interface{}) *Model {
|
||||
// })
|
||||
// OnDuplicate(g.Map{
|
||||
// "nickname": "passport",
|
||||
// })
|
||||
// }).
|
||||
func (m *Model) OnDuplicate(onDuplicate ...interface{}) *Model {
|
||||
model := m.getModel()
|
||||
if len(onDuplicate) > 1 {
|
||||
@ -151,7 +149,7 @@ func (m *Model) OnDuplicate(onDuplicate ...interface{}) *Model {
|
||||
// OnDuplicateEx(g.Map{
|
||||
// "passport": "",
|
||||
// "password": "",
|
||||
// })
|
||||
// }).
|
||||
func (m *Model) OnDuplicateEx(onDuplicateEx ...interface{}) *Model {
|
||||
model := m.getModel()
|
||||
if len(onDuplicateEx) > 1 {
|
||||
@ -256,9 +254,7 @@ func (m *Model) doInsertWithOption(insertOption int) (result sql.Result, err err
|
||||
list = List{ConvertDataForTableRecord(value)}
|
||||
|
||||
default:
|
||||
var (
|
||||
reflectInfo = utils.OriginValueAndKind(newData)
|
||||
)
|
||||
reflectInfo := utils.OriginValueAndKind(newData)
|
||||
switch reflectInfo.OriginKind {
|
||||
// If it's slice type, it then converts it to List type.
|
||||
case reflect.Slice, reflect.Array:
|
||||
@ -272,9 +268,7 @@ func (m *Model) doInsertWithOption(insertOption int) (result sql.Result, err err
|
||||
|
||||
case reflect.Struct:
|
||||
if v, ok := value.(iInterfaces); ok {
|
||||
var (
|
||||
array = v.Interfaces()
|
||||
)
|
||||
array := v.Interfaces()
|
||||
list = make(List, len(array))
|
||||
for i := 0; i < len(array); i++ {
|
||||
list[i] = ConvertDataForTableRecord(array[i])
|
||||
@ -310,7 +304,7 @@ func (m *Model) doInsertWithOption(insertOption int) (result sql.Result, err err
|
||||
}
|
||||
// Format DoInsertOption, especially for "ON DUPLICATE KEY UPDATE" statement.
|
||||
columnNames := make([]string, 0, len(list[0]))
|
||||
for k, _ := range list[0] {
|
||||
for k := range list[0] {
|
||||
columnNames = append(columnNames, k)
|
||||
}
|
||||
doInsertOption, err := m.formatDoInsertOption(insertOption, columnNames)
|
||||
@ -331,18 +325,14 @@ func (m *Model) formatDoInsertOption(insertOption int, columnNames []string) (op
|
||||
if err != nil {
|
||||
return option, err
|
||||
}
|
||||
var (
|
||||
onDuplicateExKeySet = gset.NewStrSetFrom(onDuplicateExKeys)
|
||||
)
|
||||
onDuplicateExKeySet := gset.NewStrSetFrom(onDuplicateExKeys)
|
||||
if m.onDuplicate != nil {
|
||||
switch m.onDuplicate.(type) {
|
||||
case Raw, *Raw:
|
||||
option.OnDuplicateStr = gconv.String(m.onDuplicate)
|
||||
|
||||
default:
|
||||
var (
|
||||
reflectInfo = utils.OriginValueAndKind(m.onDuplicate)
|
||||
)
|
||||
reflectInfo := utils.OriginValueAndKind(m.onDuplicate)
|
||||
switch reflectInfo.OriginKind {
|
||||
case reflect.String:
|
||||
option.OnDuplicateMap = make(map[string]interface{})
|
||||
@ -397,9 +387,7 @@ func (m *Model) formatOnDuplicateExKeys(onDuplicateEx interface{}) ([]string, er
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var (
|
||||
reflectInfo = utils.OriginValueAndKind(onDuplicateEx)
|
||||
)
|
||||
reflectInfo := utils.OriginValueAndKind(onDuplicateEx)
|
||||
switch reflectInfo.OriginKind {
|
||||
case reflect.String:
|
||||
return gstr.SplitAndTrim(reflectInfo.OriginValue.String(), ","), nil
|
||||
|
@ -30,7 +30,7 @@ func isSubQuery(s string) bool {
|
||||
// Eg:
|
||||
// Model("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Model("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
// Model("user", "u").LeftJoin("SELECT xxx FROM xxx AS a", "a.uid=u.uid")
|
||||
// Model("user", "u").LeftJoin("SELECT xxx FROM xxx AS a", "a.uid=u.uid").
|
||||
func (m *Model) LeftJoin(table ...string) *Model {
|
||||
return m.doJoin("LEFT", table...)
|
||||
}
|
||||
@ -42,7 +42,7 @@ func (m *Model) LeftJoin(table ...string) *Model {
|
||||
// Eg:
|
||||
// Model("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Model("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
// Model("user", "u").RightJoin("SELECT xxx FROM xxx AS a", "a.uid=u.uid")
|
||||
// Model("user", "u").RightJoin("SELECT xxx FROM xxx AS a", "a.uid=u.uid").
|
||||
func (m *Model) RightJoin(table ...string) *Model {
|
||||
return m.doJoin("RIGHT", table...)
|
||||
}
|
||||
@ -54,7 +54,7 @@ func (m *Model) RightJoin(table ...string) *Model {
|
||||
// Eg:
|
||||
// Model("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Model("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
// Model("user", "u").InnerJoin("SELECT xxx FROM xxx AS a", "a.uid=u.uid")
|
||||
// Model("user", "u").InnerJoin("SELECT xxx FROM xxx AS a", "a.uid=u.uid").
|
||||
func (m *Model) InnerJoin(table ...string) *Model {
|
||||
return m.doJoin("INNER", table...)
|
||||
}
|
||||
@ -63,7 +63,7 @@ func (m *Model) InnerJoin(table ...string) *Model {
|
||||
//
|
||||
// Eg:
|
||||
// Model("order").LeftJoinOnField("user", "user_id")
|
||||
// Model("order").LeftJoinOnField("product", "product_id")
|
||||
// Model("order").LeftJoinOnField("product", "product_id").
|
||||
func (m *Model) LeftJoinOnField(table, field string) *Model {
|
||||
return m.doJoin("LEFT", table, fmt.Sprintf(
|
||||
`%s.%s=%s.%s`,
|
||||
@ -78,7 +78,7 @@ func (m *Model) LeftJoinOnField(table, field string) *Model {
|
||||
//
|
||||
// Eg:
|
||||
// Model("order").InnerJoinOnField("user", "user_id")
|
||||
// Model("order").InnerJoinOnField("product", "product_id")
|
||||
// Model("order").InnerJoinOnField("product", "product_id").
|
||||
func (m *Model) RightJoinOnField(table, field string) *Model {
|
||||
return m.doJoin("RIGHT", table, fmt.Sprintf(
|
||||
`%s.%s=%s.%s`,
|
||||
@ -93,7 +93,7 @@ func (m *Model) RightJoinOnField(table, field string) *Model {
|
||||
//
|
||||
// Eg:
|
||||
// Model("order").InnerJoinOnField("user", "user_id")
|
||||
// Model("order").InnerJoinOnField("product", "product_id")
|
||||
// Model("order").InnerJoinOnField("product", "product_id").
|
||||
func (m *Model) InnerJoinOnField(table, field string) *Model {
|
||||
return m.doJoin("INNER", table, fmt.Sprintf(
|
||||
`%s.%s=%s.%s`,
|
||||
|
@ -32,7 +32,7 @@ func (m *Model) OmitEmpty() *Model {
|
||||
// Where("id", []int{}).All() -> SELECT xxx FROM xxx WHERE 0=1
|
||||
// Where("name", "").All() -> SELECT xxx FROM xxx WHERE `name`=''
|
||||
// OmitEmpty().Where("id", []int{}).All() -> SELECT xxx FROM xxx
|
||||
// OmitEmpty().("name", "").All() -> SELECT xxx FROM xxx
|
||||
// OmitEmpty().("name", "").All() -> SELECT xxx FROM xxx.
|
||||
func (m *Model) OmitEmptyWhere() *Model {
|
||||
model := m.getModel()
|
||||
model.option = model.option | optionOmitEmptyWhere
|
||||
|
@ -13,7 +13,7 @@ import "strings"
|
||||
// Eg:
|
||||
// Order("id desc")
|
||||
// Order("id", "desc")
|
||||
// Order("id desc,name asc")
|
||||
// Order("id desc,name asc").
|
||||
func (m *Model) Order(orderBy ...string) *Model {
|
||||
if len(orderBy) == 0 {
|
||||
return m
|
||||
|
@ -206,7 +206,7 @@ func (m *Model) Array(fieldsAndWhere ...interface{}) ([]Value, error) {
|
||||
// err := db.Model("user").Where("id", 1).Scan(user)
|
||||
//
|
||||
// user := (*User)(nil)
|
||||
// err := db.Model("user").Where("id", 1).Scan(&user)
|
||||
// err := db.Model("user").Where("id", 1).Scan(&user).
|
||||
func (m *Model) doStruct(pointer interface{}, where ...interface{}) error {
|
||||
model := m
|
||||
// Auto selecting fields by struct attributes.
|
||||
@ -242,7 +242,7 @@ func (m *Model) doStruct(pointer interface{}, where ...interface{}) error {
|
||||
// err := db.Model("user").Scan(&users)
|
||||
//
|
||||
// users := ([]*User)(nil)
|
||||
// err := db.Model("user").Scan(&users)
|
||||
// err := db.Model("user").Scan(&users).
|
||||
func (m *Model) doStructs(pointer interface{}, where ...interface{}) error {
|
||||
model := m
|
||||
// Auto selecting fields by struct attributes.
|
||||
@ -291,11 +291,9 @@ func (m *Model) doStructs(pointer interface{}, where ...interface{}) error {
|
||||
// err := db.Model("user").Scan(&users)
|
||||
//
|
||||
// users := ([]*User)(nil)
|
||||
// err := db.Model("user").Scan(&users)
|
||||
// err := db.Model("user").Scan(&users).
|
||||
func (m *Model) Scan(pointer interface{}, where ...interface{}) error {
|
||||
var (
|
||||
reflectInfo = utils.OriginTypeAndKind(pointer)
|
||||
)
|
||||
reflectInfo := utils.OriginTypeAndKind(pointer)
|
||||
if reflectInfo.InputKind != reflect.Ptr {
|
||||
return gerror.NewCode(
|
||||
gcode.CodeInvalidParameter,
|
||||
|
@ -113,7 +113,7 @@ func (m *Model) getSoftFieldName(table string, keys []string) (field string) {
|
||||
// "user u, user_detail ud"
|
||||
// "user u LEFT JOIN user_detail ud ON(ud.uid=u.uid)"
|
||||
// "user LEFT JOIN user_detail ON(user_detail.uid=user.uid)"
|
||||
// "user u LEFT JOIN user_detail ud ON(ud.uid=u.uid) LEFT JOIN user_stats us ON(us.uid=u.uid)"
|
||||
// "user u LEFT JOIN user_detail ud ON(ud.uid=u.uid) LEFT JOIN user_stats us ON(us.uid=u.uid)".
|
||||
func (m *Model) getConditionForSoftDeleting() string {
|
||||
if m.unscoped {
|
||||
return ""
|
||||
|
@ -49,9 +49,7 @@ func (m *Model) Update(dataAndWhere ...interface{}) (result sql.Result, err erro
|
||||
)
|
||||
// Automatically update the record updating time.
|
||||
if !m.unscoped && fieldNameUpdate != "" {
|
||||
var (
|
||||
reflectInfo = utils.OriginTypeAndKind(m.data)
|
||||
)
|
||||
reflectInfo := utils.OriginTypeAndKind(m.data)
|
||||
switch reflectInfo.OriginKind {
|
||||
case reflect.Map, reflect.Struct:
|
||||
dataMap := ConvertDataForTableRecord(m.data)
|
||||
|
@ -46,7 +46,7 @@ func (m *Model) getModel() *Model {
|
||||
// mappingAndFilterToTableFields mappings and changes given field name to really table field name.
|
||||
// Eg:
|
||||
// ID -> id
|
||||
// NICK_Name -> nickname
|
||||
// NICK_Name -> nickname.
|
||||
func (m *Model) mappingAndFilterToTableFields(fields []string, filter bool) []string {
|
||||
fieldsMap, err := m.TableFields(m.tablesInit)
|
||||
if err != nil || len(fieldsMap) == 0 {
|
||||
@ -57,7 +57,7 @@ func (m *Model) mappingAndFilterToTableFields(fields []string, filter bool) []st
|
||||
outputFieldsArray = make([]string, 0, len(inputFieldsArray))
|
||||
)
|
||||
fieldsKeyMap := make(map[string]interface{}, len(fieldsMap))
|
||||
for k, _ := range fieldsMap {
|
||||
for k := range fieldsMap {
|
||||
fieldsKeyMap[k] = nil
|
||||
}
|
||||
for _, field := range inputFieldsArray {
|
||||
@ -87,9 +87,7 @@ func (m *Model) filterDataForInsertOrUpdate(data interface{}) (interface{}, erro
|
||||
var err error
|
||||
switch value := data.(type) {
|
||||
case List:
|
||||
var (
|
||||
omitEmpty bool
|
||||
)
|
||||
var omitEmpty bool
|
||||
if m.option&optionOmitNilDataList > 0 {
|
||||
omitEmpty = true
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ func (m *Model) doWithScanStructs(pointer interface{}) error {
|
||||
relatedTargetValue interface{}
|
||||
)
|
||||
// Find the value slice of related attribute from `pointer`.
|
||||
for attributeName, _ := range currentStructFieldMap {
|
||||
for attributeName := range currentStructFieldMap {
|
||||
if utils.EqualFoldWithoutChars(attributeName, relatedTargetName) {
|
||||
relatedTargetValue = ListItemValuesUnique(pointer, attributeName)
|
||||
break
|
||||
|
@ -32,7 +32,7 @@ func (tx *TX) Schema(schema string) *Schema {
|
||||
|
||||
// Model creates and returns a new ORM model.
|
||||
// The parameter `tables` can be more than one table names, like :
|
||||
// "user", "user u", "user, user_detail", "user u, user_detail ud"
|
||||
// "user", "user u", "user, user_detail", "user u, user_detail ud".
|
||||
func (s *Schema) Model(table string) *Model {
|
||||
var m *Model
|
||||
if s.tx != nil {
|
||||
|
@ -83,7 +83,7 @@ func (r Result) Array(field ...string) []Value {
|
||||
if len(field) > 0 && field[0] != "" {
|
||||
key = field[0]
|
||||
} else {
|
||||
for k, _ := range r[0] {
|
||||
for k := range r[0] {
|
||||
key = k
|
||||
break
|
||||
}
|
||||
|
@ -290,12 +290,10 @@ func doScanList(model *Model, result Result, structSlicePointer interface{}, bin
|
||||
if relationFields != "" && !relationBindToFieldNameChecked {
|
||||
relationFromAttrField = relationFromAttrValue.FieldByName(relationBindToFieldName)
|
||||
if !relationFromAttrField.IsValid() {
|
||||
var (
|
||||
filedMap, _ = structs.FieldMap(structs.FieldMapInput{
|
||||
Pointer: relationFromAttrValue,
|
||||
RecursiveOption: structs.RecursiveOptionEmbeddedNoTag,
|
||||
})
|
||||
)
|
||||
filedMap, _ := structs.FieldMap(structs.FieldMapInput{
|
||||
Pointer: relationFromAttrValue,
|
||||
RecursiveOption: structs.RecursiveOptionEmbeddedNoTag,
|
||||
})
|
||||
if key, _ := gutil.MapPossibleItemByKey(gconv.Map(filedMap), relationBindToFieldName); key == "" {
|
||||
return gerror.NewCodef(
|
||||
gcode.CodeInvalidParameter,
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-sql-driver/mysql"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
@ -45,7 +45,6 @@ func Test_DB_Query(t *testing.T) {
|
||||
_, err = db.Query(ctx, "ERROR")
|
||||
t.AssertNE(err, nil)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func Test_DB_Exec(t *testing.T) {
|
||||
@ -56,7 +55,6 @@ func Test_DB_Exec(t *testing.T) {
|
||||
_, err = db.Exec(ctx, "ERROR")
|
||||
t.AssertNE(err, nil)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func Test_DB_Prepare(t *testing.T) {
|
||||
@ -391,7 +389,6 @@ func Test_DB_BatchInsert(t *testing.T) {
|
||||
n, _ := result.RowsAffected()
|
||||
t.Assert(n, 1)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func Test_DB_BatchInsert_Struct(t *testing.T) {
|
||||
@ -924,12 +921,10 @@ func Test_DB_ToXml(t *testing.T) {
|
||||
} else {
|
||||
gtest.Fatal("FAIL")
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func Test_DB_ToStringMap(t *testing.T) {
|
||||
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
_, err := db.Update(ctx, table, "create_time='2010-10-10 00:00:01'", "id=?", 1)
|
||||
@ -965,7 +960,6 @@ func Test_DB_ToStringMap(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_DB_ToIntMap(t *testing.T) {
|
||||
|
||||
table := createInitTable()
|
||||
defer dropTable(table)
|
||||
_, err := db.Update(ctx, table, "create_time='2010-10-10 00:00:01'", "id=?", 1)
|
||||
@ -1034,7 +1028,6 @@ func Test_DB_ToUintMap(t *testing.T) {
|
||||
t.Assert(t_users[0].Password, resultUintMap[uint(id)]["password"])
|
||||
t.Assert(t_users[0].NickName, resultUintMap[uint(id)]["nickname"])
|
||||
t.Assert(t_users[0].CreateTime, resultUintMap[uint(id)]["create_time"])
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -1072,7 +1065,6 @@ func Test_DB_ToStringRecord(t *testing.T) {
|
||||
t.Assert(t_users[0].Password, resultStringRecord[ids]["password"].String())
|
||||
t.Assert(t_users[0].NickName, resultStringRecord[ids]["nickname"].String())
|
||||
t.Assert(t_users[0].CreateTime, resultStringRecord[ids]["create_time"].String())
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -1109,7 +1101,6 @@ func Test_DB_ToIntRecord(t *testing.T) {
|
||||
t.Assert(t_users[0].Password, resultIntRecord[id]["password"].String())
|
||||
t.Assert(t_users[0].NickName, resultIntRecord[id]["nickname"].String())
|
||||
t.Assert(t_users[0].CreateTime, resultIntRecord[id]["create_time"].String())
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -1301,7 +1292,6 @@ func Test_DB_Prefix(t *testing.T) {
|
||||
t.Assert(e, nil)
|
||||
t.Assert(n, TableSize)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func Test_Model_InnerJoin(t *testing.T) {
|
||||
@ -1420,7 +1410,7 @@ func Test_Empty_Slice_Argument(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// update counter test
|
||||
// update counter test.
|
||||
func Test_DB_UpdateCounter(t *testing.T) {
|
||||
tableName := "gf_update_counter_test_" + gtime.TimestampNanoStr()
|
||||
_, err := db.Exec(ctx, fmt.Sprintf(`
|
||||
|
@ -970,7 +970,6 @@ func Test_Model_StructsWithOrmTag(t *testing.T) {
|
||||
t.Assert(one["passport"], "user_2")
|
||||
t.Assert(one["password"], "pass_2")
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func Test_Model_Scan(t *testing.T) {
|
||||
@ -1984,7 +1983,6 @@ func Test_Model_Option_List(t *testing.T) {
|
||||
t.Assert(list[1]["nickname"].String(), "")
|
||||
t.Assert(list[1]["passport"].String(), "")
|
||||
t.Assert(list[1]["password"].String(), "2")
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -2827,6 +2825,7 @@ func Test_Model_Fields_Struct(t *testing.T) {
|
||||
t.Assert(one["nickname"], "name_2")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Model_NullField(t *testing.T) {
|
||||
table := createTable()
|
||||
defer dropTable(table)
|
||||
@ -3058,7 +3057,7 @@ func Test_Model_Fields_Map_Struct(t *testing.T) {
|
||||
PASSPORT string
|
||||
XXX_TYPE int
|
||||
}
|
||||
var a = A{}
|
||||
a := A{}
|
||||
err := db.Model(table).Fields(a).Where("id", 1).Scan(&a)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a.ID, 1)
|
||||
|
@ -99,7 +99,6 @@ func Test_Model_Embedded_MapToStruct(t *testing.T) {
|
||||
t.Assert(user.Password, data["password"])
|
||||
t.Assert(user.Nickname, data["nickname"])
|
||||
t.Assert(user.CreateTime, data["create_time"])
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -550,9 +549,7 @@ func Test_Scan_JsonAttributes(t *testing.T) {
|
||||
Passport string
|
||||
}
|
||||
|
||||
var (
|
||||
table = "jfy_gift"
|
||||
)
|
||||
table := "jfy_gift"
|
||||
array := gstr.SplitAndTrim(gtest.TestDataContent(`issue1380.sql`), ";")
|
||||
for _, v := range array {
|
||||
if _, err := db.Exec(ctx, v); err != nil {
|
||||
|
@ -66,6 +66,5 @@ func Test_Model_WhereOrPrefix(t *testing.T) {
|
||||
t.Assert(r[1]["id"], "2")
|
||||
t.Assert(r[2]["id"], "8")
|
||||
t.Assert(r[3]["id"], "9")
|
||||
|
||||
})
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
// CreateAt/UpdateAt/DeleteAt
|
||||
// CreateAt/UpdateAt/DeleteAt.
|
||||
func Test_SoftCreateUpdateDeleteTime(t *testing.T) {
|
||||
table := "time_test_table_" + gtime.TimestampNanoStr()
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf(`
|
||||
@ -150,7 +150,7 @@ CREATE TABLE %s (
|
||||
})
|
||||
}
|
||||
|
||||
// CreatedAt/UpdatedAt/DeletedAt
|
||||
// CreatedAt/UpdatedAt/DeletedAt.
|
||||
func Test_SoftCreatedUpdatedDeletedTime_Map(t *testing.T) {
|
||||
table := "time_test_table_" + gtime.TimestampNanoStr()
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf(`
|
||||
@ -284,7 +284,7 @@ CREATE TABLE %s (
|
||||
})
|
||||
}
|
||||
|
||||
// CreatedAt/UpdatedAt/DeletedAt
|
||||
// CreatedAt/UpdatedAt/DeletedAt.
|
||||
func Test_SoftCreatedUpdatedDeletedTime_Struct(t *testing.T) {
|
||||
table := "time_test_table_" + gtime.TimestampNanoStr()
|
||||
if _, err := db.Exec(ctx, fmt.Sprintf(`
|
||||
|
@ -144,7 +144,6 @@ func Test_TX_Insert(t *testing.T) {
|
||||
if err := tx.Commit(); err != nil {
|
||||
gtest.Error(err)
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@ -415,7 +414,6 @@ func Test_TX_GetValue(t *testing.T) {
|
||||
gtest.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func Test_TX_GetCount(t *testing.T) {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
|
@ -10,13 +10,14 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
)
|
||||
|
||||
// tracingItem holds the information for redis tracing.
|
||||
|
@ -8,19 +8,16 @@ package gbinary
|
||||
|
||||
// NOTE: THIS IS AN EXPERIMENTAL FEATURE!
|
||||
|
||||
// Bit Binary bit (0 | 1) 二进制位(0|1)
|
||||
// Bit Binary bit (0 | 1)
|
||||
type Bit int8
|
||||
|
||||
// EncodeBits .
|
||||
// Default coding
|
||||
// 默认编码
|
||||
// EncodeBits does encode bits return bits Default coding
|
||||
func EncodeBits(bits []Bit, i int, l int) []Bit {
|
||||
return EncodeBitsWithUint(bits, uint(i), l)
|
||||
}
|
||||
|
||||
// EncodeBitsWithUint .
|
||||
// Merge ui bitwise into the bits array and occupy the length length bits (Note: binary 0 | 1 digits are stored in the uis array)
|
||||
// 将ui按位合并到bits数组中,并占length长度位(注意:uis数组中存放的是二进制的0|1数字)
|
||||
// EncodeBitsWithUint . Merge ui bitwise into the bits array and occupy the length bits
|
||||
// (Note: binary 0 | 1 digits are stored in the uis array)
|
||||
func EncodeBitsWithUint(bits []Bit, ui uint, l int) []Bit {
|
||||
a := make([]Bit, l)
|
||||
for i := l - 1; i >= 0; i-- {
|
||||
@ -33,9 +30,8 @@ func EncodeBitsWithUint(bits []Bit, ui uint, l int) []Bit {
|
||||
return a
|
||||
}
|
||||
|
||||
// EncodeBitsToBytes .
|
||||
// EncodeBitsToBytes . does encode bits to bytes
|
||||
// Convert bits to [] byte, encode from left to right, and add less than 1 byte from 0 to the end.
|
||||
// 将bits转换为[]byte,从左至右进行编码,不足1 byte按0往末尾补充
|
||||
func EncodeBitsToBytes(bits []Bit) []byte {
|
||||
if len(bits)%8 != 0 {
|
||||
for i := 0; i < len(bits)%8; i++ {
|
||||
@ -49,9 +45,8 @@ func EncodeBitsToBytes(bits []Bit) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
// DecodeBits .
|
||||
// DecodeBits .does decode bits to int
|
||||
// Resolve to int
|
||||
// 解析为int
|
||||
func DecodeBits(bits []Bit) int {
|
||||
v := 0
|
||||
for _, i := range bits {
|
||||
@ -60,9 +55,7 @@ func DecodeBits(bits []Bit) int {
|
||||
return v
|
||||
}
|
||||
|
||||
// DecodeBitsToUint .
|
||||
// Resolve to uint
|
||||
// 解析为uint
|
||||
// DecodeBitsToUint .Resolve to uint
|
||||
func DecodeBitsToUint(bits []Bit) uint {
|
||||
v := uint(0)
|
||||
for _, i := range bits {
|
||||
@ -71,9 +64,7 @@ func DecodeBitsToUint(bits []Bit) uint {
|
||||
return v
|
||||
}
|
||||
|
||||
// DecodeBytesToBits .
|
||||
// Parsing [] byte into character array [] uint8
|
||||
// 解析[]byte为字位数组[]uint8
|
||||
// DecodeBytesToBits .Parsing [] byte into character array [] uint8
|
||||
func DecodeBytesToBits(bs []byte) []Bit {
|
||||
bits := make([]Bit, 0)
|
||||
for _, b := range bs {
|
||||
|
@ -24,12 +24,13 @@ import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
"golang.org/x/text/encoding"
|
||||
"golang.org/x/text/encoding/ianaindex"
|
||||
"golang.org/x/text/transform"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"bytes"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
)
|
||||
|
||||
|
@ -27,25 +27,27 @@ func Decode(str string) (string, error) {
|
||||
return url.QueryUnescape(str)
|
||||
}
|
||||
|
||||
// RawEncode does encode the given string according
|
||||
// URL-encode according to RFC 3986.
|
||||
// See http://php.net/manual/en/function.rawurlencode.php.
|
||||
func RawEncode(str string) string {
|
||||
return strings.Replace(url.QueryEscape(str), "+", "%20", -1)
|
||||
}
|
||||
|
||||
// RawDecode does decode the given string
|
||||
// Decode URL-encoded strings.
|
||||
// See http://php.net/manual/en/function.rawurldecode.php.
|
||||
func RawDecode(str string) (string, error) {
|
||||
return url.QueryUnescape(strings.Replace(str, "%20", "+", -1))
|
||||
}
|
||||
|
||||
// Generate URL-encoded query string.
|
||||
// BuildQuery Generate URL-encoded query string.
|
||||
// See http://php.net/manual/en/function.http-build-query.php.
|
||||
func BuildQuery(queryData url.Values) string {
|
||||
return queryData.Encode()
|
||||
}
|
||||
|
||||
// Parse a URL and return its components.
|
||||
// ParseURL Parse a URL and return its components.
|
||||
// -1: all; 1: scheme; 2: host; 4: port; 8: user; 16: pass; 32: path; 64: query; 128: fragment.
|
||||
// See http://php.net/manual/en/function.parse-url.php.
|
||||
func ParseURL(str string, component int) (map[string]string, error) {
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/clbanning/mxj/v2"
|
||||
|
||||
"github.com/gogf/gf/v2/encoding/gcharset"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
)
|
||||
@ -63,9 +64,8 @@ func ToJson(content []byte) ([]byte, error) {
|
||||
mv, err := mxj.NewMapXml(res)
|
||||
if err == nil {
|
||||
return mv.Json()
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// convert does convert the encoding of given XML content from XML root tag into UTF-8 encoding content.
|
||||
|
@ -8,10 +8,11 @@
|
||||
package gyaml
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/internal/json"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func Encode(value interface{}) (out []byte, err error) {
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
// Package gerror provides simple functions to manipulate errors.
|
||||
//
|
||||
// Very note that, this package is quite a basic package, which SHOULD NOT import extra
|
||||
// packages except standard packages and internal packages, to avoid cycle imports.
|
||||
// Very note that, this package is quite a basic package, which SHOULD NOT import extra packages
|
||||
// except standard packages and internal packages, to avoid cycle imports.
|
||||
package gerror
|
||||
|
||||
import (
|
||||
|
@ -14,9 +14,10 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -11,6 +11,12 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/net/ghttp/internal/client"
|
||||
@ -18,11 +24,6 @@ import (
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -18,42 +18,42 @@ import (
|
||||
// WriteTpl parses and responses given template file.
|
||||
// The parameter `params` specifies the template variables for parsing.
|
||||
func (r *Response) WriteTpl(tpl string, params ...gview.Params) error {
|
||||
if b, err := r.ParseTpl(tpl, params...); err != nil {
|
||||
b, err := r.ParseTpl(tpl, params...)
|
||||
if err != nil {
|
||||
if !gmode.IsProduct() {
|
||||
r.Write("Template Parsing Error: " + err.Error())
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
r.Write(b)
|
||||
}
|
||||
r.Write(b)
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteTplDefault parses and responses the default template file.
|
||||
// The parameter `params` specifies the template variables for parsing.
|
||||
func (r *Response) WriteTplDefault(params ...gview.Params) error {
|
||||
if b, err := r.ParseTplDefault(params...); err != nil {
|
||||
b, err := r.ParseTplDefault(params...)
|
||||
if err != nil {
|
||||
if !gmode.IsProduct() {
|
||||
r.Write("Template Parsing Error: " + err.Error())
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
r.Write(b)
|
||||
}
|
||||
r.Write(b)
|
||||
return nil
|
||||
}
|
||||
|
||||
// WriteTplContent parses and responses the template content.
|
||||
// The parameter `params` specifies the template variables for parsing.
|
||||
func (r *Response) WriteTplContent(content string, params ...gview.Params) error {
|
||||
if b, err := r.ParseTplContent(content, params...); err != nil {
|
||||
b, err := r.ParseTplContent(content, params...)
|
||||
if err != nil {
|
||||
if !gmode.IsProduct() {
|
||||
r.Write("Template Parsing Error: " + err.Error())
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
r.Write(b)
|
||||
}
|
||||
r.Write(b)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ func (w *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return w.writer.(http.Hijacker).Hijack()
|
||||
}
|
||||
|
||||
// Flush OutputBuffer outputs the buffer to client and clears the buffer.
|
||||
// Flush outputs the buffer to client and clears the buffer.
|
||||
func (w *ResponseWriter) Flush() {
|
||||
if w.hijacked {
|
||||
return
|
||||
|
@ -16,6 +16,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/container/gtype"
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
@ -34,7 +36,6 @@ import (
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -18,14 +18,14 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/proxy"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"golang.org/x/net/proxy"
|
||||
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
// Client is the HTTP client for HTTP request management.
|
||||
|
@ -12,17 +12,18 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptrace"
|
||||
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2"
|
||||
"github.com/gogf/gf/v2/internal/utils"
|
||||
"github.com/gogf/gf/v2/net/ghttp/internal/httputil"
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -12,14 +12,15 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/net/gipv4"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/net/gipv4"
|
||||
"github.com/gogf/gf/v2/os/gcmd"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -9,10 +9,11 @@ package gtrace
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/baggage"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"go.opentelemetry.io/otel/baggage"
|
||||
)
|
||||
|
||||
// Baggage holds the data through all tracing spans.
|
||||
|
@ -10,10 +10,11 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2/net/gtrace"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -99,7 +99,7 @@ func (c *AdapterMemory) SetMap(ctx context.Context, data map[interface{}]interfa
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for k, _ := range data {
|
||||
for k := range data {
|
||||
c.eventList.PushBack(&adapterMemoryEvent{
|
||||
k: k,
|
||||
e: expireTime,
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
|
||||
"github.com/gogf/gf/v2/container/glist"
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/container/gqueue"
|
||||
|
@ -16,6 +16,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gtype"
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/internal/intlog"
|
||||
@ -27,7 +29,6 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gtimer"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
// Logger is the struct for logging management.
|
||||
|
@ -9,7 +9,7 @@ package gres
|
||||
import "github.com/gogf/gf/v2/container/gmap"
|
||||
|
||||
const (
|
||||
// DefaultName Default group name for instance usage.
|
||||
// DefaultName default group name for instance usage.
|
||||
DefaultName = "default"
|
||||
)
|
||||
|
||||
|
@ -77,7 +77,7 @@ func (s *StorageRedis) Get(ctx context.Context, id string, key string) (value in
|
||||
return nil, ErrorDisabled
|
||||
}
|
||||
|
||||
// GetMap retrieves all key-value pairs as map from storage.
|
||||
// Data retrieves all key-value pairs as map from storage.
|
||||
func (s *StorageRedis) Data(ctx context.Context, id string) (data map[string]interface{}, err error) {
|
||||
return nil, ErrorDisabled
|
||||
}
|
||||
@ -135,9 +135,8 @@ func (s *StorageRedis) GetSession(ctx context.Context, id string, ttl time.Durat
|
||||
}
|
||||
if data == nil {
|
||||
return gmap.NewStrAnyMapFrom(m, true), nil
|
||||
} else {
|
||||
data.Replace(m)
|
||||
}
|
||||
data.Replace(m)
|
||||
return data, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user