archive/Config.go
2017-08-13 13:57:08 +12:00

59 lines
1.1 KiB
Go

package archive
import (
"time"
)
type YearMonth struct {
Year int
// time.Month is a 1-based month counting system
Month time.Month
}
type LogLocation struct {
// LogFilePath will be passed to time.Format().
LogFilePath string
StartMonth YearMonth
// Leave null to use a current/ongoing log
EndMonth *YearMonth
}
type LogSource struct {
Description string
// Short strings by which this source can be identified. If any slugs are
// present, the first slug will be used as the canonical URL.
Slugs []string
// Disk location of logs for this source, for each partial date range
FileLocation []LogLocation
}
func (this *LogSource) LatestDate() YearMonth {
// assume it's the last in the list (although it might not be)
end := this.FileLocation[len(this.FileLocation)-1].EndMonth
if end == nil {
return YearMonth{time.Now().Year(), time.Now().Month()}
} else {
return *end
}
}
type Config struct {
Timezone string
LinesPerPage int
Logs []LogSource
}
func NewConfig() *Config {
return &Config{
Timezone: time.Local.String(),
LinesPerPage: 100,
Logs: make([]LogSource, 0),
}
}