add weather grpc
This commit is contained in:
@ -7,7 +7,7 @@ import (
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv"
|
||||
srvhttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http"
|
||||
)
|
||||
|
||||
func (a *App) initGRPC() {
|
||||
@ -26,8 +26,8 @@ func (a *App) initHTTP(ctx context.Context) error {
|
||||
attribute.Int("numHTTPHealthChecks", len(a.HTTP.HealthChecks)),
|
||||
)
|
||||
|
||||
httpShutdown, a.HTTP.httpDone, err = srv.InitHTTPServer(
|
||||
&srv.HTTPServerOpts{
|
||||
httpShutdown, a.HTTP.httpDone, err = srvhttp.InitHTTPServer(
|
||||
&srvhttp.HTTPServerOpts{
|
||||
Ctx: a.AppContext,
|
||||
HandleFuncs: a.HTTP.Funcs,
|
||||
Middleware: a.HTTP.Middleware,
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv"
|
||||
srvhttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
@ -35,9 +35,9 @@ type GRPCService struct {
|
||||
}
|
||||
|
||||
type AppHTTP struct {
|
||||
Funcs []srv.HTTPFunc
|
||||
Funcs []srvhttp.HTTPFunc
|
||||
Middleware []http.Handler
|
||||
HealthChecks []srv.HealthCheckFunc
|
||||
HealthChecks []srvhttp.HealthCheckFunc
|
||||
httpDone <-chan any
|
||||
}
|
||||
|
||||
|
29
pkg/srv/grpc/grpc.go
Normal file
29
pkg/srv/grpc/grpc.go
Normal file
@ -0,0 +1,29 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
|
||||
)
|
||||
|
||||
type AppGRPCServer struct {
|
||||
ctx context.Context
|
||||
tracer trace.Tracer
|
||||
meter metric.Meter
|
||||
}
|
||||
|
||||
func InitGRPCServer(ctx context.Context, opts *opts.GRPCOpts) {
|
||||
server := grpc.NewServer()
|
||||
|
||||
stats := otelgrpc.NewServerHandler(otelgrpc.WithTracerProvider(sdktrace.T))
|
||||
|
||||
for _, service := range opts.Services {
|
||||
server.RegisterService(service.Type, service.Service)
|
||||
}
|
||||
}
|
11
pkg/srv/grpc/opts/grpc_config.go
Normal file
11
pkg/srv/grpc/opts/grpc_config.go
Normal file
@ -0,0 +1,11 @@
|
||||
package opts
|
||||
|
||||
import (
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/config"
|
||||
)
|
||||
|
||||
type GRPCOpts struct {
|
||||
*config.GRPCConfig
|
||||
*app.AppGRPC
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package srv
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -128,17 +128,9 @@ func prepHTTPServer(opts *HTTPServerOpts) *http.Server {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a shutdown func and a done channel if the
|
||||
// server aborts abnormally. Panics on error.
|
||||
func InitHTTPServer(opts *HTTPServerOpts) (
|
||||
func(context.Context) error, <-chan any, error,
|
||||
) {
|
||||
return initHTTPServer(opts)
|
||||
}
|
||||
|
||||
// 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 *HTTPServerOpts) (
|
||||
func(context.Context) error, <-chan any, error,
|
||||
) {
|
||||
l := zerolog.Ctx(opts.Ctx)
|
@ -1,4 +1,4 @@
|
||||
package srv
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package srv
|
||||
package http
|
||||
|
||||
import (
|
||||
"bytes"
|
Reference in New Issue
Block a user