Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,796 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
|
||
package hello; | ||
|
||
option go_package = "./hello"; | ||
|
||
message HelloReq { | ||
string in = 1; | ||
} | ||
|
||
message HelloResp { | ||
string msg = 1; | ||
} | ||
|
||
service Greet { | ||
rpc SayHello(HelloReq) returns (HelloResp); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Name: hello.rpc | ||
ListenOn: 127.0.0.1:8080 | ||
Etcd: | ||
Hosts: | ||
- 127.0.0.1:2379 | ||
Key: hello.rpc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/zeromicro/go-zero/tools/goctl/example/rpc/hello/internal/config" | ||
greetServer "github.com/zeromicro/go-zero/tools/goctl/example/rpc/hello/internal/server/greet" | ||
"github.com/zeromicro/go-zero/tools/goctl/example/rpc/hello/internal/svc" | ||
"github.com/zeromicro/go-zero/tools/goctl/example/rpc/hello/pb/hello" | ||
|
||
"github.com/zeromicro/go-zero/core/conf" | ||
"github.com/zeromicro/go-zero/core/service" | ||
"github.com/zeromicro/go-zero/zrpc" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/reflection" | ||
) | ||
|
||
var configFile = flag.String("f", "etc/hello.yaml", "the config file") | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
var c config.Config | ||
conf.MustLoad(*configFile, &c) | ||
ctx := svc.NewServiceContext(c) | ||
|
||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) { | ||
hello.RegisterGreetServer(grpcServer, greetServer.NewGreetServer(ctx)) | ||
|
||
if c.Mode == service.DevMode || c.Mode == service.TestMode { | ||
reflection.Register(grpcServer) | ||
} | ||
}) | ||
defer s.Stop() | ||
|
||
fmt.Printf("Starting rpc server at %s...\n", c.ListenOn) | ||
s.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package config | ||
|
||
import "github.com/zeromicro/go-zero/zrpc" | ||
|
||
type Config struct { | ||
zrpc.RpcServerConf | ||
} |
30 changes: 30 additions & 0 deletions
30
tools/goctl/example/rpc/hello/internal/logic/greet/sayhellologic.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package greetlogic | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/zeromicro/go-zero/tools/goctl/example/rpc/hello/internal/svc" | ||
"github.com/zeromicro/go-zero/tools/goctl/example/rpc/hello/pb/hello" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
type SayHelloLogic struct { | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
logx.Logger | ||
} | ||
|
||
func NewSayHelloLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SayHelloLogic { | ||
return &SayHelloLogic{ | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
Logger: logx.WithContext(ctx), | ||
} | ||
} | ||
|
||
func (l *SayHelloLogic) SayHello(in *hello.HelloReq) (*hello.HelloResp, error) { | ||
// todo: add your logic here and delete this line | ||
|
||
return &hello.HelloResp{}, nil | ||
} |
28 changes: 28 additions & 0 deletions
28
tools/goctl/example/rpc/hello/internal/server/greet/greetserver.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
tools/goctl/example/rpc/hello/internal/svc/servicecontext.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package svc | ||
|
||
import "github.com/zeromicro/go-zero/tools/goctl/example/rpc/hello/internal/config" | ||
|
||
type ServiceContext struct { | ||
Config config.Config | ||
} | ||
|
||
func NewServiceContext(c config.Config) *ServiceContext { | ||
return &ServiceContext{ | ||
Config: c, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.