Files
go-server-with-otel/pkg/demo/demo.go
Ryan McGuire c1c296a0c0
All checks were successful
Build and Publish / check-chart (push) Successful in 14s
Build and Publish / helm-release (push) Has been skipped
Build and Publish / release (push) Successful in 4m30s
improve shutdown and app service boilerplate
2025-07-20 18:16:12 -04:00

55 lines
1.6 KiB
Go

// Package demo provides a reference implementation
// of service.AppService. It packages out the GRPC and HTTP
// functionality, for the sake of structure.
package demo
import (
"context"
optsgrpc "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
optshttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/config"
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/demo/demogrpc"
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/demo/demohttp"
"gitea.libretechconsulting.com/rmcguire/go-server-with-otel/pkg/service"
)
type DemoService struct {
ctx context.Context
config *config.ServiceConfig
http *demohttp.DemoHTTPServer
grpc *demogrpc.DemoGRPCServer
}
func (d *DemoService) Init(ctx context.Context, config *config.ServiceConfig,
) (service.ShutdownFunc, error) {
d.config = config
d.ctx = ctx
// These don't HAVE to be split into separate packages
// This is, after all, a demo app. Just implement the interface.
d.http = demohttp.NewDemoHTTPServer(ctx, config)
d.grpc = demogrpc.NewDemoGRPCServer(ctx, config)
// TODO: This should actually do shutdown stuff
return func(_ context.Context) (string, error) {
return "DemoService", nil
}, nil
}
func (d *DemoService) GetGRPC() *optsgrpc.AppGRPC {
return &optsgrpc.AppGRPC{
Services: d.grpc.GetServices(),
GRPCDialOpts: d.grpc.GetDialOpts(),
}
}
func (d *DemoService) GetHTTP() *optshttp.AppHTTP {
return &optshttp.AppHTTP{
Ctx: d.ctx,
Funcs: d.http.GetHandleFuncs(),
HealthChecks: d.http.GetHealthCheckFuncs(),
}
}