Implement comprehensive weather parsing capabilities following Clean Architecture principles with composite parser pattern for routing between aviation and weather messages. ## Features Added - Weather report parsing (METAR, SPECI, TAF) - Composite parser pattern for message routing - Lenient parsing with warnings for unrecognized tokens - Support for PROB and RMK sections in TAF - Rich domain modeling with typed weather elements ## Architecture **Domain Layer** (internal/domain/weather/): - WeatherMessage interface with Metar and Taf implementations - Weather elements: Wind, Visibility, Cloud, Temperature, Altimeter, Phenomenon - Domain errors: ErrInvalidFormat, ErrMissingStation, ErrMissingTime **Port Layer** (internal/port/weather_parser.go): - WeatherParser interface with CanParse and Parse methods **Adapter Layer** (internal/adapter/parser/weather/): - WeatherParserImpl with classification and parsing logic - Comprehensive regex patterns for weather elements - METAR/SPECI parser with element extraction - TAF parser with period handling (FM, TEMPO, BECMG, PROB) - Helper functions for time parsing and unit conversions **Composite Parser** (internal/adapter/parser/composite.go): - Routes weather reports to weather parser - Falls back to aviation parser for telegrams - Converts WeatherMessage to ParsedTelegram format ## Integration - Updated ProvideParser to create composite parser with weather parser - Added weather parser to Wire DI configuration - Updated processor_bench_test.go for weather parser integration - Documentation added in docs/weather-parser.md ## Testing - 29 comprehensive tests for weather parsing (all passing) - Tests for classification, METAR, SPECI, TAF, and composite routing - Benchmark compatibility maintained ## Fixes Applied - TAF PROB parsing: Include PROB/RMK in special section detection - Composite test: Updated to use properly formatted AFTN telegram - Linter issues: Switch statement refactor, removed unused patterns - Ineffective break statement fixed in TAF parser ## Coverage ~1,743 lines of new code with: - Complete METAR/SPECI parsing - TAF parsing with period support - Lenient error handling with warnings - Unit conversions and time utilities 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
//go:build wireinject
|
|
|
|
package di
|
|
|
|
import (
|
|
"caatsm/internal/adapter/parser"
|
|
weatherparser "caatsm/internal/adapter/parser/weather"
|
|
"caatsm/internal/app"
|
|
"caatsm/internal/infra/config"
|
|
"caatsm/internal/infra/log"
|
|
"caatsm/internal/infra/monitoring"
|
|
"caatsm/internal/infra/nats"
|
|
"caatsm/internal/infra/postgres"
|
|
"caatsm/internal/infra/telemetry"
|
|
|
|
"github.com/google/wire"
|
|
)
|
|
|
|
// InitializeApp initializes the application with all dependencies
|
|
func InitializeApp() (*app.MessageProcessor, *nats.Consumer, *monitoring.Server, error) {
|
|
comps, err := buildAppComponents()
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
return comps.Processor, comps.Consumer, comps.Monitoring, nil
|
|
}
|
|
|
|
// InitializeAppWithConfig wires dependencies using a pre-loaded configuration.
|
|
func InitializeAppWithConfig(cfg *config.Config) (*app.MessageProcessor, *nats.Consumer, *monitoring.Server, error) {
|
|
comps, err := buildAppComponentsWithConfig(cfg)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
return comps.Processor, comps.Consumer, comps.Monitoring, nil
|
|
}
|
|
|
|
var runtimeSet = wire.NewSet(
|
|
// Logger
|
|
log.ProvideLogger,
|
|
|
|
// Database
|
|
postgres.ProvideDB,
|
|
postgres.ProvideRepository,
|
|
|
|
// NATS
|
|
nats.ProvideNATSConn,
|
|
nats.ProvideJetStream,
|
|
nats.ProvidePublisher,
|
|
|
|
// Weather Parser
|
|
weatherparser.NewWeatherParser,
|
|
|
|
// Parser (composite, depends on weather parser)
|
|
parser.ProvideParser,
|
|
|
|
// Telemetry
|
|
telemetry.ProvideRecorder,
|
|
|
|
// App
|
|
app.NewMessageProcessor,
|
|
|
|
// Consumer
|
|
nats.ProvideConsumer,
|
|
|
|
// Monitoring HTTP server
|
|
monitoring.ProvideServer,
|
|
)
|
|
|
|
func buildAppComponents() (*appComponents, error) {
|
|
wire.Build(
|
|
config.ProvideConfig,
|
|
runtimeSet,
|
|
wire.Struct(new(appComponents), "*"),
|
|
)
|
|
return nil, nil
|
|
}
|
|
|
|
func buildAppComponentsWithConfig(cfg *config.Config) (*appComponents, error) {
|
|
wire.Build(
|
|
runtimeSet,
|
|
wire.Struct(new(appComponents), "*"),
|
|
)
|
|
return nil, nil
|
|
}
|
|
|
|
type appComponents struct {
|
|
Processor *app.MessageProcessor
|
|
Consumer *nats.Consumer
|
|
Monitoring *monitoring.Server
|
|
}
|