🎉 Initial Commit

This commit is contained in:
2024-10-25 00:56:22 +08:00
commit 7597bff972
26 changed files with 2052 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package grpc
import (
"context"
health "google.golang.org/grpc/health/grpc_health_v1"
"time"
)
func (v *Server) Check(ctx context.Context, request *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
return &health.HealthCheckResponse{
Status: health.HealthCheckResponse_SERVING,
}, nil
}
func (v *Server) Watch(request *health.HealthCheckRequest, server health.Health_WatchServer) error {
for {
if server.Send(&health.HealthCheckResponse{
Status: health.HealthCheckResponse_SERVING,
}) != nil {
break
}
time.Sleep(1000 * time.Millisecond)
}
return nil
}

View File

@@ -0,0 +1,36 @@
package grpc
import (
"context"
"git.solsynth.dev/hypernet/pusher/pkg/internal/provider"
"git.solsynth.dev/hypernet/pusher/pkg/proto"
"git.solsynth.dev/hypernet/pusher/pkg/pushkit"
)
func (v *Server) PushNotification(ctx context.Context, request *proto.PushNotificationRequest) (*proto.DeliveryResponse, error) {
err := provider.PushNotification(pushkit.NotificationPushRequest{
Provider: request.GetProvider(),
Token: request.GetDeviceToken(),
Notification: pushkit.NewNotificationFromProto(request.GetNotify()),
})
return &proto.DeliveryResponse{IsSuccess: err == nil}, nil
}
func (v *Server) PushNotificationBatch(ctx context.Context, request *proto.PushNotificationBatchRequest) (*proto.DeliveryResponse, error) {
go provider.PushNotificationBatch(pushkit.NotificationPushBatchRequest{
Providers: request.GetProviders(),
Tokens: request.GetDeviceTokens(),
Notification: pushkit.NewNotificationFromProto(request.GetNotify()),
})
return &proto.DeliveryResponse{IsSuccess: true}, nil
}
func (v *Server) DeliverEmail(ctx context.Context, request *proto.DeliverEmailRequest) (*proto.DeliveryResponse, error) {
//TODO implement me
panic("implement me")
}
func (v *Server) DeliverEmailBatch(ctx context.Context, request *proto.DeliverEmailBatchRequest) (*proto.DeliveryResponse, error) {
//TODO implement me
panic("implement me")
}

View File

@@ -0,0 +1,39 @@
package grpc
import (
"git.solsynth.dev/hypernet/pusher/pkg/proto"
"github.com/spf13/viper"
"google.golang.org/grpc"
health "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/reflection"
"net"
)
type Server struct {
proto.UnimplementedPusherServiceServer
health.UnimplementedHealthServer
srv *grpc.Server
}
func NewServer() *Server {
server := &Server{
srv: grpc.NewServer(),
}
proto.RegisterPusherServiceServer(server.srv, server)
health.RegisterHealthServer(server.srv, server)
reflection.Register(server.srv)
return server
}
func (v *Server) Listen() error {
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
if err != nil {
return err
}
return v.srv.Serve(listener)
}