archive/ArchiveServer.go

44 lines
758 B
Go
Raw Normal View History

2017-08-13 01:57:08 +00:00
package archive
import (
"fmt"
"time"
)
const (
SERVER_VERSION = "archive/3.0"
)
type ArchiveServer struct {
timezone *time.Location
cfg *Config
startup time.Time
2017-08-13 01:57:08 +00:00
}
func NewArchiveServer(cfg *Config) (*ArchiveServer, error) {
tz, err := time.LoadLocation(cfg.Timezone)
if err != nil {
return nil, err
}
if cfg.LinesPerPage <= 0 {
return nil, fmt.Errorf("Invalid %d lines per page", cfg.LinesPerPage)
}
if len(cfg.Logs) == 0 {
return nil, fmt.Errorf("No log sources configured")
}
for _, ls := range cfg.Logs {
if len(ls.FileLocation) == 0 {
return nil, fmt.Errorf(`No file locations for log source "%s"`, ls.Description)
}
}
return &ArchiveServer{
timezone: tz,
cfg: cfg,
startup: time.Now(),
2017-08-13 01:57:08 +00:00
}, nil
}