Compare commits

...

5 Commits

51 changed files with 828 additions and 69 deletions

View File

View File

@ -1,3 +1,4 @@
# The main codes build and unit testing running workflow.
name: GoFrame Main CI
@ -183,9 +184,6 @@ jobs:
- name: Start Consul Containers
run: docker-compose -f ".github/workflows/consul/docker-compose.yml" up -d --build
# - name: Start Minikube
# uses: medyagh/setup-minikube@master
- name: Setup Golang ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
@ -197,11 +195,11 @@ jobs:
- name: Build & Test
if: ${{ (github.event_name == 'push' && github.ref != 'refs/heads/master') || github.event_name == 'pull_request' }}
run: bash .github/workflows/build_and_test.sh
run: bash .github/workflows/ci-main.sh
- name: Build & Test & Coverage
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
run: bash .github/workflows/build_and_test.sh coverage
run: bash .github/workflows/ci-main.sh coverage
- name: Stop Redis Cluster Containers
run: docker-compose -f ".github/workflows/redis/docker-compose.yml" down

27
.github/workflows/ci-sub.sh vendored Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
coverage=$1
# find all path that contains go.mod.
for file in `find . -name go.mod`; do
dirpath=$(dirname $file)
echo $dirpath
# package kuhecm needs golang >= v1.19
if [ "kubecm" = $(basename $dirpath) ]; then
if ! go version|grep -qE "go1.19|go1.[2-9][0-9]"; then
echo "ignore kubecm as go version: $(go version)"
continue 1
fi
else
continue 1
fi
cd $dirpath
go mod tidy
go build ./...
go test ./... -race || exit 1
cd -
done

67
.github/workflows/ci-sub.yml vendored Normal file
View File

@ -0,0 +1,67 @@
# The sub codes build and unit testing running workflow.
# It maintains the ci of unimportant packages.
name: GoFrame Sub CI
on:
push:
branches:
- master
- develop
- personal/**
- feature/**
- enhance/**
- fix/**
pull_request:
branches:
- master
- develop
- personal/**
- feature/**
- enhance/**
- fix/**
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
env:
TZ: "Asia/Shanghai"
jobs:
code-test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ "1.18", "1.19", "1.20", "1.21" ]
goarch: [ "386", "amd64" ]
steps:
- name: Setup Timezone
uses: szenius/set-timezone@v1.1
with:
timezoneLinux: "Asia/Shanghai"
- name: Checkout Repository
uses: actions/checkout@v4
- name: Start Minikube
uses: medyagh/setup-minikube@master
- name: Setup Golang ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache-dependency-path: '**/go.sum'
- name: Before Script
run: bash .github/workflows/before_script.sh
- name: Build & Test
run: bash .github/workflows/ci-sub.sh

View File

@ -1,4 +1,4 @@
name: GoFrame CLI Build Release
name: GoFrame Release
on:
push:

View File

@ -41,7 +41,7 @@ go get -u -v github.com/gogf/gf/v2
## cli tool
```bash
go install github.com/gogf/gf/cmd/gf/v2
go install github.com/gogf/gf/cmd/gf/v2@latest
```
# Limitation

View File

@ -37,7 +37,8 @@ You can also install `gf` tool using pre-built binaries: <https://github.com/gog
## 2) Manually Install
```shell
go install github.com/gogf/gf/cmd/gf/v2
go install github.com/gogf/gf/cmd/gf/v2@latest # latest version
go install github.com/gogf/gf/cmd/gf/v2@v2.5.5 # certain version(should be >= v2.5.5)
```
## 2. Commands

View File

@ -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.5.5
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.5
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.5
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.5
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.5
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/contrib/drivers/clickhouse/v2 v2.5.6
github.com/gogf/gf/contrib/drivers/mssql/v2 v2.5.6
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.6
github.com/gogf/gf/contrib/drivers/oracle/v2 v2.5.6
github.com/gogf/gf/contrib/drivers/pgsql/v2 v2.5.6
github.com/gogf/gf/contrib/drivers/sqlite/v2 v2.5.6
github.com/gogf/gf/v2 v2.5.6
github.com/minio/selfupdate v0.6.0
github.com/olekukonko/tablewriter v0.0.5
golang.org/x/mod v0.9.0

View File

