Web 服务

This commit is contained in:
奶爸
2019-12-08 16:59:58 +08:00
parent 5a21ce6ca6
commit d8c4364653
33 changed files with 1112 additions and 21 deletions

40
service/rpc/nezha.go Normal file
View File

@@ -0,0 +1,40 @@
package rpc
import (
"context"
"fmt"
pb "github.com/p14yground/nezha/proto"
)
// NezhaHandler ..
type NezhaHandler struct {
Auth *AuthHandler
}
// ReportState ..
func (s *NezhaHandler) ReportState(c context.Context, r *pb.State) (*pb.Receipt, error) {
if err := s.Auth.Check(c); err != nil {
return nil, err
}
fmt.Printf("ReportState receive: %s\n", r)
return &pb.Receipt{Proced: true}, nil
}
// Heartbeat ..
func (s *NezhaHandler) Heartbeat(r *pb.Beat, stream pb.NezhaService_HeartbeatServer) error {
if err := s.Auth.Check(stream.Context()); err != nil {
return err
}
fmt.Printf("ReportState receive: %s\n", r)
return nil
}
// Register ..
func (s *NezhaHandler) Register(c context.Context, r *pb.Host) (*pb.Receipt, error) {
if err := s.Auth.Check(c); err != nil {
return nil, err
}
fmt.Printf("Register receive: %s\n", r)
return &pb.Receipt{Proced: true}, nil
}