代码拉取完成,页面将自动刷新
package yell
import (
"context"
"errors"
"gitee.com/nonull/eden/pkg/util/xtest/proto/testproto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"time"
)
// FooServer ...
type FooServer struct {
name string
hook func(context.Context)
}
// SetName ...
func (s *FooServer) SetName(f string) {
s.name = f
}
// SetHook ...
func (s *FooServer) SetHook(f func(context.Context)) {
s.hook = f
}
// ErrFoo ...
var ErrFoo = errors.New("error foo")
// RespFantasy ...
var RespFantasy = &testproto.HelloReply{Message: "fantasy"}
// RespBye ...
var RespBye = &testproto.HelloReply{Message: "bye"}
// StatusFoo ...
var StatusFoo = status.Errorf(codes.DataLoss, ErrFoo.Error())
// SayHello ...
func (s *FooServer) SayHello(ctx context.Context, in *testproto.HelloRequest) (out *testproto.HelloReply, err error) {
// sleep to test cost time
time.Sleep(20 * time.Millisecond)
switch in.Name {
case "traceHook":
s.hook(ctx)
err = StatusFoo
case "needErr":
err = StatusFoo
case "slow":
time.Sleep(500 * time.Millisecond)
out = RespFantasy
case "needPanic":
panic("go dead!")
default:
out = RespFantasy
}
return
}
// StreamHello ...
func (s *FooServer) StreamHello(ss testproto.Greeter_StreamHelloServer) (err error) {
for {
in, _ := ss.Recv()
switch in.Name {
case "bye":
return ss.Send(RespBye)
case "needErr":
return StatusFoo
default:
return ss.Send(RespFantasy)
}
}
}
// StreamHello ...
func (s *FooServer) WhoServer(ctx context.Context, in *testproto.WhoServerReq) (out *testproto.WhoServerReply, err error) {
return &testproto.WhoServerReply{Message: s.name}, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。