archive/ArchiveServer.go

51 lines
1.1 KiB
Go
Raw Normal View History

2017-08-13 01:57:08 +00:00
package archive
import (
"fmt"
"regexp"
2017-08-13 01:57:08 +00:00
"time"
)
const (
SERVER_VERSION = "archive/3.0"
)
type ArchiveServer struct {
timezone *time.Location
cfg *Config
startup time.Time
rxViewRoot, rxViewPage, rxSearch, rxSearchRx *regexp.Regexp
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(),
rxViewRoot: regexp.MustCompile(`^/([^/]+)/(\d+)/(\d+)$`),
rxViewPage: regexp.MustCompile(`^/([^/]+)/(\d+)/(\d+)/(?:page-)?(\d+)$`),
rxSearch: regexp.MustCompile(`^/([^/]+)/search/(.*)$`),
rxSearchRx: regexp.MustCompile(`^/([^/]+)/rx/(.*)$`),
2017-08-13 01:57:08 +00:00
}, nil
}