NewInMemoryAuditLog 创建内存审计日志
(config *AuditConfiguration)
| 400 | |
| 401 | // NewInMemoryAuditLog 创建内存审计日志 |
| 402 | func NewInMemoryAuditLog(config *AuditConfiguration) *InMemoryAuditLog { |
| 403 | if config == nil { |
| 404 | config = &AuditConfiguration{ |
| 405 | StorageType: StorageTypeMemory, |
| 406 | EnableCache: true, |
| 407 | CacheSize: 10000, |
| 408 | CacheTimeout: time.Minute * 5, |
| 409 | WorkerPoolSize: 5, |
| 410 | BatchSize: 100, |
| 411 | FlushInterval: time.Second * 10, |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | al := &InMemoryAuditLog{ |
| 416 | events: make([]AuditEvent, 0), |
| 417 | config: config, |
| 418 | status: &AuditLogStatus{}, |
| 419 | eventChan: make(chan AuditEvent, config.BatchSize*10), |
| 420 | workers: config.WorkerPoolSize, |
| 421 | done: make(chan struct{}), |
| 422 | } |
| 423 | |
| 424 | // 启动工作协程 |
| 425 | for range al.workers { |
| 426 | go al.eventWorker() |
| 427 | } |
| 428 | |
| 429 | return al |
| 430 | } |
| 431 | |
| 432 | // LogEvent 记录事件 |
| 433 | func (al *InMemoryAuditLog) LogEvent(event AuditEvent) error { |