-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
server.go
54 lines (43 loc) · 1.11 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package textboard
import (
"context"
"net/http"
"google.golang.org/protobuf/types/known/emptypb"
"github.com/twitchtv/twirp"
pb "github.com/robbydyer/sports/internal/proto/basicboard"
)
// Server ...
type Server struct {
board *TextBoard
}
// GetRPCHandler ...
func (s *TextBoard) GetRPCHandler() (string, http.Handler) {
return s.rpcServer.PathPrefix(), s.rpcServer
}
// SetStatus ...
func (s *Server) SetStatus(ctx context.Context, req *pb.SetStatusReq) (*emptypb.Empty, error) {
if req.Status == nil {
return &emptypb.Empty{}, twirp.NewError(twirp.InvalidArgument, "nil status sent")
}
cancelBoard := false
if s.board.Enabler().Store(req.Status.Enabled) {
cancelBoard = true
}
if cancelBoard {
select {
case s.board.cancelBoard <- struct{}{}:
s.board.log.Info("sent cancel board signal on status change")
default:
}
}
return &emptypb.Empty{}, nil
}
// GetStatus ...
func (s *Server) GetStatus(ctx context.Context, req *emptypb.Empty) (*pb.StatusResp, error) {
return &pb.StatusResp{
Status: &pb.Status{
Enabled: s.board.Enabler().Enabled(),
ScrollEnabled: true,
},
}, nil
}