-
Notifications
You must be signed in to change notification settings - Fork 5
Refactor Event Meta field from map to structured types #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Changed the Event.Meta field from map[string]interface{} to a strongly-typed
struct with protocol-specific substructures for DNS, HTTP, SMTP, FTP, and GeoIP
metadata.
Key changes:
- Created Meta struct with optional fields for each protocol type
- Defined DNSMeta, HTTPMeta, SMTPMeta, FTPMeta, and GeoIPMeta types
- Updated all event handlers to use new typed structures
- Modified actionsdb to convert Meta struct to map for API compatibility
- Updated notification modules (Slack, Lark, Telegram) to access typed fields
- Updated all tests to use new Meta structure
- Maintained backward compatibility through JSON serialization/deserialization
This refactoring provides better type safety, improved IDE support, and clearer
code documentation for event metadata handling across all protocols.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request refactors the Event.Meta field from an untyped map[string]interface{} to a strongly-typed struct with protocol-specific substructures. This change significantly improves type safety, IDE support, and code maintainability across the codebase.
Key changes:
- Replaced map-based Meta with typed struct containing optional protocol-specific metadata (DNS, HTTP, SMTP, FTP, GeoIP)
- Updated all event handlers to construct typed structures instead of using reflection-based map conversion
- Modified notification modules to access typed fields with proper nil checks
- Maintained backward compatibility through JSON marshaling/unmarshaling for API responses
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
internal/database/models/event.go |
Defines new Meta struct and protocol-specific metadata types (DNSMeta, HTTPMeta, SMTPMeta, FTPMeta, GeoIPMeta) with appropriate JSON tags |
internal/cmd/server/dns.go |
Removed local type definitions and structs dependency; constructs DNSMeta directly |
internal/cmd/server/http.go |
Removed local type definitions and structs dependency; constructs HTTPMeta directly |
internal/cmd/server/smtp.go |
Removed local type definitions and structs dependency; constructs SMTPMeta directly using shared models |
internal/cmd/server/ftp.go |
Removed structs dependency; maps FTP session data to FTPMeta struct |
internal/cmd/server/events.go |
Updates GeoIP handling to create GeoIPMeta struct directly instead of using StructToMap |
internal/modules/telegram/notifier.go |
Accesses typed SMTP metadata with nil checks instead of type assertions on map |
internal/modules/slack/notifier.go |
Accesses typed SMTP metadata with nil checks instead of type assertions on map |
internal/modules/lark/notifier.go |
Accesses typed SMTP metadata with nil checks instead of type assertions on map |
internal/modules/slack/block/block.go |
Uses typed field access for GeoIP and SMTP metadata instead of map operations |
internal/modules/slack/block/block_test.go |
Updates test fixtures to use typed Meta structure |
internal/modules/lark/card/v2/card.go |
Uses typed field access for GeoIP and SMTP metadata instead of map operations |
internal/modules/lark/card/v2/card_test.go |
Updates test fixtures to use typed Meta structure |
internal/actionsdb/events.go |
Converts Meta struct back to map for API response compatibility using JSON marshaling |
internal/database/events_test.go |
Updates tests to use typed Meta; validates backward compatibility with old fixture data |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| if subject, ok := email["subject"].(string); ok { | ||
| if n.Event.Meta.SMTP.Email.Subject != "" { |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is redundant since it's already checked in the parent if statement on line 98. The subject field check can be removed here as it's part of the parent condition.
| } | ||
|
|
||
| if subject, ok := email["subject"].(string); ok { | ||
| if n.Event.Meta.SMTP.Email.Subject != "" { |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is redundant since it's already checked in the parent if statement on line 236. The subject field check can be removed here as it's part of the parent condition.
Changed the Event.Meta field from map[string]interface{} to a strongly-typed
struct with protocol-specific substructures for DNS, HTTP, SMTP, FTP, and GeoIP
metadata.
Key changes:
This refactoring provides better type safety, improved IDE support, and clearer
code documentation for event metadata handling across all protocols.