Oauth. Car Backups.
This commit is contained in:
30
data/repo.go
30
data/repo.go
@@ -22,22 +22,40 @@ THE SOFTWARE.
|
||||
package data
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"git.bullercodeworks.com/brian/expds/data/models"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Repo struct {
|
||||
LoadedPDSs map[string]*models.Pds
|
||||
BestBy time.Duration
|
||||
|
||||
BestBy time.Duration
|
||||
Auth *AuthRepo
|
||||
|
||||
handler *AppLogHandler
|
||||
logFunc func(string, ...any)
|
||||
}
|
||||
|
||||
func NewRepo() (*Repo, error) {
|
||||
return &Repo{
|
||||
r := &Repo{
|
||||
LoadedPDSs: make(map[string]*models.Pds),
|
||||
BestBy: time.Minute * 15,
|
||||
}, nil
|
||||
handler: NewAppLogHandler(nil),
|
||||
}
|
||||
if viper.GetBool(KeyDebug) {
|
||||
r.handler.SetLevel(slog.LevelDebug)
|
||||
} else {
|
||||
r.handler.SetLevel(slog.LevelWarn)
|
||||
}
|
||||
var err error
|
||||
r.Auth, err = NewAuthRepo(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (r *Repo) GetPDS(atId string) (*models.Pds, error) {
|
||||
@@ -51,3 +69,9 @@ func (r *Repo) GetPDS(atId string) (*models.Pds, error) {
|
||||
r.LoadedPDSs[atId] = p
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (r *Repo) SetLogFunc(l func(string, ...any)) {
|
||||
r.logFunc = l
|
||||
r.handler = NewAppLogHandler(r.logFunc)
|
||||
slog.SetDefault(slog.New(r.handler))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user