mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
add package contrib/rpc/grpcx (#2169)
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gogf/katyusha/krpc"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -14,7 +15,7 @@ type Client struct {
|
||||
}
|
||||
|
||||
func NewClient(options ...grpc.DialOption) (*Client, error) {
|
||||
conn, err := krpc.Client.NewGrpcClientConn(ServiceName, options...)
|
||||
conn, err := grpcx.Client.NewGrpcClientConn(ServiceName, options...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
// protoc --gofast_out=plugins=grpc:. protocol/user/*.proto -I/Users/john/Workspace/Go/GOPATH/src -I/Users/john/Workspace/Go/GOPATH/src/gitee.com/johng/katyusha/.examples/tracing
|
||||
// protoc --gofast_out=plugins=grpc:. \
|
||||
// protocol/user/*.proto \
|
||||
// -I/Users/john/Workspace/Go/GOPATH/src
|
||||
syntax = "proto3";
|
||||
|
||||
package user;
|
||||
|
||||
@ -1,20 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
"github.com/gogf/gf/contrib/rpc/grpcx/v2"
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/example/trace/grpc_with_db/protobuf/user"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gcache"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/katyusha/krpc"
|
||||
|
||||
"github.com/gogf/gf/example/trace/grpc_with_db/protobuf/user"
|
||||
)
|
||||
|
||||
type server struct{}
|
||||
@ -35,7 +33,7 @@ func main() {
|
||||
// Set ORM cache adapter with redis.
|
||||
g.DB().GetCache().SetAdapter(gcache.NewAdapterRedis(g.Redis()))
|
||||
|
||||
s := krpc.Server.NewGrpcServer()
|
||||
s := grpcx.Server.New()
|
||||
user.RegisterUserServer(s.Server, &server{})
|
||||
s.Run()
|
||||
}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||
"github.com/gogf/gf/contrib/trace/jaeger/v2"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@ -46,7 +45,6 @@ func main() {
|
||||
type InsertReq struct {
|
||||
Name string `v:"required#Please input user name."`
|
||||
}
|
||||
|
||||
type InsertRes struct {
|
||||
Id int64
|
||||
}
|
||||
@ -67,7 +65,6 @@ func (c *cTrace) Insert(ctx context.Context, req *InsertReq) (res *InsertRes, er
|
||||
type QueryReq struct {
|
||||
Id int `v:"min:1#User id is required for querying"`
|
||||
}
|
||||
|
||||
type QueryRes struct {
|
||||
User gdb.Record
|
||||
}
|
||||
@ -92,7 +89,6 @@ func (c *cTrace) Query(ctx context.Context, req *QueryReq) (res *QueryRes, err e
|
||||
type DeleteReq struct {
|
||||
Id int `v:"min:1#User id is required for deleting."`
|
||||
}
|
||||
|
||||
type DeleteRes struct{}
|
||||
|
||||
// Delete is a route handler for deleting specified user info.
|
||||
|
||||
Reference in New Issue
Block a user