-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bastien Rigaud
committed
Feb 18, 2024
1 parent
a42acd8
commit 3016352
Showing
19 changed files
with
140 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
run: | ||
air -c .air.toml | ||
cd src && air -c .air.toml | ||
|
||
update: | ||
cd src && go mod tidy | ||
|
||
test: | ||
cd src/tests/integration && go test -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/internal/entity/user/v1/user.go → src/internal/entities/user/v1/user.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package entity_user_v1 | ||
package entities_user_v1 | ||
|
||
import "time" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package handlers_grpc | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/Golerplate/contracts/generated/services/servicesconnect" | ||
"github.com/Golerplate/contracts/generated/services/user/store/v1/storev1connect" | ||
"github.com/Golerplate/pkg/grpc" | ||
pkghandlers "github.com/Golerplate/pkg/grpc/handlers" | ||
sharedmidlewares "github.com/Golerplate/pkg/grpc/interceptors" | ||
"github.com/Golerplate/user-store-svc/internal/handlers" | ||
handlers_grpc_user_v1 "github.com/Golerplate/user-store-svc/internal/handlers/grpc/user/v1" | ||
"github.com/Golerplate/user-store-svc/internal/service" | ||
connectgo "github.com/bufbuild/connect-go" | ||
grpcreflect "github.com/bufbuild/connect-grpcreflect-go" | ||
"github.com/rs/zerolog/log" | ||
"golang.org/x/net/http2" | ||
"golang.org/x/net/http2/h2c" | ||
) | ||
|
||
type grpcServer struct { | ||
grpcServer *http.Server | ||
config grpc.GRPCServerConfig | ||
service service.UserStoreService | ||
} | ||
|
||
func NewServer(ctx context.Context, cfg grpc.GRPCServerConfig, service service.UserStoreService) (handlers.Server, error) { | ||
return &grpcServer{ | ||
config: cfg, | ||
service: service, | ||
}, nil | ||
} | ||
|
||
func (s *grpcServer) Setup(ctx context.Context) error { | ||
log.Info(). | ||
Msg("handlers.grpc.grpcServer.Setup: Setting up gRPC server...") | ||
|
||
userStoreServiceHandler := handlers_grpc_user_v1.NewUserStoreServiceHandler(s.service) | ||
|
||
interceptors := connectgo.WithInterceptors(sharedmidlewares.ServerDefaultChain()...) | ||
|
||
reflector := grpcreflect.NewStaticReflector( | ||
"services.user.store.v1.UserStoreSvc", "services.health.HealthService", | ||
) | ||
|
||
mux := http.NewServeMux() | ||
mux.Handle(servicesconnect.NewHealthServiceHandler(pkghandlers.NewHealthHandler())) | ||
mux.Handle(storev1connect.NewUserStoreSvcHandler(userStoreServiceHandler, interceptors)) | ||
mux.Handle(grpcreflect.NewHandlerV1(reflector)) | ||
mux.Handle(grpcreflect.NewHandlerV1Alpha(reflector)) | ||
|
||
s.grpcServer = &http.Server{ | ||
Addr: fmt.Sprintf(":%d", s.config.Port), | ||
Handler: h2c.NewHandler(mux, &http2.Server{}), | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *grpcServer) Start(ctx context.Context) error { | ||
log.Info(). | ||
Msg("handlers.grpc.grpcServer.Start: Starting gRPC server...") | ||
|
||
return s.grpcServer.ListenAndServe() | ||
} | ||
|
||
func (s *grpcServer) Stop(ctx context.Context) error { | ||
log.Info(). | ||
Msg("handlers.grpc.grpcServer.Stop: Stopping gRPC server...") | ||
|
||
return s.grpcServer.Shutdown(ctx) | ||
} |
6 changes: 3 additions & 3 deletions
6
src/internal/handler/user/v1/init.go → src/internal/handlers/grpc/user/v1/init.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package handlers_grpc_user_v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package handlers | ||
|
||
import "context" | ||
|
||
type Server interface { | ||
Setup(context.Context) error | ||
Start(context.Context) error | ||
Stop(context.Context) error | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters