Files
EvoBGP/internal/runtimelogs/service.go
T
DenozordecandCursor 3f0dd6c234 docs(runtime-logs): implement runtime log management features
Добавлены новые возможности для работы с файловыми логами Docker-сервисов:
- Эндпоинты для получения списка логов и хвоста лог-файла.
- Очистка лог-файлов с возможностью выбора режима (truncate или delete) и запись в аудит очистки.
- Обновлена документация и конфигурация для поддержки новых функций.

Co-authored-by: Cursor <[email protected]>
2026-06-12 19:04:53 +07:00

66 lines
1.3 KiB
Go

package runtimelogs
import (
"os"
"strings"
"evobgp/internal/store"
)
// Service performs filesystem operations on runtime log files.
type Service struct {
cfg Config
}
// NewService returns a runtime logs FS service.
func NewService(cfg Config) *Service {
return &Service{cfg: cfg}
}
// Available reports whether the service can access runtime logs.
func (s *Service) Available() bool {
return s.cfg.Enabled()
}
// Config returns a copy of the service configuration.
func (s *Service) Config() Config {
return s.cfg
}
// ListFiles returns metadata for *.log files in the configured root.
func (s *Service) ListFiles() ([]store.RuntimeLogFile, error) {
if !s.Available() {
return nil, ErrUnavailable
}
entries, err := os.ReadDir(s.cfg.RootDir)
if err != nil {
return nil, err
}
out := make([]store.RuntimeLogFile, 0, len(entries))
for _, ent := range entries {
if ent.IsDir() {
continue
}
name := ent.Name()
if strings.HasPrefix(name, ".") {
continue
}
if err := ValidateFilename(name); err != nil {
continue
}
info, err := ent.Info()
if err != nil {
continue
}
if info.IsDir() {
continue
}
out = append(out, store.RuntimeLogFile{
Name: name,
SizeBytes: info.Size(),
ModifiedAt: info.ModTime().UTC(),
})
}
return out, nil
}