add service

This commit is contained in:
Владимир Фёдоров 2025-05-17 03:22:10 +07:00
parent 0e399d92eb
commit 8643af86ee
3 changed files with 84 additions and 22 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"evening_detective/internal/app" "evening_detective/internal/app"
"evening_detective/internal/services"
proto "evening_detective/proto" proto "evening_detective/proto"
"log" "log"
"net" "net"
@ -23,7 +24,12 @@ func main() {
// Create a gRPC server object // Create a gRPC server object
s := grpc.NewServer() s := grpc.NewServer()
// Attach the Greeter service to the server // Attach the Greeter service to the server
proto.RegisterEveningDetectiveServer(s, app.NewServer()) proto.RegisterEveningDetectiveServer(
s,
app.NewServer(
services.NewServices(),
),
)
// Serve gRPC server // Serve gRPC server
log.Println("Serving gRPC on 0.0.0.0:8080") log.Println("Serving gRPC on 0.0.0.0:8080")
go func() { go func() {

View File

@ -2,52 +2,60 @@ package app
import ( import (
"context" "context"
"evening_detective/internal/services"
proto "evening_detective/proto" proto "evening_detective/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
) )
type Server struct { type Server struct {
proto.UnimplementedEveningDetectiveServer proto.UnimplementedEveningDetectiveServer
services *services.Services
} }
func NewServer() *Server { func NewServer(
return &Server{} services *services.Services,
) *Server {
return &Server{
services: services,
}
} }
func (s *Server) Ping(_ context.Context, _ *proto.PingReq) (*proto.PingRsp, error) { func (s *Server) Ping(_ context.Context, _ *proto.PingReq) (*proto.PingRsp, error) {
return &proto.PingRsp{}, nil return &proto.PingRsp{}, nil
} }
func (s *Server) AddTeams(context.Context, *proto.AddTeamsReq) (*proto.AddTeamsRsp, error) { func (s *Server) AddTeams(ctx context.Context, req *proto.AddTeamsReq) (*proto.AddTeamsRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method AddTeams not implemented") return s.services.AddTeams(ctx, req)
} }
func (s *Server) GetTeams(context.Context, *proto.GetTeamsReq) (*proto.GetTeamsRsp, error) { func (s *Server) GetTeams(ctx context.Context, req *proto.GetTeamsReq) (*proto.GetTeamsRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetTeams not implemented") return s.services.GetTeams(ctx, req)
} }
func (s *Server) GetTeamsCSV(context.Context, *proto.GetTeamsCSVReq) (*proto.GetTeamsCSVRsp, error) { func (s *Server) GetTeamsCSV(ctx context.Context, req *proto.GetTeamsCSVReq) (*proto.GetTeamsCSVRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetTeamsCSV not implemented") return s.services.GetTeamsCSV(ctx, req)
} }
func (s *Server) DeleteTeams(context.Context, *proto.DeleteTeamsReq) (*proto.DeleteTeamsRsp, error) { func (s *Server) GetTeam(ctx context.Context, req *proto.GetTeamReq) (*proto.GetTeamRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteTeams not implemented") return s.services.GetTeam(ctx, req)
} }
func (s *Server) AddAction(context.Context, *proto.AddActionReq) (*proto.AddActionRsp, error) { func (s *Server) DeleteTeams(ctx context.Context, req *proto.DeleteTeamsReq) (*proto.DeleteTeamsRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method AddAction not implemented") return s.services.DeleteTeams(ctx, req)
} }
func (s *Server) GameStart(context.Context, *proto.GameStartReq) (*proto.GameStartRsp, error) { func (s *Server) AddAction(ctx context.Context, req *proto.AddActionReq) (*proto.AddActionRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GameStart not implemented") return s.services.AddAction(ctx, req)
} }
func (s *Server) GameStop(context.Context, *proto.GameStopReq) (*proto.GameStopRsp, error) { func (s *Server) GameStart(ctx context.Context, req *proto.GameStartReq) (*proto.GameStartRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GameStop not implemented") return s.services.GameStart(ctx, req)
} }
func (s *Server) GiveApplications(context.Context, *proto.GiveApplicationsReq) (*proto.GiveApplicationsRsp, error) { func (s *Server) GameStop(ctx context.Context, req *proto.GameStopReq) (*proto.GameStopRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GiveApplications not implemented") return s.services.GameStop(ctx, req)
}
func (s *Server) GiveApplications(ctx context.Context, req *proto.GiveApplicationsReq) (*proto.GiveApplicationsRsp, error) {
return s.services.GiveApplications(ctx, req)
} }

View File

@ -0,0 +1,48 @@
package services
import (
"context"
"evening_detective/proto"
)
type Services struct{}
func NewServices() *Services {
return &Services{}
}
func (s *Services) GiveApplications(ctx context.Context, req *proto.GiveApplicationsReq) (*proto.GiveApplicationsRsp, error) {
panic("unimplemented")
}
func (s *Services) GameStop(ctx context.Context, req *proto.GameStopReq) (*proto.GameStopRsp, error) {
panic("unimplemented")
}
func (s *Services) GameStart(ctx context.Context, req *proto.GameStartReq) (*proto.GameStartRsp, error) {
panic("unimplemented")
}
func (s *Services) AddAction(ctx context.Context, req *proto.AddActionReq) (*proto.AddActionRsp, error) {
panic("unimplemented")
}
func (s *Services) DeleteTeams(ctx context.Context, req *proto.DeleteTeamsReq) (*proto.DeleteTeamsRsp, error) {
panic("unimplemented")
}
func (s *Services) GetTeam(ctx context.Context, req *proto.GetTeamReq) (*proto.GetTeamRsp, error) {
panic("unimplemented")
}
func (s *Services) GetTeamsCSV(ctx context.Context, req *proto.GetTeamsCSVReq) (*proto.GetTeamsCSVRsp, error) {
panic("unimplemented")
}
func (s *Services) GetTeams(ctx context.Context, req *proto.GetTeamsReq) (*proto.GetTeamsRsp, error) {
panic("unimplemented")
}
func (s *Services) AddTeams(ctx context.Context, req *proto.AddTeamsReq) (*proto.AddTeamsRsp, error) {
panic("unimplemented")
}