mirror of
https://gitee.com/johng/gf
synced 2026-06-07 18:26:02 +08:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4fb739615b | |||
| ba39323d30 | |||
| 383937fe69 | |||
| f919f90bf5 | |||
| b4f6f06ab5 | |||
| 73fbca40ca | |||
| e8d3fcac6b | |||
| f87182d5b8 | |||
| 951f8921cd | |||
| d26b7c5437 | |||
| 9407fda197 | |||
| 905913f7be | |||
| 4b8eaac73f | |||
| ca242ff401 | |||
| 42e3c5f39a | |||
| 4f4d2c2f8e | |||
| 5a01798481 | |||
| 8af1eb693e | |||
| 335ccb32af | |||
| e1f2666499 | |||
| 22fcfdf755 | |||
| 1e21b61a19 | |||
| 6abd8bd864 | |||
| 4876ae0e2b | |||
| 63bdf41d40 | |||
| 984cca8b82 | |||
| 9f7ce42c74 | |||
| 16a43bcb6c |
38
.github/ISSUE_TEMPLATE.MD
vendored
38
.github/ISSUE_TEMPLATE.MD
vendored
@ -1,38 +0,0 @@
|
||||
<!-- Please answer these questions before submitting your issue. Thanks! -->
|
||||
|
||||
<!-- 为高效处理您的疑问,如果觉得是BUG类问题,请您务必提供可复现该问题的最小可运行代码!否则issue可能会被延期处理! -->
|
||||
<!-- 为高效处理您的疑问,如果觉得是BUG类问题,请您务必提供可复现该问题的最小可运行代码!否则issue可能会被延期处理! -->
|
||||
<!-- 为高效处理您的疑问,如果觉得是BUG类问题,请您务必提供可复现该问题的最小可运行代码!否则issue可能会被延期处理! -->
|
||||
<!-- 重要的事情说三遍! -->
|
||||
|
||||
### 1. What version of `Go` and system type/arch are you using?
|
||||
<!--
|
||||
Please paste the output of command `go version` from your terminal.
|
||||
What expect to see is like: `go 1.12, linux/amd64`
|
||||
-->
|
||||
|
||||
|
||||
### 2. What version of `GoFrame` are you using?
|
||||
<!-- You can find the GF version from your `go.mod`, or from the `version.go` in `GF` -->
|
||||
|
||||
|
||||
### 3. Can this issue be re-produced with the latest release?
|
||||
|
||||
|
||||
|
||||
### 4. What did you do?
|
||||
<!--
|
||||
If possible, provide a copy of shortest codes for reproducing the error.
|
||||
A complete runnable program is best.
|
||||
-->
|
||||
|
||||
|
||||
|
||||
### 5. What did you expect to see?
|
||||
|
||||
|
||||
|
||||
### 6. What did you see instead?
|
||||
|
||||
|
||||
|
||||
41
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
41
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- Please answer these questions before submitting your issue. Thanks! -->
|
||||
|
||||
<!-- 为高效处理 Bug,请您务必提供可复现该问题的最小可运行代码!否则 issue 可能会被延期处理! -->
|
||||
<!-- 为高效处理 Bug,请您务必提供可复现该问题的最小可运行代码!否则 issue 可能会被延期处理! -->
|
||||
<!-- 为高效处理 Bug,如请您务必提供可复现该问题的最小可运行代码!否则 issue 可能会被延期处理! -->
|
||||
<!-- 重要的事情说三遍! -->
|
||||
|
||||
**What version of `Go` and system type/arch are you using?**
|
||||
<!--
|
||||
Please paste the output of command `go version` from your terminal.
|
||||
What expects to see is like: `go 1.12, linux/amd64`
|
||||
-->
|
||||
|
||||
|
||||
**What version of `GoFrame` are you using?**
|
||||
<!-- You can find the GF version from your `go.mod`, or from the `version.go` in `GF` -->
|
||||
|
||||
|
||||
**Can this bug be re-produced with the latest release?**
|
||||
|
||||
|
||||
**What did you do?**
|
||||
<!--
|
||||
If possible, provide a copy of shortest codes for reproducing the error.
|
||||
A complete runnable program is best.
|
||||
-->
|
||||
|
||||
|
||||
**What did you expect to see?**
|
||||
|
||||
|
||||
**What did you see instead?**
|
||||
16
.github/ISSUE_TEMPLATE/enhancement-request.md
vendored
Normal file
16
.github/ISSUE_TEMPLATE/enhancement-request.md
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
name: Enhancement request
|
||||
about: Enhance an idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Package that You wish to enhance**
|
||||
|
||||
|
||||
**Enhancement description**
|
||||
|
||||
|
||||
**Additional**
|
||||
19
.github/ISSUE_TEMPLATE/feature-request.md
vendored
Normal file
19
.github/ISSUE_TEMPLATE/feature-request.md
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: feature
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
|
||||
|
||||
**Describe the solution you'd like**
|
||||
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
|
||||
|
||||
**Additional**
|
||||
11
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
11
.github/ISSUE_TEMPLATE/question.md
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
name: Question
|
||||
about: I want to ask a question
|
||||
title: ''
|
||||
labels: question
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!-- 请优先仔细阅读文档 -->
|
||||
**What do you want to ask**
|
||||
6
.github/workflows/gitee-sync.yml
vendored
6
.github/workflows/gitee-sync.yml
vendored
@ -1,7 +1,7 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
@ -13,8 +13,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v4
|
||||
- name: Mirror Github to Gitee
|
||||
uses: Yikun/hub-mirror-action@v1.2
|
||||
- name: Mirror GitHub to Gitee
|
||||
uses: Yikun/hub-mirror-action@v1.3
|
||||
with:
|
||||
src: github/gogf
|
||||
dst: gitee/johng
|
||||
|
||||
16
README.MD
16
README.MD
@ -7,16 +7,16 @@
|
||||
[](https://github.com/gogf/gf/actions/workflows/ci-main.yml)
|
||||
[](https://goreportcard.com/report/github.com/gogf/gf/v2)
|
||||
[](https://codecov.io/gh/gogf/gf)
|
||||
[](https://github.com/gogf/gf)
|
||||
[](https://github.com/gogf/gf)
|
||||
[](https://github.com/gogf/gf)
|
||||
|
||||
[](https://github.com/gogf/gf/releases)
|
||||
[](https://github.com/gogf/gf/pulls)
|
||||
[](https://github.com/gogf/gf/pulls?q=is%3Apr+is%3Aclosed)
|
||||
[](https://github.com/gogf/gf/issues)
|
||||
[](https://github.com/gogf/gf/issues?q=is%3Aissue+is%3Aclosed)
|
||||

|
||||

|
||||
[](https://github.com/gogf/gf/releases)
|
||||
[](https://github.com/gogf/gf/pulls)
|
||||
[](https://github.com/gogf/gf/pulls?q=is%3Apr+is%3Aclosed)
|
||||
[](https://github.com/gogf/gf/issues)
|
||||
[](https://github.com/gogf/gf/issues?q=is%3Aissue+is%3Aclosed)
|
||||

|
||||

|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@ -3,13 +3,13 @@ module github.com/gogf/gf/cmd/gf/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.6.2
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
golang.org/x/mod v0.9.0
|
||||
|
||||
@ -44,8 +44,9 @@ type cBuild struct {
|
||||
}
|
||||
|
||||
const (
|
||||
cBuildBrief = `cross-building go project for lots of platforms`
|
||||
cBuildEg = `
|
||||
cBuildDefaultFile = "main.go"
|
||||
cBuildBrief = `cross-building go project for lots of platforms`
|
||||
cBuildEg = `
|
||||
gf build main.go
|
||||
gf build main.go --ps public,template
|
||||
gf build main.go --cgo
|
||||
@ -123,7 +124,7 @@ type cBuildInput struct {
|
||||
Arch string `short:"a" name:"arch" brief:"output binary architecture, multiple arch separated with ','"`
|
||||
System string `short:"s" name:"system" brief:"output binary system, multiple os separated with ','"`
|
||||
Output string `short:"o" name:"output" brief:"output binary path, used when building single binary file"`
|
||||
Path string `short:"p" name:"path" brief:"output binary directory path, default is './temp'" d:"./temp"`
|
||||
Path string `short:"p" name:"path" brief:"output binary directory path, default is '.'" d:"."`
|
||||
Extra string `short:"e" name:"extra" brief:"extra custom \"go build\" options"`
|
||||
Mod string `short:"m" name:"mod" brief:"like \"-mod\" option of \"go build\", use \"-m none\" to disable go module"`
|
||||
Cgo bool `short:"c" name:"cgo" brief:"enable or disable cgo feature, it's disabled in default" orphan:"true"`
|
||||
@ -152,12 +153,13 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
|
||||
|
||||
var (
|
||||
parser = gcmd.ParserFromCtx(ctx)
|
||||
file = parser.GetArg(2).String()
|
||||
file = in.File
|
||||
)
|
||||
if len(file) < 1 {
|
||||
if file == "" {
|
||||
file = parser.GetArg(2).String()
|
||||
// Check and use the main.go file.
|
||||
if gfile.Exists("main.go") {
|
||||
file = "main.go"
|
||||
if gfile.Exists(cBuildDefaultFile) {
|
||||
file = cBuildDefaultFile
|
||||
} else {
|
||||
mlog.Fatal("build file path is empty or main.go not found in current working directory")
|
||||
}
|
||||
@ -239,13 +241,7 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
|
||||
} else {
|
||||
genv.MustSet("CGO_ENABLED", "0")
|
||||
}
|
||||
var (
|
||||
cmd = ""
|
||||
ext = ""
|
||||
)
|
||||
for system, item := range platformMap {
|
||||
cmd = ""
|
||||
ext = ""
|
||||
if len(customSystems) > 0 && customSystems[0] != "all" && !gstr.InArray(customSystems, system) {
|
||||
continue
|
||||
}
|
||||
@ -258,58 +254,22 @@ func (c cBuild) Index(ctx context.Context, in cBuildInput) (out *cBuildOutput, e
|
||||
// For example:
|
||||
// `gf build`
|
||||
// `gf build -o main.exe`
|
||||
if runtime.GOOS == "windows" {
|
||||
ext = ".exe"
|
||||
}
|
||||
var outputPath string
|
||||
if len(in.Output) > 0 {
|
||||
outputPath = "-o " + in.Output
|
||||
} else {
|
||||
outputPath = "-o " + in.Name + ext
|
||||
}
|
||||
cmd = fmt.Sprintf(
|
||||
`go build %s -ldflags "%s" %s %s`,
|
||||
outputPath, ldFlags, in.Extra, file,
|
||||
c.doBinaryBuild(
|
||||
ctx, file,
|
||||
in.Output, in.Path,
|
||||
runtime.GOOS, runtime.GOARCH, in.Name, ldFlags, in.Extra,
|
||||
in.ExitWhenError,
|
||||
true,
|
||||
)
|
||||
} else {
|
||||
// Cross-building, output the compiled binary to specified path.
|
||||
if system == "windows" {
|
||||
ext = ".exe"
|
||||
}
|
||||
genv.MustSet("GOOS", system)
|
||||
genv.MustSet("GOARCH", arch)
|
||||
|
||||
var outputPath string
|
||||
if len(in.Output) > 0 {
|
||||
outputPath = "-o " + in.Output
|
||||
} else {
|
||||
outputPath = fmt.Sprintf(
|
||||
"-o %s/%s/%s%s",
|
||||
in.Path, system+"_"+arch, in.Name, ext,
|
||||
)
|
||||
}
|
||||
cmd = fmt.Sprintf(
|
||||
`go build %s -ldflags "%s" %s%s`,
|
||||
outputPath, ldFlags, in.Extra, file,
|
||||
c.doBinaryBuild(
|
||||
ctx, file,
|
||||
in.Output, in.Path,
|
||||
system, arch, in.Name, ldFlags, in.Extra,
|
||||
in.ExitWhenError,
|
||||
false,
|
||||
)
|
||||
}
|
||||
mlog.Debug(fmt.Sprintf("build for GOOS=%s GOARCH=%s", system, arch))
|
||||
mlog.Debug(cmd)
|
||||
// It's not necessary printing the complete command string.
|
||||
cmdShow, _ := gregex.ReplaceString(`\s+(-ldflags ".+?")\s+`, " ", cmd)
|
||||
mlog.Print(cmdShow)
|
||||
if result, err := gproc.ShellExec(ctx, cmd); err != nil {
|
||||
mlog.Printf(
|
||||
"failed to build, os:%s, arch:%s, error:\n%s\n\n%s\n",
|
||||
system, arch, gstr.Trim(result),
|
||||
`you may use command option "--debug" to enable debug info and check the details`,
|
||||
)
|
||||
if in.ExitWhenError {
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
mlog.Debug(gstr.Trim(result))
|
||||
}
|
||||
// single binary building.
|
||||
if len(customSystems) == 0 && len(customArches) == 0 {
|
||||
goto buildDone
|
||||
@ -322,6 +282,68 @@ buildDone:
|
||||
return
|
||||
}
|
||||
|
||||
func (c cBuild) doBinaryBuild(
|
||||
ctx context.Context,
|
||||
filePath string,
|
||||
outputPath, dirPath string,
|
||||
system, arch, name, ldFlags, extra string,
|
||||
exitWhenError bool,
|
||||
singleBuild bool,
|
||||
) {
|
||||
var (
|
||||
cmd string
|
||||
ext string
|
||||
)
|
||||
// Cross-building, output the compiled binary to specified path.
|
||||
if system == "windows" {
|
||||
ext = ".exe"
|
||||
}
|
||||
genv.MustSet("GOOS", system)
|
||||
genv.MustSet("GOARCH", arch)
|
||||
|
||||
if outputPath != "" {
|
||||
outputPath = "-o " + outputPath
|
||||
} else {
|
||||
if dirPath == "" {
|
||||
dirPath = "."
|
||||
} else {
|
||||
dirPath = gstr.TrimRight(dirPath, "/")
|
||||
}
|
||||
if singleBuild {
|
||||
outputPath = fmt.Sprintf(
|
||||
"-o %s/%s%s",
|
||||
dirPath, name, ext,
|
||||
)
|
||||
} else {
|
||||
outputPath = fmt.Sprintf(
|
||||
"-o %s/%s/%s%s",
|
||||
dirPath, system+"_"+arch, name, ext,
|
||||
)
|
||||
}
|
||||
}
|
||||
cmd = fmt.Sprintf(
|
||||
`go build %s -ldflags "%s" %s%s`,
|
||||
outputPath, ldFlags, extra, filePath,
|
||||
)
|
||||
mlog.Debug(fmt.Sprintf("build for GOOS=%s GOARCH=%s", system, arch))
|
||||
mlog.Debug(cmd)
|
||||
// It's not necessary printing the complete command string, filtering ldFlags.
|
||||
cmdShow, _ := gregex.ReplaceString(`\s+(-ldflags ".+?")\s+`, " ", cmd)
|
||||
mlog.Print(cmdShow)
|
||||
if result, err := gproc.ShellExec(ctx, cmd); err != nil {
|
||||
mlog.Printf(
|
||||
"failed to build, os:%s, arch:%s, error:\n%s\n\n%s\n",
|
||||
system, arch, gstr.Trim(result),
|
||||
`you may use command option "--debug" to enable debug info and check the details`,
|
||||
)
|
||||
if exitWhenError {
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
mlog.Debug(gstr.Trim(result))
|
||||
}
|
||||
}
|
||||
|
||||
// getBuildInVarStr retrieves and returns the custom build-in variables in configuration
|
||||
// file as json.
|
||||
func (c cBuild) getBuildInVarStr(ctx context.Context, in cBuildInput) string {
|
||||
|
||||
151
cmd/gf/internal/cmd/cmd_z_unit_build_test.go
Normal file
151
cmd/gf/internal/cmd/cmd_z_unit_build_test.go
Normal file
@ -0,0 +1,151 @@
|
||||
// Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
func Test_Build_Single(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `single`)
|
||||
pwd = gfile.Pwd()
|
||||
binaryName = `t.test`
|
||||
binaryPath = gtest.DataPath(`build`, `single`, binaryName)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPath), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
File: cBuildDefaultFile,
|
||||
Name: binaryName,
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPath), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Build_Single_Output(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `single`)
|
||||
pwd = gfile.Pwd()
|
||||
binaryName = `tt`
|
||||
binaryDirPath = gtest.DataPath(`build`, `single`, `tt`)
|
||||
binaryPath = gtest.DataPath(`build`, `single`, `tt`, binaryName)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryDirPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPath), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
Output: "./tt/tt",
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPath), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Build_Single_Path(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `single`)
|
||||
pwd = gfile.Pwd()
|
||||
dirName = "ttt"
|
||||
binaryName = `main`
|
||||
binaryDirPath = gtest.DataPath(`build`, `single`, dirName)
|
||||
binaryPath = gtest.DataPath(`build`, `single`, dirName, binaryName)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryDirPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPath), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
Path: "ttt",
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPath), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Build_Single_VarMap(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `varmap`)
|
||||
pwd = gfile.Pwd()
|
||||
binaryName = `main`
|
||||
binaryPath = gtest.DataPath(`build`, `varmap`, binaryName)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPath), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
VarMap: map[string]interface{}{
|
||||
"a": "1",
|
||||
"b": "2",
|
||||
},
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPath), true)
|
||||
|
||||
result, err := gproc.ShellExec(ctx, binaryPath)
|
||||
t.AssertNil(err)
|
||||
t.Assert(gstr.Contains(result, `a: 1`), true)
|
||||
t.Assert(gstr.Contains(result, `b: 2`), true)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Build_Multiple(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var (
|
||||
buildPath = gtest.DataPath(`build`, `multiple`)
|
||||
pwd = gfile.Pwd()
|
||||
binaryDirPath = gtest.DataPath(`build`, `multiple`, `temp`)
|
||||
binaryPathLinux = gtest.DataPath(`build`, `multiple`, `temp`, `v1.1`, `linux_amd64`, `ttt`)
|
||||
binaryPathWindows = gtest.DataPath(`build`, `multiple`, `temp`, `v1.1`, `windows_amd64`, `ttt.exe`)
|
||||
f = cBuild{}
|
||||
)
|
||||
defer gfile.Chdir(pwd)
|
||||
defer gfile.Remove(binaryDirPath)
|
||||
err := gfile.Chdir(buildPath)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(binaryPathLinux), false)
|
||||
t.Assert(gfile.Exists(binaryPathWindows), false)
|
||||
_, err = f.Index(ctx, cBuildInput{
|
||||
File: "multiple.go",
|
||||
Name: "ttt",
|
||||
Version: "v1.1",
|
||||
Arch: "amd64",
|
||||
System: "linux, windows",
|
||||
Path: "temp",
|
||||
})
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(binaryPathLinux), true)
|
||||
t.Assert(gfile.Exists(binaryPathWindows), true)
|
||||
})
|
||||
}
|
||||
@ -7,13 +7,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genctrl"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Gen_Ctrl_Default(t *testing.T) {
|
||||
|
||||
@ -7,13 +7,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genservice"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/util/guid"
|
||||
"github.com/gogf/gf/v2/util/gutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Gen_Service_Default(t *testing.T) {
|
||||
|
||||
@ -174,7 +174,7 @@ func (c CGenService) Service(ctx context.Context, in CGenServiceInput) (out *CGe
|
||||
// Parse single logic package folder.
|
||||
var (
|
||||
// StructName => FunctionDefinitions
|
||||
srcPkgInterfaceMap = make(map[string]*garray.StrArray)
|
||||
srcPkgInterfaceMap = gmap.NewListMap()
|
||||
srcImportedPackages = garray.NewSortedStrArray().SetUnique(true)
|
||||
importAliasToPathMap = gmap.NewStrStrMap() // for conflict imports check. alias => import path(with `"`)
|
||||
importPathToAliasMap = gmap.NewStrStrMap() // for conflict imports check. import path(with `"`) => alias
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"go/token"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
@ -99,10 +100,9 @@ func (c CGenService) calculateCodeCommented(in CGenServiceInput, fileContent str
|
||||
}
|
||||
|
||||
func (c CGenService) calculateInterfaceFunctions(
|
||||
in CGenServiceInput, fileContent string, srcPkgInterfaceMap map[string]*garray.StrArray,
|
||||
in CGenServiceInput, fileContent string, srcPkgInterfaceMap *gmap.ListMap,
|
||||
) (err error) {
|
||||
var (
|
||||
ok bool
|
||||
matches [][]string
|
||||
srcPkgInterfaceFuncArray *garray.StrArray
|
||||
)
|
||||
@ -142,9 +142,11 @@ func (c CGenService) calculateInterfaceFunctions(
|
||||
continue
|
||||
}
|
||||
structName = gstr.CaseCamel(structMatch[1])
|
||||
if srcPkgInterfaceFuncArray, ok = srcPkgInterfaceMap[structName]; !ok {
|
||||
srcPkgInterfaceMap[structName] = garray.NewStrArray()
|
||||
srcPkgInterfaceFuncArray = srcPkgInterfaceMap[structName]
|
||||
if !srcPkgInterfaceMap.Contains(structName) {
|
||||
srcPkgInterfaceFuncArray = garray.NewStrArray()
|
||||
srcPkgInterfaceMap.Set(structName, srcPkgInterfaceFuncArray)
|
||||
} else {
|
||||
srcPkgInterfaceFuncArray = srcPkgInterfaceMap.Get(structName).(*garray.StrArray)
|
||||
}
|
||||
srcPkgInterfaceFuncArray.Append(functionHead)
|
||||
}
|
||||
@ -165,8 +167,8 @@ func (c CGenService) calculateInterfaceFunctions(
|
||||
continue
|
||||
}
|
||||
structName = gstr.CaseCamel(structMatch[1])
|
||||
if srcPkgInterfaceFuncArray, ok = srcPkgInterfaceMap[structName]; !ok {
|
||||
srcPkgInterfaceMap[structName] = garray.NewStrArray()
|
||||
if !srcPkgInterfaceMap.Contains(structName) {
|
||||
srcPkgInterfaceMap.Set(structName, garray.NewStrArray())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/container/gmap"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/text/gregex"
|
||||
@ -23,7 +24,7 @@ import (
|
||||
type generateServiceFilesInput struct {
|
||||
CGenServiceInput
|
||||
DstFilePath string // Absolute file path for generated service go file.
|
||||
SrcStructFunctions map[string]*garray.StrArray
|
||||
SrcStructFunctions *gmap.ListMap
|
||||
SrcImportedPackages []string
|
||||
SrcPackageName string
|
||||
DstPackageName string
|
||||
@ -46,7 +47,8 @@ func (c CGenService) generateServiceFile(in generateServiceFilesInput) (ok bool,
|
||||
// Type definitions.
|
||||
generatedContent += "type("
|
||||
generatedContent += "\n"
|
||||
for structName, funcArray := range in.SrcStructFunctions {
|
||||
in.SrcStructFunctions.Iterator(func(key, value interface{}) bool {
|
||||
structName, funcArray := key.(string), value.(*garray.StrArray)
|
||||
allFuncArray.Append(funcArray.Slice()...)
|
||||
// Add comments to a method.
|
||||
for index, funcName := range funcArray.Slice() {
|
||||
@ -60,7 +62,8 @@ func (c CGenService) generateServiceFile(in generateServiceFilesInput) (ok bool,
|
||||
"{FuncDefinition}": funcArray.Join("\n\t"),
|
||||
}))
|
||||
generatedContent += "\n"
|
||||
}
|
||||
return true
|
||||
})
|
||||
generatedContent += ")"
|
||||
generatedContent += "\n"
|
||||
|
||||
@ -70,17 +73,19 @@ func (c CGenService) generateServiceFile(in generateServiceFilesInput) (ok bool,
|
||||
generatingInterfaceCheck string
|
||||
)
|
||||
// Variable definitions.
|
||||
for structName := range in.SrcStructFunctions {
|
||||
in.SrcStructFunctions.Iterator(func(key, value interface{}) bool {
|
||||
structName := key.(string)
|
||||
generatingInterfaceCheck = fmt.Sprintf(`[^\w\d]+%s.I%s[^\w\d]`, in.DstPackageName, structName)
|
||||
if gregex.IsMatchString(generatingInterfaceCheck, generatedContent) {
|
||||
continue
|
||||
return true
|
||||
}
|
||||
variableContent += gstr.Trim(gstr.ReplaceByMap(consts.TemplateGenServiceContentVariable, g.MapStrStr{
|
||||
"{StructName}": structName,
|
||||
"{InterfaceName}": "I" + structName,
|
||||
}))
|
||||
variableContent += "\n"
|
||||
}
|
||||
return true
|
||||
})
|
||||
if variableContent != "" {
|
||||
generatedContent += "var("
|
||||
generatedContent += "\n"
|
||||
@ -89,17 +94,19 @@ func (c CGenService) generateServiceFile(in generateServiceFilesInput) (ok bool,
|
||||
generatedContent += "\n"
|
||||
}
|
||||
// Variable register function definitions.
|
||||
for structName := range in.SrcStructFunctions {
|
||||
in.SrcStructFunctions.Iterator(func(key, value interface{}) bool {
|
||||
structName := key.(string)
|
||||
generatingInterfaceCheck = fmt.Sprintf(`[^\w\d]+%s.I%s[^\w\d]`, in.DstPackageName, structName)
|
||||
if gregex.IsMatchString(generatingInterfaceCheck, generatedContent) {
|
||||
continue
|
||||
return true
|
||||
}
|
||||
generatedContent += gstr.Trim(gstr.ReplaceByMap(consts.TemplateGenServiceContentRegister, g.MapStrStr{
|
||||
"{StructName}": structName,
|
||||
"{InterfaceName}": "I" + structName,
|
||||
}))
|
||||
generatedContent += "\n\n"
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
// Replace empty braces that have new line.
|
||||
generatedContent, _ = gregex.ReplaceString(`{[\s\t]+}`, `{}`, generatedContent)
|
||||
|
||||
5
cmd/gf/internal/cmd/testdata/build/multiple/multiple.go
vendored
Normal file
5
cmd/gf/internal/cmd/testdata/build/multiple/multiple.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
5
cmd/gf/internal/cmd/testdata/build/single/main.go
vendored
Normal file
5
cmd/gf/internal/cmd/testdata/build/single/main.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
12
cmd/gf/internal/cmd/testdata/build/varmap/go.mod
vendored
Normal file
12
cmd/gf/internal/cmd/testdata/build/varmap/go.mod
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
module github.com/gogf/gf/cmd/gf/cmd/gf/testdata/vardump/v2
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.6.1
|
||||
|
||||
require (
|
||||
go.opentelemetry.io/otel v1.14.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.14.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gogf/gf/v2 => ../../../../../../../
|
||||
27
cmd/gf/internal/cmd/testdata/build/varmap/go.sum
vendored
Normal file
27
cmd/gf/internal/cmd/testdata/build/varmap/go.sum
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/grokify/html-strip-tags-go v0.0.1 h1:0fThFwLbW7P/kOiTBs03FsJSV9RM2M/Q/MOnCQxKMo0=
|
||||
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||
go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM=
|
||||
go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU=
|
||||
go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY=
|
||||
go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M=
|
||||
go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8=
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
13
cmd/gf/internal/cmd/testdata/build/varmap/main.go
vendored
Normal file
13
cmd/gf/internal/cmd/testdata/build/varmap/main.go
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gbuild"
|
||||
)
|
||||
|
||||
func main() {
|
||||
for k, v := range gbuild.Data() {
|
||||
fmt.Printf("%s: %v\n", k, v)
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@ package article
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/cmd/testdata/genservice/service"
|
||||
)
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ package utils
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/tools/imports"
|
||||
|
||||
"github.com/gogf/gf/cmd/gf/v2/internal/consts"
|
||||
|
||||
@ -173,7 +173,11 @@ func (a *IntArray) InsertBefore(index int, values ...int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
|
||||
return gerror.NewCodef(
|
||||
gcode.CodeInvalidParameter,
|
||||
"index %d out of array range %d",
|
||||
index, len(a.array),
|
||||
)
|
||||
}
|
||||
rear := append([]int{}, a.array[index:]...)
|
||||
a.array = append(a.array[0:index], values...)
|
||||
@ -186,7 +190,11 @@ func (a *IntArray) InsertAfter(index int, values ...int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if index < 0 || index >= len(a.array) {
|
||||
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", index, len(a.array))
|
||||
return gerror.NewCodef(
|
||||
gcode.CodeInvalidParameter,
|
||||
"index %d out of array range %d",
|
||||
index, len(a.array),
|
||||
)
|
||||
}
|
||||
rear := append([]int{}, a.array[index+1:]...)
|
||||
a.array = append(a.array[0:index+1], values...)
|
||||
@ -583,7 +591,11 @@ func (a *IntArray) Fill(startIndex int, num int, value int) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if startIndex < 0 || startIndex > len(a.array) {
|
||||
return gerror.NewCodef(gcode.CodeInvalidParameter, "index %d out of array range %d", startIndex, len(a.array))
|
||||
return gerror.NewCodef(
|
||||
gcode.CodeInvalidParameter,
|
||||
"index %d out of array range %d",
|
||||
startIndex, len(a.array),
|
||||
)
|
||||
}
|
||||
for i := startIndex; i < startIndex+num; i++ {
|
||||
if i > len(a.array)-1 {
|
||||
|
||||
@ -75,7 +75,8 @@ func TestQueue_Close(t *testing.T) {
|
||||
q1 := gqueue.New()
|
||||
q1.Push(1)
|
||||
q1.Push(2)
|
||||
time.Sleep(time.Millisecond)
|
||||
// wait sync to channel
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
t.Assert(q1.Len(), 2)
|
||||
q1.Close()
|
||||
})
|
||||
@ -83,7 +84,8 @@ func TestQueue_Close(t *testing.T) {
|
||||
q1 := gqueue.New(2)
|
||||
q1.Push(1)
|
||||
q1.Push(2)
|
||||
time.Sleep(time.Millisecond)
|
||||
// wait sync to channel
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
t.Assert(q1.Len(), 2)
|
||||
q1.Close()
|
||||
})
|
||||
|
||||
@ -42,7 +42,7 @@ func ExampleIntSet_Add() {
|
||||
fmt.Println(intSet.Slice())
|
||||
fmt.Println(intSet.AddIfNotExist(1))
|
||||
|
||||
// Mya Output:
|
||||
// May Output:
|
||||
// [1 2 3]
|
||||
// false
|
||||
}
|
||||
@ -56,7 +56,7 @@ func ExampleIntSet_AddIfNotExist() {
|
||||
fmt.Println(intSet.Slice())
|
||||
fmt.Println(intSet.AddIfNotExist(1))
|
||||
|
||||
// Mya Output:
|
||||
// May Output:
|
||||
// [1 2 3]
|
||||
// false
|
||||
}
|
||||
|
||||
@ -42,13 +42,13 @@ func ExampleStrSet_Add() {
|
||||
fmt.Println(strSet.Slice())
|
||||
fmt.Println(strSet.AddIfNotExist("str"))
|
||||
|
||||
// Mya Output:
|
||||
// May Output:
|
||||
// [str str1 str2 str3]
|
||||
// false
|
||||
}
|
||||
|
||||
// AddIfNotExist checks whether item exists in the set,
|
||||
// it adds the item to set and returns true if it does not exists in the set,
|
||||
// it adds the item to set and returns true if it does not exist in the set,
|
||||
// or else it does nothing and returns false.
|
||||
func ExampleStrSet_AddIfNotExist() {
|
||||
strSet := gset.NewStrSetFrom([]string{"str1", "str2", "str3"}, true)
|
||||
@ -56,13 +56,13 @@ func ExampleStrSet_AddIfNotExist() {
|
||||
fmt.Println(strSet.Slice())
|
||||
fmt.Println(strSet.AddIfNotExist("str"))
|
||||
|
||||
// Mya Output:
|
||||
// May Output:
|
||||
// [str str1 str2 str3]
|
||||
// false
|
||||
}
|
||||
|
||||
// AddIfNotExistFunc checks whether item exists in the set,
|
||||
// it adds the item to set and returns true if it does not exists in the set and function `f` returns true,
|
||||
// it adds the item to set and returns true if it does not exist in the set and function `f` returns true,
|
||||
// or else it does nothing and returns false.
|
||||
// Note that, the function `f` is executed without writing lock.
|
||||
func ExampleStrSet_AddIfNotExistFunc() {
|
||||
@ -79,7 +79,7 @@ func ExampleStrSet_AddIfNotExistFunc() {
|
||||
}
|
||||
|
||||
// AddIfNotExistFunc checks whether item exists in the set,
|
||||
// it adds the item to set and returns true if it does not exists in the set and function `f` returns true,
|
||||
// it adds the item to set and returns true if it does not exist in the set and function `f` returns true,
|
||||
// or else it does nothing and returns false.
|
||||
// Note that, the function `f` is executed without writing lock.
|
||||
func ExampleStrSet_AddIfNotExistFuncLock() {
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/apolloconfig/agollo/v4 v4.3.1
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/consul/v2
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/hashicorp/consul/api v1.24.0
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2
|
||||
)
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/kubecm/v2
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
k8s.io/api v0.27.4
|
||||
k8s.io/apimachinery v0.27.4
|
||||
k8s.io/client-go v0.27.4
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/nacos/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/nacos-group/nacos-sdk-go v1.1.4
|
||||
)
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/polaris/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/polarismesh/polaris-go v1.5.5
|
||||
)
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.0.15
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/shopspring/decimal v1.3.1
|
||||
)
|
||||
|
||||
@ -6,7 +6,7 @@ replace github.com/gogf/gf/v2 => ../../../
|
||||
|
||||
require (
|
||||
gitee.com/chunanyong/dm v1.8.12
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/denisenkom/go-mssqldb v0.12.3
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/oracle/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/sijms/go-ora/v2 v2.7.10
|
||||
)
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/pgsql/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/lib/pq v1.10.9
|
||||
)
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/glebarez/go-sqlite v1.21.2
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/sqlitecgo/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/mattn/go-sqlite3 v1.14.17
|
||||
)
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/nosql/redis/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/redis/go-redis/v9 v9.2.1
|
||||
go.opentelemetry.io/otel v1.14.0
|
||||
go.opentelemetry.io/otel/trace v1.14.0
|
||||
|
||||
@ -8,20 +8,19 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/database/gredis"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
// Redis is an implement of Adapter using go-redis.
|
||||
type Redis struct {
|
||||
gredis.AdapterOperation
|
||||
|
||||
client redis.UniversalClient
|
||||
config *gredis.Config
|
||||
}
|
||||
@ -75,40 +74,12 @@ func New(config *gredis.Config) *Redis {
|
||||
client = redis.NewClient(opts.Simple())
|
||||
}
|
||||
|
||||
return &Redis{
|
||||
r := &Redis{
|
||||
client: client,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
// Do send a command to the server and returns the received reply.
|
||||
// It uses json.Marshal for struct/slice/map type values before committing them to redis.
|
||||
func (r *Redis) Do(ctx context.Context, command string, args ...interface{}) (*gvar.Var, error) {
|
||||
conn, err := r.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = conn.Close(ctx)
|
||||
}()
|
||||
return conn.Do(ctx, command, args...)
|
||||
}
|
||||
|
||||
// Close closes the redis connection pool, which will release all connections reserved by this pool.
|
||||
// It is commonly not necessary to call Close manually.
|
||||
func (r *Redis) Close(ctx context.Context) (err error) {
|
||||
if err = r.client.Close(); err != nil {
|
||||
err = gerror.Wrap(err, `Redis Client Close failed`)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Conn retrieves and returns a connection object for continuous operations.
|
||||
// Note that you should call Close function manually if you do not use this connection any further.
|
||||
func (r *Redis) Conn(ctx context.Context) (gredis.Conn, error) {
|
||||
return &Conn{
|
||||
redis: r,
|
||||
}, nil
|
||||
r.AdapterOperation = r
|
||||
return r
|
||||
}
|
||||
|
||||
func fillWithDefaultConfiguration(config *gredis.Config) {
|
||||
|
||||
@ -18,13 +18,13 @@ import (
|
||||
|
||||
// GroupGeneric provides generic functions of redis.
|
||||
type GroupGeneric struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupGeneric creates and returns GroupGeneric.
|
||||
func (r *Redis) GroupGeneric() gredis.IGroupGeneric {
|
||||
return GroupGeneric{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ func (r GroupGeneric) Copy(ctx context.Context, source, destination string, opti
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "Copy", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "Copy", mustMergeOptionToArgs(
|
||||
[]interface{}{source, destination}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -59,7 +59,7 @@ func (r GroupGeneric) Copy(ctx context.Context, source, destination string, opti
|
||||
//
|
||||
// https://redis.io/commands/exists/
|
||||
func (r GroupGeneric) Exists(ctx context.Context, keys ...string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Exists", gconv.Interfaces(keys)...)
|
||||
v, err := r.Operation.Do(ctx, "Exists", gconv.Interfaces(keys)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func (r GroupGeneric) Exists(ctx context.Context, keys ...string) (int64, error)
|
||||
//
|
||||
// https://redis.io/commands/type/
|
||||
func (r GroupGeneric) Type(ctx context.Context, key string) (string, error) {
|
||||
v, err := r.redis.Do(ctx, "Type", key)
|
||||
v, err := r.Operation.Do(ctx, "Type", key)
|
||||
return v.String(), err
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ func (r GroupGeneric) Type(ctx context.Context, key string) (string, error) {
|
||||
//
|
||||
// https://redis.io/commands/unlink/
|
||||
func (r GroupGeneric) Unlink(ctx context.Context, keys ...string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Unlink", gconv.Interfaces(keys)...)
|
||||
v, err := r.Operation.Do(ctx, "Unlink", gconv.Interfaces(keys)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ func (r GroupGeneric) Unlink(ctx context.Context, keys ...string) (int64, error)
|
||||
//
|
||||
// https://redis.io/commands/rename/
|
||||
func (r GroupGeneric) Rename(ctx context.Context, key, newKey string) error {
|
||||
_, err := r.redis.Do(ctx, "Rename", key, newKey)
|
||||
_, err := r.Operation.Do(ctx, "Rename", key, newKey)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ func (r GroupGeneric) Rename(ctx context.Context, key, newKey string) error {
|
||||
//
|
||||
// https://redis.io/commands/renamenx/
|
||||
func (r GroupGeneric) RenameNX(ctx context.Context, key, newKey string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "RenameNX", key, newKey)
|
||||
v, err := r.Operation.Do(ctx, "RenameNX", key, newKey)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ func (r GroupGeneric) RenameNX(ctx context.Context, key, newKey string) (int64,
|
||||
//
|
||||
// https://redis.io/commands/move/
|
||||
func (r GroupGeneric) Move(ctx context.Context, key string, db int) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Move", key, db)
|
||||
v, err := r.Operation.Do(ctx, "Move", key, db)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ func (r GroupGeneric) Move(ctx context.Context, key string, db int) (int64, erro
|
||||
//
|
||||
// https://redis.io/commands/del/
|
||||
func (r GroupGeneric) Del(ctx context.Context, keys ...string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Del", gconv.Interfaces(keys)...)
|
||||
v, err := r.Operation.Do(ctx, "Del", gconv.Interfaces(keys)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ func (r GroupGeneric) Del(ctx context.Context, keys ...string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/randomkey/
|
||||
func (r GroupGeneric) RandomKey(ctx context.Context) (string, error) {
|
||||
v, err := r.redis.Do(ctx, "RandomKey")
|
||||
v, err := r.Operation.Do(ctx, "RandomKey")
|
||||
return v.String(), err
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func (r GroupGeneric) RandomKey(ctx context.Context) (string, error) {
|
||||
//
|
||||
// https://redis.io/commands/dbsize/
|
||||
func (r GroupGeneric) DBSize(ctx context.Context) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "DBSize")
|
||||
v, err := r.Operation.Do(ctx, "DBSize")
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ func (r GroupGeneric) DBSize(ctx context.Context) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/keys/
|
||||
func (r GroupGeneric) Keys(ctx context.Context, pattern string) ([]string, error) {
|
||||
v, err := r.redis.Do(ctx, "Keys", pattern)
|
||||
v, err := r.Operation.Do(ctx, "Keys", pattern)
|
||||
return v.Strings(), err
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ func (r GroupGeneric) Keys(ctx context.Context, pattern string) ([]string, error
|
||||
//
|
||||
// https://redis.io/commands/flushdb/
|
||||
func (r GroupGeneric) FlushDB(ctx context.Context, option ...gredis.FlushOp) error {
|
||||
_, err := r.redis.Do(ctx, "FlushDB", gconv.Interfaces(option)...)
|
||||
_, err := r.Operation.Do(ctx, "FlushDB", gconv.Interfaces(option)...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ func (r GroupGeneric) FlushDB(ctx context.Context, option ...gredis.FlushOp) err
|
||||
//
|
||||
// https://redis.io/commands/flushall/
|
||||
func (r GroupGeneric) FlushAll(ctx context.Context, option ...gredis.FlushOp) error {
|
||||
_, err := r.redis.Do(ctx, "FlushAll", gconv.Interfaces(option)...)
|
||||
_, err := r.Operation.Do(ctx, "FlushAll", gconv.Interfaces(option)...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ func (r GroupGeneric) Expire(ctx context.Context, key string, seconds int64, opt
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "Expire", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "Expire", mustMergeOptionToArgs(
|
||||
[]interface{}{key, seconds}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -229,7 +229,7 @@ func (r GroupGeneric) ExpireAt(ctx context.Context, key string, time time.Time,
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "ExpireAt", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "ExpireAt", mustMergeOptionToArgs(
|
||||
[]interface{}{key, gtime.New(time).Timestamp()}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -243,7 +243,7 @@ func (r GroupGeneric) ExpireAt(ctx context.Context, key string, time time.Time,
|
||||
//
|
||||
// https://redis.io/commands/expiretime/
|
||||
func (r GroupGeneric) ExpireTime(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "ExpireTime", key)
|
||||
return r.Operation.Do(ctx, "ExpireTime", key)
|
||||
}
|
||||
|
||||
// TTL returns the remaining time to live of a key that has a timeout.
|
||||
@ -263,7 +263,7 @@ func (r GroupGeneric) ExpireTime(ctx context.Context, key string) (*gvar.Var, er
|
||||
//
|
||||
// https://redis.io/commands/ttl/
|
||||
func (r GroupGeneric) TTL(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "TTL", key)
|
||||
v, err := r.Operation.Do(ctx, "TTL", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ func (r GroupGeneric) TTL(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/persist/
|
||||
func (r GroupGeneric) Persist(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Persist", key)
|
||||
v, err := r.Operation.Do(ctx, "Persist", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ func (r GroupGeneric) PExpire(ctx context.Context, key string, milliseconds int6
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "PExpire", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "PExpire", mustMergeOptionToArgs(
|
||||
[]interface{}{key, milliseconds}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -308,7 +308,7 @@ func (r GroupGeneric) PExpireAt(ctx context.Context, key string, time time.Time,
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "PExpireAt", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "PExpireAt", mustMergeOptionToArgs(
|
||||
[]interface{}{key, gtime.New(time).TimestampMilli()}, usedOption,
|
||||
)...)
|
||||
return v.Int64(), err
|
||||
@ -322,7 +322,7 @@ func (r GroupGeneric) PExpireAt(ctx context.Context, key string, time time.Time,
|
||||
//
|
||||
// https://redis.io/commands/pexpiretime/
|
||||
func (r GroupGeneric) PExpireTime(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "PExpireTime", key)
|
||||
return r.Operation.Do(ctx, "PExpireTime", key)
|
||||
}
|
||||
|
||||
// PTTL like TTL this command returns the remaining time to live of a key that has an expired set,
|
||||
@ -336,6 +336,6 @@ func (r GroupGeneric) PExpireTime(ctx context.Context, key string) (*gvar.Var, e
|
||||
//
|
||||
// https://redis.io/commands/pttl/
|
||||
func (r GroupGeneric) PTTL(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "PTTL", key)
|
||||
v, err := r.Operation.Do(ctx, "PTTL", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupHash is the redis group object for hash operations.
|
||||
type GroupHash struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupHash creates and returns a redis group object for hash operations.
|
||||
func (r *Redis) GroupHash() gredis.IGroupHash {
|
||||
return GroupHash{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ func (r GroupHash) HSet(ctx context.Context, key string, fields map[string]inter
|
||||
for k, v := range fields {
|
||||
s = append(s, k, v)
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "HSet", s...)
|
||||
v, err := r.Operation.Do(ctx, "HSet", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ func (r GroupHash) HSet(ctx context.Context, key string, fields map[string]inter
|
||||
//
|
||||
// https://redis.io/commands/hsetnx/
|
||||
func (r GroupHash) HSetNX(ctx context.Context, key, field string, value interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HSetNX", key, field, value)
|
||||
v, err := r.Operation.Do(ctx, "HSetNX", key, field, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ func (r GroupHash) HSetNX(ctx context.Context, key, field string, value interfac
|
||||
//
|
||||
// https://redis.io/commands/hget/
|
||||
func (r GroupHash) HGet(ctx context.Context, key, field string) (*gvar.Var, error) {
|
||||
v, err := r.redis.Do(ctx, "HGet", key, field)
|
||||
v, err := r.Operation.Do(ctx, "HGet", key, field)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ func (r GroupHash) HGet(ctx context.Context, key, field string) (*gvar.Var, erro
|
||||
//
|
||||
// https://redis.io/commands/hstrlen/
|
||||
func (r GroupHash) HStrLen(ctx context.Context, key, field string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HSTRLEN", key, field)
|
||||
v, err := r.Operation.Do(ctx, "HSTRLEN", key, field)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ func (r GroupHash) HStrLen(ctx context.Context, key, field string) (int64, error
|
||||
//
|
||||
// https://redis.io/commands/hexists/
|
||||
func (r GroupHash) HExists(ctx context.Context, key, field string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HExists", key, field)
|
||||
v, err := r.Operation.Do(ctx, "HExists", key, field)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ func (r GroupHash) HExists(ctx context.Context, key, field string) (int64, error
|
||||
//
|
||||
// https://redis.io/commands/hdel/
|
||||
func (r GroupHash) HDel(ctx context.Context, key string, fields ...string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HDel", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
|
||||
v, err := r.Operation.Do(ctx, "HDel", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ func (r GroupHash) HDel(ctx context.Context, key string, fields ...string) (int6
|
||||
//
|
||||
// https://redis.io/commands/hlen/
|
||||
func (r GroupHash) HLen(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HLen", key)
|
||||
v, err := r.Operation.Do(ctx, "HLen", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ func (r GroupHash) HLen(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/hincrby/
|
||||
func (r GroupHash) HIncrBy(ctx context.Context, key, field string, increment int64) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "HIncrBy", key, field, increment)
|
||||
v, err := r.Operation.Do(ctx, "HIncrBy", key, field, increment)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ func (r GroupHash) HIncrBy(ctx context.Context, key, field string, increment int
|
||||
//
|
||||
// https://redis.io/commands/hincrbyfloat/
|
||||
func (r GroupHash) HIncrByFloat(ctx context.Context, key, field string, increment float64) (float64, error) {
|
||||
v, err := r.redis.Do(ctx, "HIncrByFloat", key, field, increment)
|
||||
v, err := r.Operation.Do(ctx, "HIncrByFloat", key, field, increment)
|
||||
return v.Float64(), err
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ func (r GroupHash) HMSet(ctx context.Context, key string, fields map[string]inte
|
||||
for k, v := range fields {
|
||||
s = append(s, k, v)
|
||||
}
|
||||
_, err := r.redis.Do(ctx, "HMSet", s...)
|
||||
_, err := r.Operation.Do(ctx, "HMSet", s...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ func (r GroupHash) HMSet(ctx context.Context, key string, fields map[string]inte
|
||||
//
|
||||
// https://redis.io/commands/hmget/
|
||||
func (r GroupHash) HMGet(ctx context.Context, key string, fields ...string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "HMGet", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
|
||||
v, err := r.Operation.Do(ctx, "HMGet", append([]interface{}{key}, gconv.Interfaces(fields)...)...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ func (r GroupHash) HMGet(ctx context.Context, key string, fields ...string) (gva
|
||||
//
|
||||
// https://redis.io/commands/hkeys/
|
||||
func (r GroupHash) HKeys(ctx context.Context, key string) ([]string, error) {
|
||||
v, err := r.redis.Do(ctx, "HKeys", key)
|
||||
v, err := r.Operation.Do(ctx, "HKeys", key)
|
||||
return v.Strings(), err
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ func (r GroupHash) HKeys(ctx context.Context, key string) ([]string, error) {
|
||||
//
|
||||
// https://redis.io/commands/hvals/
|
||||
func (r GroupHash) HVals(ctx context.Context, key string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "HVals", key)
|
||||
v, err := r.Operation.Do(ctx, "HVals", key)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -189,6 +189,6 @@ func (r GroupHash) HVals(ctx context.Context, key string) (gvar.Vars, error) {
|
||||
//
|
||||
// https://redis.io/commands/hgetall/
|
||||
func (r GroupHash) HGetAll(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
v, err := r.redis.Do(ctx, "HGetAll", key)
|
||||
v, err := r.Operation.Do(ctx, "HGetAll", key)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupList is the redis group list object.
|
||||
type GroupList struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupList creates and returns a redis group object for list operations.
|
||||
func (r *Redis) GroupList() gredis.IGroupList {
|
||||
return GroupList{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ func (r *Redis) GroupList() gredis.IGroupList {
|
||||
//
|
||||
// https://redis.io/commands/lpush/
|
||||
func (r GroupList) LPush(ctx context.Context, key string, values ...interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LPush", append([]interface{}{key}, values...)...)
|
||||
v, err := r.Operation.Do(ctx, "LPush", append([]interface{}{key}, values...)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ func (r GroupList) LPush(ctx context.Context, key string, values ...interface{})
|
||||
//
|
||||
// https://redis.io/commands/lpushx
|
||||
func (r GroupList) LPushX(ctx context.Context, key string, element interface{}, elements ...interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LPushX", append([]interface{}{key, element}, elements...)...)
|
||||
v, err := r.Operation.Do(ctx, "LPushX", append([]interface{}{key, element}, elements...)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ func (r GroupList) LPushX(ctx context.Context, key string, element interface{},
|
||||
//
|
||||
// https://redis.io/commands/rpush
|
||||
func (r GroupList) RPush(ctx context.Context, key string, values ...interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "RPush", append([]interface{}{key}, values...)...)
|
||||
v, err := r.Operation.Do(ctx, "RPush", append([]interface{}{key}, values...)...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ func (r GroupList) RPush(ctx context.Context, key string, values ...interface{})
|
||||
//
|
||||
// https://redis.io/commands/rpushx
|
||||
func (r GroupList) RPushX(ctx context.Context, key string, value interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "RPushX", key, value)
|
||||
v, err := r.Operation.Do(ctx, "RPushX", key, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -103,9 +103,9 @@ func (r GroupList) RPushX(ctx context.Context, key string, value interface{}) (i
|
||||
// https://redis.io/commands/lpop
|
||||
func (r GroupList) LPop(ctx context.Context, key string, count ...int) (*gvar.Var, error) {
|
||||
if len(count) > 0 {
|
||||
return r.redis.Do(ctx, "LPop", key, count[0])
|
||||
return r.Operation.Do(ctx, "LPop", key, count[0])
|
||||
}
|
||||
return r.redis.Do(ctx, "LPop", key)
|
||||
return r.Operation.Do(ctx, "LPop", key)
|
||||
}
|
||||
|
||||
// RPop remove and returns the last element of the list stored at key.
|
||||
@ -126,9 +126,9 @@ func (r GroupList) LPop(ctx context.Context, key string, count ...int) (*gvar.Va
|
||||
// https://redis.io/commands/rpop
|
||||
func (r GroupList) RPop(ctx context.Context, key string, count ...int) (*gvar.Var, error) {
|
||||
if len(count) > 0 {
|
||||
return r.redis.Do(ctx, "RPop", key, count[0])
|
||||
return r.Operation.Do(ctx, "RPop", key, count[0])
|
||||
}
|
||||
return r.redis.Do(ctx, "RPop", key)
|
||||
return r.Operation.Do(ctx, "RPop", key)
|
||||
}
|
||||
|
||||
// LRem removes the first count occurrences of elements equal to value from the list stored at key.
|
||||
@ -137,7 +137,7 @@ func (r GroupList) RPop(ctx context.Context, key string, count ...int) (*gvar.Va
|
||||
//
|
||||
// https://redis.io/commands/lrem/
|
||||
func (r GroupList) LRem(ctx context.Context, key string, count int64, value interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LRem", key, count, value)
|
||||
v, err := r.Operation.Do(ctx, "LRem", key, count, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ func (r GroupList) LRem(ctx context.Context, key string, count int64, value inte
|
||||
//
|
||||
// https://redis.io/commands/llen
|
||||
func (r GroupList) LLen(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LLen", key)
|
||||
v, err := r.Operation.Do(ctx, "LLen", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ func (r GroupList) LLen(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/lindex
|
||||
func (r GroupList) LIndex(ctx context.Context, key string, index int64) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "LIndex", key, index)
|
||||
return r.Operation.Do(ctx, "LIndex", key, index)
|
||||
}
|
||||
|
||||
// LInsert inserts element in the list stored at key either before or after the reference value pivot.
|
||||
@ -174,7 +174,7 @@ func (r GroupList) LIndex(ctx context.Context, key string, index int64) (*gvar.V
|
||||
//
|
||||
// https://redis.io/commands/linsert/
|
||||
func (r GroupList) LInsert(ctx context.Context, key string, op gredis.LInsertOp, pivot, value interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "LInsert", key, string(op), pivot, value)
|
||||
v, err := r.Operation.Do(ctx, "LInsert", key, string(op), pivot, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ func (r GroupList) LInsert(ctx context.Context, key string, op gredis.LInsertOp,
|
||||
//
|
||||
// https://redis.io/commands/lset/
|
||||
func (r GroupList) LSet(ctx context.Context, key string, index int64, value interface{}) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "LSet", key, index, value)
|
||||
return r.Operation.Do(ctx, "LSet", key, index, value)
|
||||
}
|
||||
|
||||
// LRange returns the specified elements of the list stored at key.
|
||||
@ -196,7 +196,7 @@ func (r GroupList) LSet(ctx context.Context, key string, index int64, value inte
|
||||
//
|
||||
// https://redis.io/commands/lrange/
|
||||
func (r GroupList) LRange(ctx context.Context, key string, start, stop int64) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "LRange", key, start, stop)
|
||||
v, err := r.Operation.Do(ctx, "LRange", key, start, stop)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ func (r GroupList) LRange(ctx context.Context, key string, start, stop int64) (g
|
||||
//
|
||||
// https://redis.io/commands/ltrim/
|
||||
func (r GroupList) LTrim(ctx context.Context, key string, start, stop int64) error {
|
||||
_, err := r.redis.Do(ctx, "LTrim", key, start, stop)
|
||||
_, err := r.Operation.Do(ctx, "LTrim", key, start, stop)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ func (r GroupList) LTrim(ctx context.Context, key string, start, stop int64) err
|
||||
//
|
||||
// https://redis.io/commands/blpop/
|
||||
func (r GroupList) BLPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "BLPop", append(gconv.Interfaces(keys), timeout)...)
|
||||
v, err := r.Operation.Do(ctx, "BLPop", append(gconv.Interfaces(keys), timeout)...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ func (r GroupList) BLPop(ctx context.Context, timeout int64, keys ...string) (gv
|
||||
//
|
||||
// https://redis.io/commands/brpop/
|
||||
func (r GroupList) BRPop(ctx context.Context, timeout int64, keys ...string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "BRPop", append(gconv.Interfaces(keys), timeout)...)
|
||||
v, err := r.Operation.Do(ctx, "BRPop", append(gconv.Interfaces(keys), timeout)...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ func (r GroupList) BRPop(ctx context.Context, timeout int64, keys ...string) (gv
|
||||
//
|
||||
// https://redis.io/commands/rpoplpush/
|
||||
func (r GroupList) RPopLPush(ctx context.Context, source, destination string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "RPopLPush", source, destination)
|
||||
return r.Operation.Do(ctx, "RPopLPush", source, destination)
|
||||
}
|
||||
|
||||
// BRPopLPush is the blocking variant of RPopLPush.
|
||||
@ -259,5 +259,5 @@ func (r GroupList) RPopLPush(ctx context.Context, source, destination string) (*
|
||||
//
|
||||
// https://redis.io/commands/brpoplpush/
|
||||
func (r GroupList) BRPopLPush(ctx context.Context, source, destination string, timeout int64) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "BRPopLPush", source, destination, timeout)
|
||||
return r.Operation.Do(ctx, "BRPopLPush", source, destination, timeout)
|
||||
}
|
||||
|
||||
@ -14,13 +14,13 @@ import (
|
||||
|
||||
// GroupPubSub provides pub/sub functions for redis.
|
||||
type GroupPubSub struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupPubSub creates and returns GroupPubSub.
|
||||
func (r *Redis) GroupPubSub() gredis.IGroupPubSub {
|
||||
return GroupPubSub{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ func (r *Redis) GroupPubSub() gredis.IGroupPubSub {
|
||||
//
|
||||
// https://redis.io/commands/publish/
|
||||
func (r GroupPubSub) Publish(ctx context.Context, channel string, message interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Publish", channel, message)
|
||||
v, err := r.Operation.Do(ctx, "Publish", channel, message)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ func (r GroupPubSub) Publish(ctx context.Context, channel string, message interf
|
||||
func (r GroupPubSub) Subscribe(
|
||||
ctx context.Context, channel string, channels ...string,
|
||||
) (gredis.Conn, []*gredis.Subscription, error) {
|
||||
conn, err := r.redis.Conn(ctx)
|
||||
conn, err := r.Operation.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -70,7 +70,7 @@ func (r GroupPubSub) Subscribe(
|
||||
func (r GroupPubSub) PSubscribe(
|
||||
ctx context.Context, pattern string, patterns ...string,
|
||||
) (gredis.Conn, []*gredis.Subscription, error) {
|
||||
conn, err := r.redis.Conn(ctx)
|
||||
conn, err := r.Operation.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupScript provides script functions for redis.
|
||||
type GroupScript struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupScript creates and returns GroupScript.
|
||||
func (r *Redis) GroupScript() gredis.IGroupScript {
|
||||
return GroupScript{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ func (r GroupScript) Eval(ctx context.Context, script string, numKeys int64, key
|
||||
var s = []interface{}{script, numKeys}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
s = append(s, args...)
|
||||
v, err := r.redis.Do(ctx, "Eval", s...)
|
||||
v, err := r.Operation.Do(ctx, "Eval", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ func (r GroupScript) EvalSha(ctx context.Context, sha1 string, numKeys int64, ke
|
||||
var s = []interface{}{sha1, numKeys}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
s = append(s, args...)
|
||||
v, err := r.redis.Do(ctx, "EvalSha", s...)
|
||||
v, err := r.Operation.Do(ctx, "EvalSha", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ func (r GroupScript) EvalSha(ctx context.Context, sha1 string, numKeys int64, ke
|
||||
//
|
||||
// https://redis.io/commands/script-load/
|
||||
func (r GroupScript) ScriptLoad(ctx context.Context, script string) (string, error) {
|
||||
v, err := r.redis.Do(ctx, "Script", "Load", script)
|
||||
v, err := r.Operation.Do(ctx, "Script", "Load", script)
|
||||
return v.String(), err
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ func (r GroupScript) ScriptExists(ctx context.Context, sha1 string, sha1s ...str
|
||||
)
|
||||
s = append(s, "Exists")
|
||||
s = append(s, sha1Array...)
|
||||
result, err := r.redis.Do(ctx, "Script", s...)
|
||||
result, err := r.Operation.Do(ctx, "Script", s...)
|
||||
var (
|
||||
m = make(map[string]bool)
|
||||
resultArray = result.Vars()
|
||||
@ -99,7 +99,7 @@ func (r GroupScript) ScriptFlush(ctx context.Context, option ...gredis.ScriptFlu
|
||||
s = append(s, mustMergeOptionToArgs(
|
||||
[]interface{}{}, usedOption,
|
||||
)...)
|
||||
_, err := r.redis.Do(ctx, "Script", s...)
|
||||
_, err := r.Operation.Do(ctx, "Script", s...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -108,6 +108,6 @@ func (r GroupScript) ScriptFlush(ctx context.Context, option ...gredis.ScriptFlu
|
||||
//
|
||||
// https://redis.io/commands/script-kill/
|
||||
func (r GroupScript) ScriptKill(ctx context.Context) error {
|
||||
_, err := r.redis.Do(ctx, "Script", "Kill")
|
||||
_, err := r.Operation.Do(ctx, "Script", "Kill")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupSet provides set functions for redis.
|
||||
type GroupSet struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupSet creates and returns GroupSet.
|
||||
func (r *Redis) GroupSet() gredis.IGroupSet {
|
||||
return GroupSet{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ func (r GroupSet) SAdd(ctx context.Context, key string, member interface{}, memb
|
||||
var s = []interface{}{key}
|
||||
s = append(s, member)
|
||||
s = append(s, members...)
|
||||
v, err := r.redis.Do(ctx, "SAdd", s...)
|
||||
v, err := r.Operation.Do(ctx, "SAdd", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ func (r GroupSet) SAdd(ctx context.Context, key string, member interface{}, memb
|
||||
//
|
||||
// https://redis.io/commands/sismember/
|
||||
func (r GroupSet) SIsMember(ctx context.Context, key string, member interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "SIsMember", key, member)
|
||||
v, err := r.Operation.Do(ctx, "SIsMember", key, member)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ func (r GroupSet) SIsMember(ctx context.Context, key string, member interface{})
|
||||
func (r GroupSet) SPop(ctx context.Context, key string, count ...int) (*gvar.Var, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(count)...)
|
||||
v, err := r.redis.Do(ctx, "SPop", s...)
|
||||
v, err := r.Operation.Do(ctx, "SPop", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func (r GroupSet) SPop(ctx context.Context, key string, count ...int) (*gvar.Var
|
||||
func (r GroupSet) SRandMember(ctx context.Context, key string, count ...int) (*gvar.Var, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(count)...)
|
||||
v, err := r.redis.Do(ctx, "SRandMember", s...)
|
||||
v, err := r.Operation.Do(ctx, "SRandMember", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ func (r GroupSet) SRem(ctx context.Context, key string, member interface{}, memb
|
||||
var s = []interface{}{key}
|
||||
s = append(s, member)
|
||||
s = append(s, members...)
|
||||
v, err := r.redis.Do(ctx, "SRem", s...)
|
||||
v, err := r.Operation.Do(ctx, "SRem", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ func (r GroupSet) SRem(ctx context.Context, key string, member interface{}, memb
|
||||
//
|
||||
// https://redis.io/commands/smove/
|
||||
func (r GroupSet) SMove(ctx context.Context, source, destination string, member interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "SMove", source, destination, member)
|
||||
v, err := r.Operation.Do(ctx, "SMove", source, destination, member)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ func (r GroupSet) SMove(ctx context.Context, source, destination string, member
|
||||
//
|
||||
// https://redis.io/commands/scard/
|
||||
func (r GroupSet) SCard(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "SCard", key)
|
||||
v, err := r.Operation.Do(ctx, "SCard", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ func (r GroupSet) SCard(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/smembers/
|
||||
func (r GroupSet) SMembers(ctx context.Context, key string) (gvar.Vars, error) {
|
||||
v, err := r.redis.Do(ctx, "SMembers", key)
|
||||
v, err := r.Operation.Do(ctx, "SMembers", key)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ func (r GroupSet) SMembers(ctx context.Context, key string) (gvar.Vars, error) {
|
||||
func (r GroupSet) SMIsMember(ctx context.Context, key, member interface{}, members ...interface{}) ([]int, error) {
|
||||
var s = []interface{}{key, member}
|
||||
s = append(s, members...)
|
||||
v, err := r.redis.Do(ctx, "SMIsMember", s...)
|
||||
v, err := r.Operation.Do(ctx, "SMIsMember", s...)
|
||||
return v.Ints(), err
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ func (r GroupSet) SMIsMember(ctx context.Context, key, member interface{}, membe
|
||||
func (r GroupSet) SInter(ctx context.Context, key string, keys ...string) (gvar.Vars, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SInter", s...)
|
||||
v, err := r.Operation.Do(ctx, "SInter", s...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ func (r GroupSet) SInter(ctx context.Context, key string, keys ...string) (gvar.
|
||||
func (r GroupSet) SInterStore(ctx context.Context, destination string, key string, keys ...string) (int64, error) {
|
||||
var s = []interface{}{destination, key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SInterStore", s...)
|
||||
v, err := r.Operation.Do(ctx, "SInterStore", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ func (r GroupSet) SInterStore(ctx context.Context, destination string, key strin
|
||||
func (r GroupSet) SUnion(ctx context.Context, key string, keys ...string) (gvar.Vars, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SUnion", s...)
|
||||
v, err := r.Operation.Do(ctx, "SUnion", s...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -220,7 +220,7 @@ func (r GroupSet) SUnion(ctx context.Context, key string, keys ...string) (gvar.
|
||||
func (r GroupSet) SUnionStore(ctx context.Context, destination, key string, keys ...string) (int64, error) {
|
||||
var s = []interface{}{destination, key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SUnionStore", s...)
|
||||
v, err := r.Operation.Do(ctx, "SUnionStore", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ func (r GroupSet) SUnionStore(ctx context.Context, destination, key string, keys
|
||||
func (r GroupSet) SDiff(ctx context.Context, key string, keys ...string) (gvar.Vars, error) {
|
||||
var s = []interface{}{key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SDiff", s...)
|
||||
v, err := r.Operation.Do(ctx, "SDiff", s...)
|
||||
return v.Vars(), err
|
||||
}
|
||||
|
||||
@ -247,6 +247,6 @@ func (r GroupSet) SDiff(ctx context.Context, key string, keys ...string) (gvar.V
|
||||
func (r GroupSet) SDiffStore(ctx context.Context, destination string, key string, keys ...string) (int64, error) {
|
||||
var s = []interface{}{destination, key}
|
||||
s = append(s, gconv.Interfaces(keys)...)
|
||||
v, err := r.redis.Do(ctx, "SDiffStore", s...)
|
||||
v, err := r.Operation.Do(ctx, "SDiffStore", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -15,13 +15,13 @@ import (
|
||||
|
||||
// GroupSortedSet provides sorted set functions for redis.
|
||||
type GroupSortedSet struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupSortedSet creates and returns GroupSortedSet.
|
||||
func (r *Redis) GroupSortedSet() gredis.IGroupSortedSet {
|
||||
return GroupSortedSet{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ func (r GroupSortedSet) ZAdd(
|
||||
for _, item := range members {
|
||||
s = append(s, item.Score, item.Member)
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "ZAdd", s...)
|
||||
v, err := r.Operation.Do(ctx, "ZAdd", s...)
|
||||
return v, err
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ func (r GroupSortedSet) ZAdd(
|
||||
//
|
||||
// https://redis.io/commands/zscore/
|
||||
func (r GroupSortedSet) ZScore(ctx context.Context, key string, member interface{}) (float64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZScore", key, member)
|
||||
v, err := r.Operation.Do(ctx, "ZScore", key, member)
|
||||
return v.Float64(), err
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ func (r GroupSortedSet) ZScore(ctx context.Context, key string, member interface
|
||||
//
|
||||
// https://redis.io/commands/zincrby/
|
||||
func (r GroupSortedSet) ZIncrBy(ctx context.Context, key string, increment float64, member interface{}) (float64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZIncrBy", key, increment, member)
|
||||
v, err := r.Operation.Do(ctx, "ZIncrBy", key, increment, member)
|
||||
return v.Float64(), err
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ func (r GroupSortedSet) ZIncrBy(ctx context.Context, key string, increment float
|
||||
//
|
||||
// https://redis.io/commands/zcard/
|
||||
func (r GroupSortedSet) ZCard(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZCard", key)
|
||||
v, err := r.Operation.Do(ctx, "ZCard", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ func (r GroupSortedSet) ZCard(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/zcount/
|
||||
func (r GroupSortedSet) ZCount(ctx context.Context, key string, min, max string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZCount", key, min, max)
|
||||
v, err := r.Operation.Do(ctx, "ZCount", key, min, max)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ func (r GroupSortedSet) ZRange(ctx context.Context, key string, start, stop int6
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "ZRange", mustMergeOptionToArgs(
|
||||
v, err := r.Operation.Do(ctx, "ZRange", mustMergeOptionToArgs(
|
||||
[]interface{}{key, start, stop}, usedOption,
|
||||
)...)
|
||||
return v.Vars(), err
|
||||
@ -144,7 +144,7 @@ func (r GroupSortedSet) ZRevRange(ctx context.Context, key string, start, stop i
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
return r.redis.Do(ctx, "ZRevRange", mustMergeOptionToArgs(
|
||||
return r.Operation.Do(ctx, "ZRevRange", mustMergeOptionToArgs(
|
||||
[]interface{}{key, start, stop}, usedOption,
|
||||
)...)
|
||||
}
|
||||
@ -160,7 +160,7 @@ func (r GroupSortedSet) ZRevRange(ctx context.Context, key string, start, stop i
|
||||
//
|
||||
// https://redis.io/commands/zrank/
|
||||
func (r GroupSortedSet) ZRank(ctx context.Context, key string, member interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRank", key, member)
|
||||
v, err := r.Operation.Do(ctx, "ZRank", key, member)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ func (r GroupSortedSet) ZRank(ctx context.Context, key string, member interface{
|
||||
//
|
||||
// https://redis.io/commands/zrevrank/
|
||||
func (r GroupSortedSet) ZRevRank(ctx context.Context, key string, member interface{}) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRevRank", key, member)
|
||||
v, err := r.Operation.Do(ctx, "ZRevRank", key, member)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ func (r GroupSortedSet) ZRem(ctx context.Context, key string, member interface{}
|
||||
var s = []interface{}{key}
|
||||
s = append(s, member)
|
||||
s = append(s, members...)
|
||||
v, err := r.redis.Do(ctx, "ZRem", s...)
|
||||
v, err := r.Operation.Do(ctx, "ZRem", s...)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ func (r GroupSortedSet) ZRem(ctx context.Context, key string, member interface{}
|
||||
//
|
||||
// https://redis.io/commands/zremrangebyrank/
|
||||
func (r GroupSortedSet) ZRemRangeByRank(ctx context.Context, key string, start, stop int64) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRemRangeByRank", key, start, stop)
|
||||
v, err := r.Operation.Do(ctx, "ZRemRangeByRank", key, start, stop)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ func (r GroupSortedSet) ZRemRangeByRank(ctx context.Context, key string, start,
|
||||
//
|
||||
// https://redis.io/commands/zremrangebyscore/
|
||||
func (r GroupSortedSet) ZRemRangeByScore(ctx context.Context, key string, min, max string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRemRangeByScore", key, min, max)
|
||||
v, err := r.Operation.Do(ctx, "ZRemRangeByScore", key, min, max)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ func (r GroupSortedSet) ZRemRangeByScore(ctx context.Context, key string, min, m
|
||||
//
|
||||
// https://redis.io/commands/zremrangebylex/
|
||||
func (r GroupSortedSet) ZRemRangeByLex(ctx context.Context, key string, min, max string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZRemRangeByLex", key, min, max)
|
||||
v, err := r.Operation.Do(ctx, "ZRemRangeByLex", key, min, max)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -249,6 +249,6 @@ func (r GroupSortedSet) ZRemRangeByLex(ctx context.Context, key string, min, max
|
||||
//
|
||||
// https://redis.io/commands/zlexcount/
|
||||
func (r GroupSortedSet) ZLexCount(ctx context.Context, key, min, max string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "ZLexCount", key, min, max)
|
||||
v, err := r.Operation.Do(ctx, "ZLexCount", key, min, max)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -16,13 +16,13 @@ import (
|
||||
|
||||
// GroupString is the function group manager for string operations.
|
||||
type GroupString struct {
|
||||
redis *Redis
|
||||
Operation gredis.AdapterOperation
|
||||
}
|
||||
|
||||
// GroupString is the redis group object for string operations.
|
||||
func (r *Redis) GroupString() gredis.IGroupString {
|
||||
return GroupString{
|
||||
redis: r,
|
||||
Operation: r.AdapterOperation,
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ func (r GroupString) Set(ctx context.Context, key string, value interface{}, opt
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
return r.redis.Do(ctx, "Set", mustMergeOptionToArgs(
|
||||
return r.Operation.Do(ctx, "Set", mustMergeOptionToArgs(
|
||||
[]interface{}{key, value}, usedOption,
|
||||
)...)
|
||||
}
|
||||
@ -52,7 +52,7 @@ func (r GroupString) Set(ctx context.Context, key string, value interface{}, opt
|
||||
//
|
||||
// https://redis.io/commands/setnx/
|
||||
func (r GroupString) SetNX(ctx context.Context, key string, value interface{}) (bool, error) {
|
||||
v, err := r.redis.Do(ctx, "SetNX", key, value)
|
||||
v, err := r.Operation.Do(ctx, "SetNX", key, value)
|
||||
return v.Bool(), err
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func (r GroupString) SetNX(ctx context.Context, key string, value interface{}) (
|
||||
//
|
||||
// https://redis.io/commands/setex/
|
||||
func (r GroupString) SetEX(ctx context.Context, key string, value interface{}, ttlInSeconds int64) error {
|
||||
_, err := r.redis.Do(ctx, "SetEX", key, ttlInSeconds, value)
|
||||
_, err := r.Operation.Do(ctx, "SetEX", key, ttlInSeconds, value)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ func (r GroupString) SetEX(ctx context.Context, key string, value interface{}, t
|
||||
//
|
||||
// https://redis.io/commands/get/
|
||||
func (r GroupString) Get(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "Get", key)
|
||||
return r.Operation.Do(ctx, "Get", key)
|
||||
}
|
||||
|
||||
// GetDel gets the value of key and delete the key.
|
||||
@ -88,7 +88,7 @@ func (r GroupString) Get(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
//
|
||||
// https://redis.io/commands/getdel/
|
||||
func (r GroupString) GetDel(ctx context.Context, key string) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "GetDel", key)
|
||||
return r.Operation.Do(ctx, "GetDel", key)
|
||||
}
|
||||
|
||||
// GetEX is similar to GET, but is a write command with additional options.
|
||||
@ -99,7 +99,7 @@ func (r GroupString) GetEX(ctx context.Context, key string, option ...gredis.Get
|
||||
if len(option) > 0 {
|
||||
usedOption = option[0]
|
||||
}
|
||||
return r.redis.Do(ctx, "GetEX", mustMergeOptionToArgs(
|
||||
return r.Operation.Do(ctx, "GetEX", mustMergeOptionToArgs(
|
||||
[]interface{}{key}, usedOption,
|
||||
)...)
|
||||
}
|
||||
@ -110,7 +110,7 @@ func (r GroupString) GetEX(ctx context.Context, key string, option ...gredis.Get
|
||||
//
|
||||
// https://redis.io/commands/getset/
|
||||
func (r GroupString) GetSet(ctx context.Context, key string, value interface{}) (*gvar.Var, error) {
|
||||
return r.redis.Do(ctx, "GetSet", key, value)
|
||||
return r.Operation.Do(ctx, "GetSet", key, value)
|
||||
}
|
||||
|
||||
// StrLen returns the length of the string value stored at key.
|
||||
@ -120,7 +120,7 @@ func (r GroupString) GetSet(ctx context.Context, key string, value interface{})
|
||||
//
|
||||
// https://redis.io/commands/strlen/
|
||||
func (r GroupString) StrLen(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "StrLen", key)
|
||||
v, err := r.Operation.Do(ctx, "StrLen", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ func (r GroupString) StrLen(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/append/
|
||||
func (r GroupString) Append(ctx context.Context, key string, value string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Append", key, value)
|
||||
v, err := r.Operation.Do(ctx, "Append", key, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ func (r GroupString) Append(ctx context.Context, key string, value string) (int6
|
||||
//
|
||||
// https://redis.io/commands/setrange/
|
||||
func (r GroupString) SetRange(ctx context.Context, key string, offset int64, value string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "SetRange", key, offset, value)
|
||||
v, err := r.Operation.Do(ctx, "SetRange", key, offset, value)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func (r GroupString) SetRange(ctx context.Context, key string, offset int64, val
|
||||
//
|
||||
// https://redis.io/commands/getrange/
|
||||
func (r GroupString) GetRange(ctx context.Context, key string, start, end int64) (string, error) {
|
||||
v, err := r.redis.Do(ctx, "GetRange", key, start, end)
|
||||
v, err := r.Operation.Do(ctx, "GetRange", key, start, end)
|
||||
return v.String(), err
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ func (r GroupString) GetRange(ctx context.Context, key string, start, end int64)
|
||||
//
|
||||
// https://redis.io/commands/incr/
|
||||
func (r GroupString) Incr(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Incr", key)
|
||||
v, err := r.Operation.Do(ctx, "Incr", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ func (r GroupString) Incr(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/incrby/
|
||||
func (r GroupString) IncrBy(ctx context.Context, key string, increment int64) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "IncrBy", key, increment)
|
||||
v, err := r.Operation.Do(ctx, "IncrBy", key, increment)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ func (r GroupString) IncrBy(ctx context.Context, key string, increment int64) (i
|
||||
//
|
||||
// https://redis.io/commands/incrbyfloat/
|
||||
func (r GroupString) IncrByFloat(ctx context.Context, key string, increment float64) (float64, error) {
|
||||
v, err := r.redis.Do(ctx, "IncrByFloat", key, increment)
|
||||
v, err := r.Operation.Do(ctx, "IncrByFloat", key, increment)
|
||||
return v.Float64(), err
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ func (r GroupString) IncrByFloat(ctx context.Context, key string, increment floa
|
||||
//
|
||||
// https://redis.io/commands/decr/
|
||||
func (r GroupString) Decr(ctx context.Context, key string) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "Decr", key)
|
||||
v, err := r.Operation.Do(ctx, "Decr", key)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -202,7 +202,7 @@ func (r GroupString) Decr(ctx context.Context, key string) (int64, error) {
|
||||
//
|
||||
// https://redis.io/commands/decrby/
|
||||
func (r GroupString) DecrBy(ctx context.Context, key string, decrement int64) (int64, error) {
|
||||
v, err := r.redis.Do(ctx, "DecrBy", key, decrement)
|
||||
v, err := r.Operation.Do(ctx, "DecrBy", key, decrement)
|
||||
return v.Int64(), err
|
||||
}
|
||||
|
||||
@ -219,7 +219,7 @@ func (r GroupString) MSet(ctx context.Context, keyValueMap map[string]interface{
|
||||
for k, v := range keyValueMap {
|
||||
args = append(args, k, v)
|
||||
}
|
||||
_, err := r.redis.Do(ctx, "MSet", args...)
|
||||
_, err := r.Operation.Do(ctx, "MSet", args...)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ func (r GroupString) MSetNX(ctx context.Context, keyValueMap map[string]interfac
|
||||
for k, v := range keyValueMap {
|
||||
args = append(args, k, v)
|
||||
}
|
||||
v, err := r.redis.Do(ctx, "MSetNX", args...)
|
||||
v, err := r.Operation.Do(ctx, "MSetNX", args...)
|
||||
return v.Bool(), err
|
||||
}
|
||||
|
||||
@ -242,7 +242,7 @@ func (r GroupString) MSetNX(ctx context.Context, keyValueMap map[string]interfac
|
||||
// https://redis.io/commands/mget/
|
||||
func (r GroupString) MGet(ctx context.Context, keys ...string) (map[string]*gvar.Var, error) {
|
||||
var result = make(map[string]*gvar.Var)
|
||||
v, err := r.redis.Do(ctx, "MGet", gconv.Interfaces(keys)...)
|
||||
v, err := r.Operation.Do(ctx, "MGet", gconv.Interfaces(keys)...)
|
||||
if err == nil {
|
||||
values := v.Vars()
|
||||
for i, key := range keys {
|
||||
|
||||
45
contrib/nosql/redis/redis_operation.go
Normal file
45
contrib/nosql/redis/redis_operation.go
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/database/gredis"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
)
|
||||
|
||||
// Do send a command to the server and returns the received reply.
|
||||
// It uses json.Marshal for struct/slice/map type values before committing them to redis.
|
||||
func (r *Redis) Do(ctx context.Context, command string, args ...interface{}) (*gvar.Var, error) {
|
||||
conn, err := r.Conn(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = conn.Close(ctx)
|
||||
}()
|
||||
return conn.Do(ctx, command, args...)
|
||||
}
|
||||
|
||||
// Close closes the redis connection pool, which will release all connections reserved by this pool.
|
||||
// It is commonly not necessary to call Close manually.
|
||||
func (r *Redis) Close(ctx context.Context) (err error) {
|
||||
if err = r.client.Close(); err != nil {
|
||||
err = gerror.Wrap(err, `Operation Client Close failed`)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Conn retrieves and returns a connection object for continuous operations.
|
||||
// Note that you should call Close function manually if you do not use this connection any further.
|
||||
func (r *Redis) Conn(ctx context.Context) (gredis.Conn, error) {
|
||||
return &Conn{
|
||||
redis: r,
|
||||
}, nil
|
||||
}
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/etcd/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
go.etcd.io/etcd/client/v3 v3.5.7
|
||||
)
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ module github.com/gogf/gf/contrib/registry/file/v2
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.6.1
|
||||
require github.com/gogf/gf/v2 v2.6.2
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/nacos/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/joy999/nacos-sdk-go v0.0.0-20231120071639-10a34b3e7288
|
||||
)
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/polaris/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/polarismesh/polaris-go v1.5.5
|
||||
)
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/go-zookeeper/zk v1.0.3
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
golang.org/x/sync v0.4.0
|
||||
)
|
||||
|
||||
|
||||
@ -3,8 +3,8 @@ module github.com/gogf/gf/contrib/rpc/grpcx/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.6.2
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
go.opentelemetry.io/otel v1.14.0
|
||||
go.opentelemetry.io/otel/trace v1.14.0
|
||||
google.golang.org/grpc v1.57.2
|
||||
|
||||
@ -8,6 +8,8 @@ package grpcx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@ -74,8 +76,26 @@ func (s modServer) NewConfig() *GrpcServerConfig {
|
||||
// Reading configuration file and updating the configured keys.
|
||||
if g.Cfg().Available(ctx) {
|
||||
// Server attributes configuration.
|
||||
if err = g.Cfg().MustGet(ctx, configNodeNameGrpcServer).Struct(&config); err != nil {
|
||||
serverConfigMap := g.Cfg().MustGet(ctx, configNodeNameGrpcServer).Map()
|
||||
if len(serverConfigMap) == 0 {
|
||||
return config
|
||||
}
|
||||
if err = gconv.Struct(serverConfigMap, &config); err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
return config
|
||||
}
|
||||
// Server logger configuration checks.
|
||||
serverLoggerConfigMap := g.Cfg().MustGet(
|
||||
ctx,
|
||||
fmt.Sprintf(`%s.logger`, configNodeNameGrpcServer),
|
||||
).Map()
|
||||
if len(serverLoggerConfigMap) == 0 && len(serverConfigMap) > 0 {
|
||||
serverLoggerConfigMap = gconv.Map(serverConfigMap["logger"])
|
||||
}
|
||||
if len(serverLoggerConfigMap) > 0 {
|
||||
if err = config.Logger.SetConfigWithMap(serverLoggerConfigMap); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return config
|
||||
|
||||
@ -7,9 +7,13 @@
|
||||
package grpcx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/debug/gdebug"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
@ -70,3 +74,28 @@ func Test_Grpcx_Grpc_Server_Config(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Grpcx_Grpc_Server_Config_Logger(t *testing.T) {
|
||||
var (
|
||||
pwd = gfile.Pwd()
|
||||
configDir = gfile.Join(gdebug.CallerDirectory(), "testdata", "configuration")
|
||||
)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err := gfile.Chdir(configDir)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Chdir(pwd)
|
||||
|
||||
s := Server.New()
|
||||
s.Start()
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
defer s.Stop()
|
||||
|
||||
var (
|
||||
logFilePath = fmt.Sprintf("/tmp/log/%s.log", gtime.Now().Format("Y-m-d"))
|
||||
logFileContent = gfile.GetContents(logFilePath)
|
||||
)
|
||||
t.Assert(gfile.Exists(logFilePath), true)
|
||||
t.Assert(gstr.Contains(logFileContent, "TestLogger "), true)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
14
contrib/rpc/grpcx/testdata/configuration/config.yaml
vendored
Normal file
14
contrib/rpc/grpcx/testdata/configuration/config.yaml
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
grpc:
|
||||
name: "demo" # 服务名称
|
||||
address: ":8000" # 自定义服务监听地址
|
||||
logPath: "./log" # 日志存储目录路径
|
||||
logStdout: true # 日志是否输出到终端
|
||||
errorLogEnabled: true # 是否开启错误日志记录
|
||||
accessLogEnabled: true # 是否开启访问日志记录
|
||||
errorStack: true # 当产生错误时,是否记录错误堆栈
|
||||
logger:
|
||||
path: "/tmp/log/" # 日志文件路径。默认为空,表示关闭,仅输出到终端
|
||||
file: "{Y-m-d}.log" # 日志文件格式。默认为"{Y-m-d}.log"
|
||||
prefix: "TestLogger" # 日志内容输出前缀。默认为空
|
||||
level: "all" # 日志输出级别
|
||||
stdout: false # 日志是否同时输出到终端。默认true
|
||||
@ -2,7 +2,7 @@ module github.com/gogf/gf/contrib/sdk/httpclient/v2
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/gogf/gf/v2 v2.6.1
|
||||
require github.com/gogf/gf/v2 v2.6.2
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.2.0 // indirect
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/jaeger/v2
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
go.opentelemetry.io/otel v1.14.0
|
||||
go.opentelemetry.io/otel/exporters/jaeger v1.14.0
|
||||
go.opentelemetry.io/otel/sdk v1.14.0
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/otlpgrpc/v2
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
go.opentelemetry.io/otel v1.19.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0
|
||||
|
||||
@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/otlphttp/v2
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
go.opentelemetry.io/otel v1.19.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0
|
||||
|
||||
@ -15,7 +15,24 @@ import (
|
||||
// Adapter is an interface for universal redis operations.
|
||||
type Adapter interface {
|
||||
AdapterGroup
|
||||
AdapterOperation
|
||||
}
|
||||
|
||||
// AdapterGroup is an interface managing group operations for redis.
|
||||
type AdapterGroup interface {
|
||||
GroupGeneric() IGroupGeneric
|
||||
GroupHash() IGroupHash
|
||||
GroupList() IGroupList
|
||||
GroupPubSub() IGroupPubSub
|
||||
GroupScript() IGroupScript
|
||||
GroupSet() IGroupSet
|
||||
GroupSortedSet() IGroupSortedSet
|
||||
GroupString() IGroupString
|
||||
}
|
||||
|
||||
// AdapterOperation is the core operation functions for redis.
|
||||
// These functions can be easily overwritten by custom implements.
|
||||
type AdapterOperation interface {
|
||||
// Do send a command to the server and returns the received reply.
|
||||
// It uses json.Marshal for struct/slice/map type values before committing them to redis.
|
||||
Do(ctx context.Context, command string, args ...interface{}) (*gvar.Var, error)
|
||||
@ -40,18 +57,6 @@ type Conn interface {
|
||||
Close(ctx context.Context) (err error)
|
||||
}
|
||||
|
||||
// AdapterGroup is an interface managing group operations for redis.
|
||||
type AdapterGroup interface {
|
||||
GroupGeneric() IGroupGeneric
|
||||
GroupHash() IGroupHash
|
||||
GroupList() IGroupList
|
||||
GroupPubSub() IGroupPubSub
|
||||
GroupScript() IGroupScript
|
||||
GroupSet() IGroupSet
|
||||
GroupSortedSet() IGroupSortedSet
|
||||
GroupString() IGroupString
|
||||
}
|
||||
|
||||
// ConnCommand is an interface managing some operations bound to certain connection.
|
||||
type ConnCommand interface {
|
||||
// Subscribe subscribes the client to the specified channels.
|
||||
|
||||
@ -53,6 +53,21 @@ func Test_New(t *testing.T) {
|
||||
t.Assert(j.Get("k2"), "v2")
|
||||
t.Assert(j.Get("k3"), nil)
|
||||
})
|
||||
// https://github.com/gogf/gf/issues/3253
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type TestStruct struct {
|
||||
Result []map[string]string `json:"result"`
|
||||
}
|
||||
ts := &TestStruct{
|
||||
Result: []map[string]string{
|
||||
{
|
||||
"Name": "gf",
|
||||
"Role": "",
|
||||
},
|
||||
},
|
||||
}
|
||||
gjson.New(ts)
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Valid(t *testing.T) {
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 boot
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,12 +1,19 @@
|
||||
// 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 boot
|
||||
|
||||
import (
|
||||
consul "github.com/gogf/gf/contrib/config/consul/v2"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/hashicorp/consul/api"
|
||||
"github.com/hashicorp/go-cleanhttp"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 boot
|
||||
|
||||
import (
|
||||
|
||||
@ -1,10 +1,17 @@
|
||||
// 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 boot
|
||||
|
||||
import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
"github.com/gogf/gf/contrib/config/kubecm/v2"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,11 +1,18 @@
|
||||
// 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 boot
|
||||
|
||||
import (
|
||||
"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"
|
||||
"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() {
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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
|
||||
|
||||
import (
|
||||
|
||||
58
example/converter/alias_type_convert_with_refer/main.go
Normal file
58
example/converter/alias_type_convert_with_refer/main.go
Normal file
@ -0,0 +1,58 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type MyTime = *gtime.Time
|
||||
|
||||
type Src struct {
|
||||
A MyTime
|
||||
}
|
||||
|
||||
type Dst struct {
|
||||
B string
|
||||
}
|
||||
|
||||
type SrcWrap struct {
|
||||
Value Src
|
||||
}
|
||||
|
||||
type DstWrap struct {
|
||||
Value Dst
|
||||
}
|
||||
|
||||
// SrcToDstConverter is custom converting function for custom type.
|
||||
func SrcToDstConverter(src Src) (dst *Dst, err error) {
|
||||
return &Dst{B: src.A.Format("Y-m-d")}, nil
|
||||
}
|
||||
|
||||
// SrcToDstConverter is custom converting function for custom type.
|
||||
func main() {
|
||||
// register custom converter function.
|
||||
err := gconv.RegisterConverter(SrcToDstConverter)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// custom struct converting.
|
||||
var src = Src{A: gtime.Now()}
|
||||
dst := gconv.ConvertWithRefer(src, &Dst{})
|
||||
fmt.Println("src:", src)
|
||||
fmt.Println("dst:", dst)
|
||||
|
||||
// custom struct attributes converting.
|
||||
var srcWrap = SrcWrap{Src{A: gtime.Now()}}
|
||||
dstWrap := gconv.ConvertWithRefer(srcWrap, &DstWrap{})
|
||||
fmt.Println("srcWrap:", srcWrap)
|
||||
fmt.Println("dstWrap:", dstWrap)
|
||||
}
|
||||
72
example/converter/alias_type_scan/main.go
Normal file
72
example/converter/alias_type_scan/main.go
Normal file
@ -0,0 +1,72 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type MyTime = *gtime.Time
|
||||
|
||||
type Src struct {
|
||||
A MyTime
|
||||
}
|
||||
|
||||
type Dst struct {
|
||||
B string
|
||||
}
|
||||
|
||||
type SrcWrap struct {
|
||||
Value Src
|
||||
}
|
||||
|
||||
type DstWrap struct {
|
||||
Value Dst
|
||||
}
|
||||
|
||||
// SrcToDstConverter is custom converting function for custom type.
|
||||
func SrcToDstConverter(src Src) (dst *Dst, err error) {
|
||||
return &Dst{B: src.A.Format("Y-m-d")}, nil
|
||||
}
|
||||
|
||||
// SrcToDstConverter is custom converting function for custom type.
|
||||
func main() {
|
||||
// register custom converter function.
|
||||
err := gconv.RegisterConverter(SrcToDstConverter)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// custom struct converting.
|
||||
var (
|
||||
src = Src{A: gtime.Now()}
|
||||
dst *Dst
|
||||
)
|
||||
err = gconv.Scan(src, &dst)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("src:", src)
|
||||
fmt.Println("dst:", dst)
|
||||
|
||||
// custom struct attributes converting.
|
||||
var (
|
||||
srcWrap = SrcWrap{Src{A: gtime.Now()}}
|
||||
dstWrap *DstWrap
|
||||
)
|
||||
err = gconv.Scan(srcWrap, &dstWrap)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("srcWrap:", srcWrap)
|
||||
fmt.Println("dstWrap:", dstWrap)
|
||||
}
|
||||
54
example/converter/struct_convert_with_refer/main.go
Normal file
54
example/converter/struct_convert_with_refer/main.go
Normal file
@ -0,0 +1,54 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type Src struct {
|
||||
A int
|
||||
}
|
||||
|
||||
type Dst struct {
|
||||
B int
|
||||
}
|
||||
|
||||
type SrcWrap struct {
|
||||
Value Src
|
||||
}
|
||||
|
||||
type DstWrap struct {
|
||||
Value Dst
|
||||
}
|
||||
|
||||
// SrcToDstConverter is custom converting function for custom type.
|
||||
func SrcToDstConverter(src Src) (dst *Dst, err error) {
|
||||
return &Dst{B: src.A}, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
// register custom converter function.
|
||||
err := gconv.RegisterConverter(SrcToDstConverter)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// custom struct converting.
|
||||
var src = Src{A: 1}
|
||||
dst := gconv.ConvertWithRefer(src, Dst{})
|
||||
fmt.Println("src:", src)
|
||||
fmt.Println("dst:", dst)
|
||||
|
||||
// custom struct attributes converting.
|
||||
var srcWrap = SrcWrap{Src{A: 1}}
|
||||
dstWrap := gconv.ConvertWithRefer(srcWrap, &DstWrap{})
|
||||
fmt.Println("srcWrap:", srcWrap)
|
||||
fmt.Println("dstWrap:", dstWrap)
|
||||
}
|
||||
68
example/converter/struct_scan/main.go
Normal file
68
example/converter/struct_scan/main.go
Normal file
@ -0,0 +1,68 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type Src struct {
|
||||
A int
|
||||
}
|
||||
|
||||
type Dst struct {
|
||||
B int
|
||||
}
|
||||
|
||||
type SrcWrap struct {
|
||||
Value Src
|
||||
}
|
||||
|
||||
type DstWrap struct {
|
||||
Value Dst
|
||||
}
|
||||
|
||||
func SrcToDstConverter(src Src) (dst *Dst, err error) {
|
||||
return &Dst{B: src.A}, nil
|
||||
}
|
||||
|
||||
// SrcToDstConverter is custom converting function for custom type.
|
||||
func main() {
|
||||
// register custom converter function.
|
||||
err := gconv.RegisterConverter(SrcToDstConverter)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// custom struct converting.
|
||||
var (
|
||||
src = Src{A: 1}
|
||||
dst *Dst
|
||||
)
|
||||
err = gconv.Scan(src, &dst)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("src:", src)
|
||||
fmt.Println("dst:", dst)
|
||||
|
||||
// custom struct attributes converting.
|
||||
var (
|
||||
srcWrap = SrcWrap{Src{A: 1}}
|
||||
dstWrap *DstWrap
|
||||
)
|
||||
err = gconv.Scan(srcWrap, &dstWrap)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("srcWrap:", srcWrap)
|
||||
fmt.Println("dstWrap:", dstWrap)
|
||||
}
|
||||
@ -1,27 +1,28 @@
|
||||
module github.com/gogf/gf/example
|
||||
|
||||
go 1.20
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/gogf/gf/contrib/config/apollo/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/config/consul/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/config/kubecm/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/config/nacos/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/config/polaris/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/registry/etcd/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/config/apollo/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/config/consul/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/config/kubecm/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/config/nacos/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/config/polaris/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/nosql/redis/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/registry/etcd/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/registry/file/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/registry/nacos/v2 v2.5.6
|
||||
github.com/gogf/gf/contrib/registry/polaris/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.6.1
|
||||
github.com/gogf/gf/v2 v2.6.1
|
||||
github.com/gogf/gf/contrib/registry/polaris/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.6.2
|
||||
github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.6.2
|
||||
github.com/gogf/gf/v2 v2.6.2
|
||||
github.com/hashicorp/consul/api v1.24.0
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2
|
||||
github.com/nacos-group/nacos-sdk-go v1.1.4
|
||||
github.com/polarismesh/polaris-go v1.5.5
|
||||
github.com/prometheus/client_golang v1.17.0
|
||||
golang.org/x/time v0.3.0
|
||||
google.golang.org/grpc v1.59.0
|
||||
google.golang.org/protobuf v1.31.0
|
||||
@ -93,7 +94,6 @@ require (
|
||||
github.com/pelletier/go-toml v1.9.3 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/polarismesh/specification v1.4.1 // indirect
|
||||
github.com/prometheus/client_golang v1.17.0 // indirect
|
||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
|
||||
github.com/prometheus/common v0.44.0 // indirect
|
||||
github.com/prometheus/procfs v0.11.1 // indirect
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,12 +1,19 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
type HelloReq struct {
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
45
example/httpserver/serve_file/main.go
Normal file
45
example/httpserver/serve_file/main.go
Normal file
@ -0,0 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// pathMap is used for URL mapping
|
||||
var pathMap = map[string]string{
|
||||
"/aaa/": "/tmp/",
|
||||
}
|
||||
|
||||
// ServeFile serves the file to the response.
|
||||
func ServeFile(r *ghttp.Request) {
|
||||
truePath := r.URL.Path
|
||||
hasPrefix := false
|
||||
// Replace the path prefix.
|
||||
for k, v := range pathMap {
|
||||
if strings.HasPrefix(truePath, k) {
|
||||
truePath = strings.Replace(truePath, k, v, 1) // Replace only once.
|
||||
hasPrefix = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !hasPrefix {
|
||||
r.Response.WriteStatus(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
r.Response.ServeFile(truePath)
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Use(ghttp.MiddlewareHandlerResponse)
|
||||
s.BindHandler("/*", ServeFile)
|
||||
s.SetPort(8080)
|
||||
s.Run()
|
||||
}
|
||||
|
||||
// http://127.0.0.1:8080/aaa/main.go
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
@ -8,17 +14,21 @@ import (
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// HelloReq hello request
|
||||
type HelloReq struct {
|
||||
g.Meta `path:"/hello" method:"get" sort:"1"`
|
||||
Name string `v:"required" dc:"Your name"`
|
||||
}
|
||||
|
||||
// HelloRes hello response
|
||||
type HelloRes struct {
|
||||
Reply string `dc:"Reply content"`
|
||||
}
|
||||
|
||||
// Hello Controller
|
||||
type Hello struct{}
|
||||
|
||||
// Say function
|
||||
func (Hello) Say(ctx context.Context, req *HelloReq) (res *HelloRes, err error) {
|
||||
g.Log().Debugf(ctx, `receive say: %+v`, req)
|
||||
res = &HelloRes{
|
||||
|
||||
4
example/httpserver/swagger_set_template/config.yaml
Normal file
4
example/httpserver/swagger_set_template/config.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
server:
|
||||
address: ":8199"
|
||||
openapiPath: "/api.json"
|
||||
swaggerPath: "/swagger"
|
||||
71
example/httpserver/swagger_set_template/main.go
Normal file
71
example/httpserver/swagger_set_template/main.go
Normal file
@ -0,0 +1,71 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// HelloReq hello request
|
||||
type HelloReq struct {
|
||||
g.Meta `path:"/hello" method:"get" sort:"1"`
|
||||
Name string `v:"required" dc:"Your name"`
|
||||
}
|
||||
|
||||
// HelloRes hello response
|
||||
type HelloRes struct {
|
||||
Reply string `dc:"Reply content"`
|
||||
}
|
||||
|
||||
// Hello Controller
|
||||
type Hello struct{}
|
||||
|
||||
// Say function
|
||||
func (Hello) Say(ctx context.Context, req *HelloReq) (res *HelloRes, err error) {
|
||||
g.Log().Debugf(ctx, `receive say: %+v`, req)
|
||||
res = &HelloRes{
|
||||
Reply: fmt.Sprintf(`Hi %s`, req.Name),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
MySwaggerUITemplate = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="SwaggerUI"/>
|
||||
<title>SwaggerUI</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.10.5/swagger-ui.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.10.5/swagger-ui-bundle.js" crossorigin></script>
|
||||
<script>
|
||||
window.onload = () => {
|
||||
window.ui = SwaggerUIBundle({
|
||||
url: '{SwaggerUIDocUrl}',
|
||||
dom_id: '#swagger-ui',
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := g.Server()
|
||||
s.Use(ghttp.MiddlewareHandlerResponse)
|
||||
s.Group("/", func(group *ghttp.RouterGroup) {
|
||||
group.Bind(
|
||||
new(Hello),
|
||||
)
|
||||
})
|
||||
s.SetSwaggerUITemplate(MySwaggerUITemplate)
|
||||
s.Run()
|
||||
}
|
||||
51
example/metric/prometheus/prometheus.go
Normal file
51
example/metric/prometheus/prometheus.go
Normal file
@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
// Demo metric type Counter
|
||||
var metricCounter = promauto.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "demo_counter",
|
||||
Help: "A demo counter.",
|
||||
},
|
||||
)
|
||||
|
||||
// Demo metric type Gauge.
|
||||
var metricGauge = promauto.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "demo_gauge",
|
||||
Help: "A demo gauge.",
|
||||
},
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create prometheus metric registry.
|
||||
registry := prometheus.NewRegistry()
|
||||
registry.MustRegister(
|
||||
metricCounter,
|
||||
metricGauge,
|
||||
)
|
||||
|
||||
// Start metric http server.
|
||||
s := g.Server()
|
||||
s.SetPort(8000)
|
||||
// Fake metric values.
|
||||
// http://127.0.0.1:8000/
|
||||
s.BindHandler("/", func(r *ghttp.Request) {
|
||||
metricCounter.Add(1)
|
||||
metricGauge.Set(float64(grand.N(1, 100)))
|
||||
r.Response.Write("fake ok")
|
||||
})
|
||||
// Export metric values.
|
||||
// You can view http://127.0.0.1:8000/metrics to see all metric values.
|
||||
s.BindHandler("/metrics", ghttp.WrapH(promhttp.Handler()))
|
||||
s.Run()
|
||||
}
|
||||
52
example/nosql/redis/adapter/main.go
Normal file
52
example/nosql/redis/adapter/main.go
Normal file
@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/contrib/nosql/redis/v2"
|
||||
|
||||
"github.com/gogf/gf/v2/container/gvar"
|
||||
"github.com/gogf/gf/v2/database/gredis"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
)
|
||||
|
||||
var (
|
||||
ctx = gctx.New()
|
||||
group = "cache"
|
||||
config = gredis.Config{
|
||||
Address: "127.0.0.1:6379",
|
||||
Db: 1,
|
||||
}
|
||||
)
|
||||
|
||||
// MyRedis description
|
||||
type MyRedis struct {
|
||||
*redis.Redis
|
||||
}
|
||||
|
||||
// Do implements and overwrites the underlying function Do from Adapter.
|
||||
func (r *MyRedis) Do(ctx context.Context, command string, args ...interface{}) (*gvar.Var, error) {
|
||||
fmt.Println("MyRedis Do:", command, args)
|
||||
return r.Redis.Do(ctx, command, args...)
|
||||
}
|
||||
|
||||
func main() {
|
||||
gredis.RegisterAdapterFunc(func(config *gredis.Config) gredis.Adapter {
|
||||
r := &MyRedis{redis.New(config)}
|
||||
r.AdapterOperation = r // This is necessary.
|
||||
return r
|
||||
})
|
||||
gredis.SetConfig(&config, group)
|
||||
|
||||
_, err := g.Redis(group).Set(ctx, "key", "value")
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
value, err := g.Redis(group).Get(ctx, "key")
|
||||
if err != nil {
|
||||
g.Log().Fatal(ctx, err)
|
||||
}
|
||||
fmt.Println(value.String())
|
||||
}
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
4
example/os/log/ctx_keys/config.yaml
Normal file
4
example/os/log/ctx_keys/config.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
logger:
|
||||
Level: "all"
|
||||
Stdout: true
|
||||
CtxKeys: ["RequestId", "UserId"]
|
||||
20
example/os/log/ctx_keys/main.go
Normal file
20
example/os/log/ctx_keys/main.go
Normal file
@ -0,0 +1,20 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = context.Background()
|
||||
ctx = context.WithValue(ctx, "RequestId", "123456789")
|
||||
ctx = context.WithValue(ctx, "UserId", "10000")
|
||||
g.Log().Error(ctx, "runtime error")
|
||||
}
|
||||
@ -1,3 +1,9 @@
|
||||
// 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 main
|
||||
|
||||
import (
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user