rcvr.go 631 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package impl
  4. import (
  5. "context"
  6. "smart-alarm/impl/v1/monitor"
  7. "smart-alarm/pb"
  8. "smart-alarm/pb/v1"
  9. "github.com/jaryhe/gopkgs/tasker/rpctasker"
  10. "google.golang.org/grpc"
  11. )
  12. // 具体实现
  13. type Rcvr struct {
  14. }
  15. func Register(s *grpc.Server) {
  16. pb.RegisterSmartAlarmServer(s, &Rcvr{})
  17. }
  18. func (c *Rcvr) AlarmAdd(ctx context.Context, req *v1.AlarmAddRequest) (reply *v1.AlarmAddReply, err error) {
  19. t1 := func() error {
  20. reply, err = monitor.AlarmAdd(ctx, req)
  21. return err
  22. }
  23. return reply, rpctasker.Exec(ctx, t1)
  24. }