@ -4,7 +4,7 @@ go 1.18
require (
github.com/apolloconfig/agollo/v4 v4.3.1
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
)
require (

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/consul/v2
go 1.19
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/hashicorp/consul/api v1.24.0
github.com/hashicorp/go-cleanhttp v0.5.2
)

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/kubecm/v2
go 1.19
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
k8s.io/api v0.27.4
k8s.io/apimachinery v0.27.4
k8s.io/client-go v0.27.4

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/nacos/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/nacos-group/nacos-sdk-go v1.1.4
)

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/config/polaris/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/polarismesh/polaris-go v1.5.4
)

View File

@ -4,7 +4,7 @@ go 1.18
require (
github.com/ClickHouse/clickhouse-go/v2 v2.0.15
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/google/uuid v1.3.0
github.com/shopspring/decimal v1.3.1
)

View File

@ -6,7 +6,7 @@ replace github.com/gogf/gf/v2 => ../../../
require (
gitee.com/chunanyong/dm v1.8.10
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
)
require (

View File

@ -4,7 +4,7 @@ go 1.18
require (
github.com/denisenkom/go-mssqldb v0.12.3
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
)
require (

View File

@ -4,7 +4,7 @@ go 1.18
require (
github.com/go-sql-driver/mysql v1.7.1
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
)
require (

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/oracle/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/sijms/go-ora/v2 v2.7.10
)

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/pgsql/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/lib/pq v1.10.9
)

View File

@ -4,7 +4,7 @@ go 1.18
require (
github.com/glebarez/go-sqlite v1.21.2
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
)
require (

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/drivers/sqlitecgo/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/mattn/go-sqlite3 v1.14.17
)

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/nosql/redis/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/redis/go-redis/v9 v9.0.5
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/trace v1.14.0

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/etcd/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
go.etcd.io/etcd/client/v3 v3.5.7
)

View File

