62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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"
|
|
|
|
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/ambienthttp"
|
|
weathergrpc "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/grpc"
|
|
)
|
|
|
|
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
|
|
|
|
// Health check funcs
|
|
HealthChecks: []httpopts.HealthCheckFunc{
|
|
// TODO: Implement
|
|
func(ctx context.Context) error {
|
|
return nil
|
|
},
|
|
},
|
|
},
|
|
|
|
// GRPC Service for retrieving weather
|
|
GRPC: &grpcopts.AppGRPC{
|
|
Services: []*grpcopts.GRPCService{
|
|
{
|
|
Name: "Weather Service",
|
|
Type: &weatherpb.AmbientLocalWeatherService_ServiceDesc,
|
|
Service: weathergrpc.NewGRPCWeather(ctx, aw.GetRecorder()),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
return awApp
|
|
}
|