Skip to content

Conversation

@nt0xa
Copy link
Owner

@nt0xa nt0xa commented Jan 9, 2026

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.

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.
Copy link

Copilot AI left a 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 != "" {
Copy link

Copilot AI Jan 9, 2026

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.

Copilot uses AI. Check for mistakes.
}

if subject, ok := email["subject"].(string); ok {
if n.Event.Meta.SMTP.Email.Subject != "" {
Copy link

Copilot AI Jan 9, 2026

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants