76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/app"
|
|
grpcopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
|
|
httpopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
|
|
weatherpb "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/api/v1alpha1/weather"
|
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient"
|
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/ambientgrpc"
|
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/ambienthttp"
|
|
)
|
|
|
|
func prepareApp(ctx context.Context, aw *ambient.AmbientWeather) *app.App {
|
|
// Load ambient routes into app
|
|
awApp := &app.App{
|
|
AppContext: ctx,
|
|
|
|
// HTTP Endpoints for Ambient Weather Stations
|
|
HTTP: &httpopts.AppHTTP{
|
|
Funcs: []httpopts.HTTPFunc{
|
|
{
|
|
Path: "/weatherstation/updateweatherstation.php",
|
|
HandlerFunc: aw.GetWundergroundHandlerFunc(ctx),
|
|
},
|
|
{
|
|
Path: "/data/report",
|
|
HandlerFunc: aw.GetAWNHandlerFunc(ctx),
|
|
},
|
|
},
|
|
|
|
// HTTP Listener that fixes broken requests generated by
|
|
// some versions of awn firmware
|
|
CustomListener: ambienthttp.NewAWNMutatingListener(ctx,
|
|
aw.Config.HTTP.Listen), // Necessary to fix certain bad AWN firmware
|
|
|
|
HealthChecks: []httpopts.HealthCheckFunc{
|
|
// Check recorder health
|
|
// Only redis implements this
|
|
func(ctx context.Context) error {
|
|
var errs error
|
|
errs = errors.Join(errs, aw.GetRecorder().Ping(ctx))
|
|
return errs
|
|
},
|
|
},
|
|
},
|
|
|
|
// GRPC Service for retrieving weather
|
|
GRPC: &grpcopts.AppGRPC{
|
|
GRPCDialOpts: []grpc.DialOption{
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
},
|
|
GRPCGatewayOpts: aw.GetGatewayOpts(),
|
|
Services: []*grpcopts.GRPCService{
|
|
{
|
|
Name: "Weather Service",
|
|
Type: &weatherpb.AmbientLocalWeatherService_ServiceDesc,
|
|
Service: ambientgrpc.NewGRPCWeather(ctx, aw.GetRecorder()),
|
|
GwRegistrationFuncs: []grpcopts.GwRegistrationFunc{
|
|
// HTTP API via grpc-gateway. Update path in app grpc config
|
|
// to change default (/grpcapi)
|
|
weatherpb.RegisterAmbientLocalWeatherServiceHandler,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
return awApp
|
|
}
|