🐛 Bug fixes on connection and package naming

This commit is contained in:
2024-06-17 22:21:34 +08:00
parent 80ee964afa
commit 9c3b42f078
53 changed files with 236 additions and 137 deletions

View File

@ -3,8 +3,8 @@ package grpc
import (
"context"
"git.solsynth.dev/hydrogen/passport/pkg/grpc/proto"
"git.solsynth.dev/hydrogen/passport/pkg/services"
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
"git.solsynth.dev/hydrogen/passport/pkg/proto"
jsoniter "github.com/json-iterator/go"
"github.com/samber/lo"
)

View File

@ -3,9 +3,9 @@ package grpc
import (
"context"
"fmt"
"git.solsynth.dev/hydrogen/passport/pkg/grpc/proto"
"git.solsynth.dev/hydrogen/passport/pkg/models"
"git.solsynth.dev/hydrogen/passport/pkg/services"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
"git.solsynth.dev/hydrogen/passport/pkg/proto"
"github.com/samber/lo"
)

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

@ -4,9 +4,9 @@ import (
"context"
jsoniter "github.com/json-iterator/go"
"git.solsynth.dev/hydrogen/passport/pkg/grpc/proto"
"git.solsynth.dev/hydrogen/passport/pkg/models"
"git.solsynth.dev/hydrogen/passport/pkg/services"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
"git.solsynth.dev/hydrogen/passport/pkg/proto"
"github.com/samber/lo"
)

View File

@ -3,10 +3,10 @@ package grpc
import (
"context"
"fmt"
"git.solsynth.dev/hydrogen/passport/pkg/database"
"git.solsynth.dev/hydrogen/passport/pkg/models"
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
"git.solsynth.dev/hydrogen/passport/pkg/proto"
"git.solsynth.dev/hydrogen/passport/pkg/services"
"github.com/samber/lo"
"google.golang.org/protobuf/types/known/emptypb"
)

View File

@ -1,35 +1,43 @@
package grpc
import (
"google.golang.org/grpc/reflection"
"net"
"git.solsynth.dev/hydrogen/passport/pkg/grpc/proto"
"git.solsynth.dev/hydrogen/passport/pkg/proto"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
import health "google.golang.org/grpc/health/grpc_health_v1"
type Server struct {
proto.UnimplementedAuthServer
proto.UnimplementedNotifyServer
proto.UnimplementedFriendshipsServer
proto.UnimplementedRealmsServer
health.UnimplementedHealthServer
}
func StartGrpc() error {
var S *grpc.Server
func NewGRPC() {
S = grpc.NewServer()
proto.RegisterAuthServer(S, &Server{})
proto.RegisterNotifyServer(S, &Server{})
proto.RegisterFriendshipsServer(S, &Server{})
proto.RegisterRealmsServer(S, &Server{})
health.RegisterHealthServer(S, &Server{})
reflection.Register(S)
}
func ListenGRPC() error {
listen, err := net.Listen("tcp", viper.GetString("grpc_bind"))
if err != nil {
return err
}
server := grpc.NewServer()
proto.RegisterAuthServer(server, &Server{})
proto.RegisterNotifyServer(server, &Server{})
proto.RegisterFriendshipsServer(server, &Server{})
proto.RegisterRealmsServer(server, &Server{})
reflection.Register(server)
return server.Serve(listen)
return S.Serve(listen)
}