moth/cmd/mothd/theme.go

41 lines
690 B
Go
Raw Permalink Normal View History

2019-09-02 18:42:27 -06:00
package main
import (
"time"
2020-08-17 17:43:57 -06:00
"github.com/spf13/afero"
2019-09-02 18:42:27 -06:00
)
2020-08-17 17:43:57 -06:00
// Theme defines a filesystem-backed ThemeProvider.
2019-09-02 18:42:27 -06:00
type Theme struct {
afero.Fs
2019-09-02 18:42:27 -06:00
}
2020-08-17 17:43:57 -06:00
// NewTheme returns a new Theme, backed by Fs.
2019-12-05 22:25:03 -07:00
func NewTheme(fs afero.Fs) *Theme {
2019-09-02 18:42:27 -06:00
return &Theme{
Fs: fs,
2019-09-02 18:42:27 -06:00
}
}
2020-08-17 17:43:57 -06:00
// Open returns a new opened file.
2020-03-01 16:10:55 -07:00
func (t *Theme) Open(name string) (ReadSeekCloser, time.Time, error) {
f, err := t.Fs.Open(name)
if err != nil {
return nil, time.Time{}, err
}
2020-08-17 17:43:57 -06:00
2020-03-01 16:10:55 -07:00
fi, err := f.Stat()
if err != nil {
f.Close()
return nil, time.Time{}, err
2019-09-02 18:42:27 -06:00
}
2020-08-17 17:43:57 -06:00
2020-03-01 16:10:55 -07:00
return f, fi.ModTime(), nil
}
2019-09-02 18:42:27 -06:00
2020-08-18 17:04:23 -06:00
// Maintain performs housekeeping for a Theme.
func (t *Theme) Maintain(i time.Duration) {
// No periodic tasks for a theme
2019-09-02 18:42:27 -06:00
}