@ -2,7 +2,7 @@ module github.com/gogf/gf/contrib/registry/file/v2
go 1.18
require github.com/gogf/gf/v2 v2.5.5
require github.com/gogf/gf/v2 v2.5.6
require (
github.com/BurntSushi/toml v1.2.0 // indirect

View File

@ -0,0 +1,81 @@
# GoFrame Nacos Registry
Use `nacos` as service registration and discovery management.
## Installation
```
go get -u -v github.com/gogf/gf/contrib/registry/nacos/v2
```
suggested using `go.mod`:
```
require github.com/gogf/gf/contrib/registry/nacos/v2 latest
```
## Example
### Reference example
[server](example/registry/nacos/server/main.go)
```go
package main
import (
"github.com/gogf/gf/contrib/registry/nacos/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/net/gsvc"
)
func main() {
gsvc.SetRegistry(nacos.New(`127.0.0.1:8848`).
SetClusterName("DEFAULT").
SetGroupName("DEFAULT_GROUP"))
s := g.Server(`hello.svc`)
s.BindHandler("/", func(r *ghttp.Request) {
g.Log().Info(r.Context(), `request received`)
r.Response.Write(`Hello world`)
})
s.Run()
}
```
[client](example/registry/nacos/client/main.go)
```go
package main
import (
"fmt"
"time"
"github.com/gogf/gf/contrib/registry/nacos/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/gsel"
"github.com/gogf/gf/v2/net/gsvc"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
gsvc.SetRegistry(nacos.New(`127.0.0.1:8848`))
gsel.SetBuilder(gsel.NewBuilderRoundRobin())
client := g.Client()
for i := 0; i < 100; i++ {
res, err := client.Get(gctx.New(), `http://hello.svc/`)
if err != nil {
panic(err)
}
fmt.Println(res.ReadAllString())
res.Close()
time.Sleep(time.Second)
}
}
```
## License
`GoFrame Nacos` is licensed under the [MIT License](../../../LICENSE), 100% free and open-source, forever.

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/nacos/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa
)

View File

@ -136,7 +136,7 @@ func TestWatch(t *testing.T) {
t.AssertNil(err)
t.Assert(registered.GetName(), svc2.GetName())
time.Sleep(time.Second * 1)
time.Sleep(time.Second * 10)
// Watch and retrieve the service changes:
// svc1 and svc2 is the same service name, which has 2 endpoints.
@ -154,7 +154,7 @@ func TestWatch(t *testing.T) {
err = registry2.Deregister(ctx, svc2)
t.AssertNil(err)
time.Sleep(time.Second * 1)
time.Sleep(time.Second * 10)
proceedResult, err = watcher.Proceed()
t.AssertNil(err)
t.Assert(len(proceedResult), 1)

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/registry/polaris/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
github.com/polarismesh/polaris-go v1.5.4
)

View File

@ -4,7 +4,7 @@ go 1.18
require (
github.com/go-zookeeper/zk v1.0.3
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
golang.org/x/sync v0.3.0
)

View File

@ -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.5.5
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/contrib/registry/file/v2 v2.5.6
github.com/gogf/gf/v2 v2.5.6
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/trace v1.14.0
google.golang.org/grpc v1.57.0

View File

@ -88,6 +88,7 @@ func (s modServer) UnaryAllowNilRes(
}
// UnaryTracing is a unary interceptor for adding tracing feature for gRPC server using OpenTelemetry.
// The tracing feature is builtin enabled.
func (s modServer) UnaryTracing(
ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler,
) (interface{}, error) {

View File

@ -27,7 +27,7 @@ import (
)
// UnaryServerInterceptor returns a grpc.UnaryServerInterceptor suitable
// for use in a grpc.NewServer call.
// for usage in a grpc.NewServer call.
func UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
tracer := otel.GetTracerProvider().Tracer(
tracingInstrumentGrpcServer,

View File

@ -2,7 +2,7 @@ module github.com/gogf/gf/contrib/sdk/httpclient/v2
go 1.18
require github.com/gogf/gf/v2 v2.5.5
require github.com/gogf/gf/v2 v2.5.6
require (
github.com/BurntSushi/toml v1.2.0 // indirect

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/jaeger/v2
go 1.18
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
go.opentelemetry.io/otel v1.14.0
go.opentelemetry.io/otel/exporters/jaeger v1.14.0
go.opentelemetry.io/otel/sdk v1.14.0

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/otlpgrpc/v2
go 1.20
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
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

View File

@ -3,7 +3,7 @@ module github.com/gogf/gf/contrib/trace/otlphttp/v2
go 1.20
require (
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.6
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

View File

@ -3,24 +3,26 @@ module github.com/gogf/gf/example
go 1.20
require (
github.com/gogf/gf/contrib/config/apollo/v2 v2.5.5
github.com/gogf/gf/contrib/config/consul/v2 v2.5.5
github.com/gogf/gf/contrib/config/kubecm/v2 v2.5.5
github.com/gogf/gf/contrib/config/nacos/v2 v2.5.5
github.com/gogf/gf/contrib/config/polaris/v2 v2.5.5
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.5
github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.5
github.com/gogf/gf/contrib/registry/etcd/v2 v2.5.5
github.com/gogf/gf/contrib/registry/file/v2 v2.5.5
github.com/gogf/gf/contrib/registry/polaris/v2 v2.5.5
github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.5.5
github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.5.5
github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.5.5
github.com/gogf/gf/v2 v2.5.5
github.com/gogf/gf/contrib/config/apollo/v2 v2.5.6
github.com/gogf/gf/contrib/config/consul/v2 v2.5.6
github.com/gogf/gf/contrib/config/kubecm/v2 v2.5.6
github.com/gogf/gf/contrib/config/nacos/v2 v2.5.6
github.com/gogf/gf/contrib/config/polaris/v2 v2.5.6
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.5.6
github.com/gogf/gf/contrib/nosql/redis/v2 v2.5.6
github.com/gogf/gf/contrib/registry/etcd/v2 v2.5.6
github.com/gogf/gf/contrib/registry/file/v2 v2.5.6
github.com/gogf/gf/contrib/registry/nacos/v2 v2.5.5
github.com/gogf/gf/contrib/registry/polaris/v2 v2.5.6
github.com/gogf/gf/contrib/rpc/grpcx/v2 v2.5.6
github.com/gogf/gf/contrib/trace/otlpgrpc/v2 v2.5.6
github.com/gogf/gf/contrib/trace/otlphttp/v2 v2.5.6
github.com/gogf/gf/v2 v2.5.6
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.4
golang.org/x/time v0.3.0
google.golang.org/grpc v1.58.2
google.golang.org/protobuf v1.31.0
k8s.io/client-go v0.27.4
@ -52,6 +54,7 @@ require (
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
@ -71,6 +74,7 @@ require (
github.com/imdario/mergo v0.3.6 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
@ -123,7 +127,6 @@ require (
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230920204549-e6e6cdab5c13 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 // indirect

View File

@ -296,6 +296,8 @@ github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogf/gf/contrib/registry/nacos/v2 v2.5.5 h1:SX/Hm8lTVmS+Jgr96nhEfIjkPVFb/G1WHBrJnSkaWtY=
github.com/gogf/gf/contrib/registry/nacos/v2 v2.5.5/go.mod h1:sjXCL0HbPyvRGYHEnuihLfXSkXXrMmoDNKj5D8JT8r0=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
@ -468,6 +470,8 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5i
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa h1:FPzhsWW/aZQKw9tWOTvLc8lpKLGnPVBMaF0B+DIvKlc=
github.com/joy999/nacos-sdk-go v0.0.0-20231008093845-7f2f84bc6faa/go.mod h1:vks3UUh7Hp+e5qbvDySGnvVCD0RYqjyDy/RpVMSf3xc=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
@ -975,8 +979,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44=
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View File

@ -0,0 +1,52 @@
package main
import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"golang.org/x/time/rate"
)
type HelloReq struct {
g.Meta `path:"/hello" method:"get" sort:"1"`
Name string `v:"required" dc:"Your name"`
}
type HelloRes struct {
Reply string `dc:"Reply content"`
}
type Hello struct{}
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
}
var limiter = rate.NewLimiter(rate.Limit(10), 1) // 10 request per second
func Limiter(r *ghttp.Request) {
if !limiter.Allow() {
r.Response.WriteStatusExit(429)
r.ExitAll()
}
r.Middleware.Next()
}
// curl "http://127.0.0.1:8080/hello?name=world"
func main() {
s := g.Server()
s.Use(Limiter, ghttp.MiddlewareHandlerResponse)
s.Group("/", func(group *ghttp.RouterGroup) {
group.Bind(
new(Hello),
)
})
s.SetPort(8080)
s.Run()
}

View File

@ -0,0 +1,31 @@
// 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 (
"github.com/gogf/gf/contrib/registry/nacos/v2"
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
"github.com/gogf/gf/example/registry/etcd/grpc/protobuf"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
grpcx.Resolver.Register(nacos.New("127.0.0.1:8848"))
var (
ctx = gctx.New()
conn = grpcx.Client.MustNewGrpcClientConn("demo")
client = protobuf.NewGreeterClient(conn)
)
res, err := client.SayHello(ctx, &protobuf.HelloRequest{Name: "World"})
if err != nil {
g.Log().Error(ctx, err)
return
}
g.Log().Debug(ctx, "Response:", res.Message)
}

View File

@ -0,0 +1,27 @@
// 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 controller
import (
"context"
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
"github.com/gogf/gf/example/registry/etcd/grpc/protobuf"
)
type Controller struct {
protobuf.UnimplementedGreeterServer
}
func Register(s *grpcx.GrpcServer) {
protobuf.RegisterGreeterServer(s.Server, &Controller{})
}
// SayHello implements helloworld.GreeterServer
func (s *Controller) SayHello(ctx context.Context, in *protobuf.HelloRequest) (*protobuf.HelloReply, error) {
return &protobuf.HelloReply{Message: "Hello " + in.GetName()}, nil
}

View File

@ -0,0 +1,217 @@
// protoc --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. *.proto
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v3.21.12
// source: helloworld.proto
package protobuf
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// The request message containing the user's name.
type HelloRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
func (x *HelloRequest) Reset() {
*x = HelloRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_helloworld_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HelloRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HelloRequest) ProtoMessage() {}
func (x *HelloRequest) ProtoReflect() protoreflect.Message {
mi := &file_helloworld_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use HelloRequest.ProtoReflect.Descriptor instead.
func (*HelloRequest) Descriptor() ([]byte, []int) {
return file_helloworld_proto_rawDescGZIP(), []int{0}
}
func (x *HelloRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
// The response message containing the greetings
type HelloReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
}
func (x *HelloReply) Reset() {
*x = HelloReply{}
if protoimpl.UnsafeEnabled {
mi := &file_helloworld_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HelloReply) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HelloReply) ProtoMessage() {}
func (x *HelloReply) ProtoReflect() protoreflect.Message {
mi := &file_helloworld_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use HelloReply.ProtoReflect.Descriptor instead.
func (*HelloReply) Descriptor() ([]byte, []int) {
return file_helloworld_proto_rawDescGZIP(), []int{1}
}
func (x *HelloReply) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
var File_helloworld_proto protoreflect.FileDescriptor
var file_helloworld_proto_rawDesc = []byte{
0x0a, 0x10, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x12, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x22, 0x22, 0x0a, 0x0c,
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
0x22, 0x26, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18,
0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x45, 0x0a, 0x07, 0x47, 0x72, 0x65, 0x65,
0x74, 0x65, 0x72, 0x12, 0x3a, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12,
0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42,
0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x6f,
0x67, 0x66, 0x2f, 0x67, 0x66, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70,
0x6c, 0x65, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_helloworld_proto_rawDescOnce sync.Once
file_helloworld_proto_rawDescData = file_helloworld_proto_rawDesc
)
func file_helloworld_proto_rawDescGZIP() []byte {
file_helloworld_proto_rawDescOnce.Do(func() {
file_helloworld_proto_rawDescData = protoimpl.X.CompressGZIP(file_helloworld_proto_rawDescData)
})
return file_helloworld_proto_rawDescData
}
var file_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_helloworld_proto_goTypes = []interface{}{
(*HelloRequest)(nil), // 0: protobuf.HelloRequest
(*HelloReply)(nil), // 1: protobuf.HelloReply
}
var file_helloworld_proto_depIdxs = []int32{
0, // 0: protobuf.Greeter.SayHello:input_type -> protobuf.HelloRequest
1, // 1: protobuf.Greeter.SayHello:output_type -> protobuf.HelloReply
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_helloworld_proto_init() }
func file_helloworld_proto_init() {
if File_helloworld_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_helloworld_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HelloRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_helloworld_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HelloReply); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_helloworld_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_helloworld_proto_goTypes,
DependencyIndexes: file_helloworld_proto_depIdxs,
MessageInfos: file_helloworld_proto_msgTypes,
}.Build()
File_helloworld_proto = out.File
file_helloworld_proto_rawDesc = nil
file_helloworld_proto_goTypes = nil
file_helloworld_proto_depIdxs = nil
}

View File

@ -0,0 +1,24 @@
// protoc --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. *.proto
syntax = "proto3";
package protobuf;
option go_package = "github.com/gogf/gf/grpc/example/helloworld/protobuf";
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}

View File

@ -0,0 +1,107 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v3.21.12
// source: helloworld.proto
package protobuf
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// GreeterClient is the client API for Greeter service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type GreeterClient interface {
// Sends a greeting
SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error)
}
type greeterClient struct {
cc grpc.ClientConnInterface
}
func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient {
return &greeterClient{cc}
}
func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) {
out := new(HelloReply)
err := c.cc.Invoke(ctx, "/protobuf.Greeter/SayHello", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// GreeterServer is the server API for Greeter service.
// All implementations must embed UnimplementedGreeterServer
// for forward compatibility
type GreeterServer interface {
// Sends a greeting
SayHello(context.Context, *HelloRequest) (*HelloReply, error)
mustEmbedUnimplementedGreeterServer()
}
// UnimplementedGreeterServer must be embedded to have forward compatible implementations.
type UnimplementedGreeterServer struct {
}
func (UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) {
return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented")
}
func (UnimplementedGreeterServer) mustEmbedUnimplementedGreeterServer() {}
// UnsafeGreeterServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to GreeterServer will
// result in compilation errors.
type UnsafeGreeterServer interface {
mustEmbedUnimplementedGreeterServer()
}
func RegisterGreeterServer(s grpc.ServiceRegistrar, srv GreeterServer) {
s.RegisterService(&Greeter_ServiceDesc, srv)
}
func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HelloRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(GreeterServer).SayHello(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/protobuf.Greeter/SayHello",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GreeterServer).SayHello(ctx, req.(*HelloRequest))
}
return interceptor(ctx, in, info, handler)
}
// Greeter_ServiceDesc is the grpc.ServiceDesc for Greeter service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Greeter_ServiceDesc = grpc.ServiceDesc{
ServiceName: "protobuf.Greeter",
HandlerType: (*GreeterServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "SayHello",
Handler: _Greeter_SayHello_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "helloworld.proto",
}

View File

@ -0,0 +1,8 @@
grpc:
name: "demo"
logPath: "./log"
logStdout: true
errorLogEnabled: true
accessLogEnabled: true
errorStack: true

View File

@ -0,0 +1,23 @@
// 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 (
"github.com/gogf/gf/contrib/registry/nacos/v2"
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
"github.com/gogf/gf/example/registry/etcd/grpc/controller"
)
func main() {
grpcx.Resolver.Register(nacos.New("127.0.0.1:8848").
SetClusterName("DEFAULT").
SetGroupName("DEFAULT_GROUP"))
s := grpcx.Server.New()
controller.Register(s)
s.Run()
}

View File

@ -0,0 +1,21 @@
// 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 (
"github.com/gogf/gf/contrib/registry/nacos/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/gsvc"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {
gsvc.SetRegistry(nacos.New(`127.0.0.1:8848`))
ctx := gctx.New()
res := g.Client().GetContent(ctx, `http://hello.svc/`)
g.Log().Info(ctx, res)
}

