-
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
Andreas Lindfalk
committed
May 24, 2022
1 parent
8e048c2
commit b85f89e
Showing
2 changed files
with
65 additions
and
2 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 |
---|---|---|
|
@@ -4,4 +4,65 @@ Since we only have one port on Cloud Run, but want to serve both the "native" gR | |
|
||
Opentelemetry instrumentation is configured for the gRPC server via the [otelgrpc](https://pkg.go.dev/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc) lib to intercept both unary and stream communication. | ||
|
||
// TODO: continue... | ||
Which handler to use is configurable, provide your implementation of choice by setting "HttpAndGrpcHandlerFunc" in the config. If this is not provided then the "DefaultHttpAndGrpcHandlerFunc" is used, and we also provide a "CorsHttpAndGrpcHandlerFunc" that handles preflight requests so have a closer look at: [handlers.go](https://github.com/dentech-floss/server/blob/master/pkg/server/handlers.go). | ||
|
||
## Install | ||
|
||
``` | ||
go get github.com/dentech-floss/[email protected] | ||
``` | ||
|
||
## Usage | ||
|
||
```go | ||
package example | ||
|
||
import ( | ||
"github.com/dentech-floss/server/pkg/server" | ||
) | ||
|
||
func main() { | ||
|
||
ctx := context.Background() | ||
|
||
... | ||
|
||
appointmentServiceV1 := service.NewAppointmentServiceV1(repo, publisher, logger) | ||
patientGatewayServiceV1 := service.NewPatientGatewayServiceV1(repo, publisher, logger) | ||
|
||
... | ||
|
||
_server := server.NewServer( | ||
&server.ServerConfig{ | ||
Port: config.Port, | ||
// The "DefaultHttpAndGrpcHandlerFunc" will be used if you don't set this | ||
// HttpAndGrpcHandlerFunc: server.CorsHttpAndGrpcHandlerFunc | ||
}, | ||
) | ||
|
||
appointmentServiceV1.Register(_server.GrpcServer) | ||
appointmentServiceV1.RegisterMux(ctx, _server.GrpcMux) // if you use the grpc gateway | ||
|
||
patientGatewayServiceV1.Register(_server.GrpcServer) | ||
patientGatewayServiceV1.RegisterMux(ctx, _server.GrpcMux) | ||
|
||
go _server.Serve() | ||
handleShutdown(_server, logger) | ||
} | ||
|
||
func handleShutdown( | ||
_server *service.Server, | ||
logger *logging.Logger, | ||
) { | ||
done := make(chan os.Signal, 1) | ||
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) | ||
sig := <-done // Block until we receive our signal | ||
logger.Info("Got signal: " + sig.String()) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
if err := _server.Shutdown(ctx); err != nil { | ||
logger.Warn("Server shutdown failed: " + err.Error()) | ||
} | ||
} | ||
``` |
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