2021-02-06 16:26:23 +00:00
|
|
|
// Package storage defines interfaces to interact with the files persisted such as the list of servers.
|
2020-08-25 19:38:50 -04:00
|
|
|
package storage
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
|
|
|
"github.com/qdm12/golibs/logging"
|
2021-01-02 01:57:00 +00:00
|
|
|
"github.com/qdm12/golibs/os"
|
2020-08-25 19:38:50 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Storage interface {
|
2020-12-29 17:49:38 +00:00
|
|
|
// Passing an empty filepath disables writing to a file
|
|
|
|
|
SyncServers(hardcodedServers models.AllServers) (allServers models.AllServers, err error)
|
2020-08-28 08:17:04 -04:00
|
|
|
FlushToFile(servers models.AllServers) error
|
2020-08-25 19:38:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type storage struct {
|
2020-12-29 17:49:38 +00:00
|
|
|
os os.OS
|
|
|
|
|
logger logging.Logger
|
|
|
|
|
filepath string
|
2020-08-25 19:38:50 -04:00
|
|
|
}
|
|
|
|
|
|
2020-12-29 17:49:38 +00:00
|
|
|
func New(logger logging.Logger, os os.OS, filepath string) Storage {
|
2020-08-25 19:38:50 -04:00
|
|
|
return &storage{
|
2020-12-29 17:49:38 +00:00
|
|
|
os: os,
|
|
|
|
|
logger: logger.WithPrefix("storage: "),
|
|
|
|
|
filepath: filepath,
|
2020-08-25 19:38:50 -04:00
|
|
|
}
|
|
|
|
|
}
|