View File

@ -0,0 +1,25 @@
// 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 (
"github.com/gogf/gf/contrib/registry/nacos/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/net/gsvc"
)
func main() {
gsvc.SetRegistry(nacos.New(`127.0.0.1:8848`))
s := g.Server(`hello.svc`)
s.BindHandler("/", func(r *ghttp.Request) {
g.Log().Info(r.Context(), `request received`)
r.Response.Write(`Hello world`)
})
s.Run()
}

View File

@ -257,13 +257,11 @@ func (s *Server) checkAndCreateFuncInfo(
return funcInfo, err
}
funcInfo.ReqStructFields = fields
funcInfo.Func = createRouterFunc(funcInfo, inputObject, inputObjectPtr)
funcInfo.Func = createRouterFunc(funcInfo)
return
}
func createRouterFunc(
funcInfo handlerFuncInfo, inputObject reflect.Value, inputObjectPtr interface{},
) func(r *Request) {
func createRouterFunc(funcInfo handlerFuncInfo) func(r *Request) {
return func(r *Request) {
var (
ok bool
@ -272,11 +270,20 @@ func createRouterFunc(
reflect.ValueOf(r.Context()),
}
)
r.error = r.Parse(inputObjectPtr)
if r.error != nil {
return
if funcInfo.Type.NumIn() == 2 {
var inputObject reflect.Value
if funcInfo.Type.In(1).Kind() == reflect.Ptr {
inputObject = reflect.New(funcInfo.Type.In(1).Elem())
r.error = r.Parse(inputObject.Interface())
} else {
inputObject = reflect.New(funcInfo.Type.In(1).Elem()).Elem()
r.error = r.Parse(inputObject.Addr().Interface())
}
if r.error != nil {
return
}
inputValues = append(inputValues, inputObject)
}
inputValues = append(inputValues, inputObject)
// Call handler with dynamic created parameter values.
results := funcInfo.Value.Call(inputValues)
switch len(results) {

View File

@ -439,3 +439,38 @@ func Test_Issue2963(t *testing.T) {
t.Assert(c.GetContent(ctx, "/"+gurl.Encode("中文G146(1)-icon.txt")), `中文G146(1)-icon`)
})
}
type Issue3077Req struct {
g.Meta `path:"/echo" method:"get"`
A string `default:"a"`
B string `default:""`
}
type Issue3077Res struct {
g.Meta `mime:"text/html"`
}
type Issue3077V1 struct{}
func (c *Issue3077V1) Hello(ctx context.Context, req *Issue3077Req) (res *Issue3077Res, err error) {
g.RequestFromCtx(ctx).Response.Write(fmt.Sprintf("%v", req))
return
}
// https://github.com/gogf/gf/issues/3077
func Test_Issue3077(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
s := g.Server(guid.S())
s.Group("/", func(group *ghttp.RouterGroup) {
group.Bind(Issue3077V1{})
})
s.SetDumpRouterMap(false)
s.Start()
defer s.Shutdown()
time.Sleep(100 * time.Millisecond)
c := g.Client()
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
t.Assert(c.GetContent(ctx, "/echo?a=1&b=2"), `&{{} 1 2}`)
t.Assert(c.GetContent(ctx, "/echo?"), `&{{} a }`)
})
}

View File

@ -2,5 +2,5 @@ package gf
const (
// VERSION is the current GoFrame version.
VERSION = "v2.5.5"
VERSION = "v2.5.6"
)