add grpc support

This commit is contained in:
2025-03-07 15:19:05 -05:00
parent 2cf15a4837
commit 00c8e2e4fc
8 changed files with 95 additions and 68 deletions

View File

@ -17,6 +17,7 @@ import (
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
)
var (
@ -27,20 +28,7 @@ var (
defIdleTimeout = 15 * time.Second
)
type HTTPFunc struct {
Path string
HandlerFunc http.HandlerFunc
}
type HTTPServerOpts struct {
Ctx context.Context
HandleFuncs []HTTPFunc
Middleware []http.Handler
HealthCheckFuncs []HealthCheckFunc
CustomListener net.Listener
}
func prepHTTPServer(opts *HTTPServerOpts) *http.Server {
func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
var (
cfg = config.MustFromCtx(opts.Ctx)
l = zerolog.Ctx(opts.Ctx)
@ -54,11 +42,11 @@ func prepHTTPServer(opts *HTTPServerOpts) *http.Server {
mux.Handle(pattern, handler) // Associate pattern with handler
}
healthChecks := handleHealthCheckFunc(opts.Ctx, opts.HealthCheckFuncs...)
healthChecks := handleHealthCheckFunc(opts.Ctx, opts.HealthChecks...)
otelHandleFunc("/health", healthChecks)
otelHandleFunc("/", healthChecks)
for _, f := range opts.HandleFuncs {
for _, f := range opts.Funcs {
otelHandleFunc(f.Path, f.HandlerFunc)
}
@ -130,7 +118,7 @@ func prepHTTPServer(opts *HTTPServerOpts) *http.Server {
// Returns a shutdown func and a done channel if the
// server aborts abnormally. Returns error on failure to start
func InitHTTPServer(opts *HTTPServerOpts) (
func InitHTTPServer(opts *opts.AppHTTP) (
func(context.Context) error, <-chan any, error,
) {
l := zerolog.Ctx(opts.Ctx)