Files
ai 4cf590ef5f perf!: streaming I/O refactoring, full test coverage, and v3.0.0
- Implemented streaming processing for constant memory footprint.
- Optimized memory usage: reduced allocations from 185 to 99.
- Migrated `config.Direction` to typed Enum.
- Added comprehensive test suite for config, cgp, rspamc and internal logic.
- Cleaned up loop protection and action handlers.
2026-03-05 23:19:40 +03:00

52 lines
1.0 KiB
Go

package config
import (
"fmt"
)
type Direction int
const (
DirBoth Direction = iota
DirIn
DirOut
)
// MarshalYAML позволяет Marshal печатать строку вместо числа
func (d Direction) MarshalYAML() (any, error) {
return d.String(), nil
}
// String реализует интерфейс fmt.Stringer
func (d Direction) String() string {
switch d {
case DirIn:
return "in"
case DirOut:
return "out"
case DirBoth:
return "both"
default:
return fmt.Sprintf("unknown(%d)", d)
}
}
// UnmarshalYAML позволяет прозрачно читать "in", "out", "both" из конфига
func (d *Direction) UnmarshalYAML(unmarshal func(any) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
switch s {
case "in":
*d = DirIn
case "out":
*d = DirOut
case "both", "": // Пустое значение трактуем как both
*d = DirBoth
default:
return fmt.Errorf("invalid direction: %s (want: in, out, both)", s)
}
return nil
}