Add cachePath variable and CLI option
This commit is contained in:
@@ -20,6 +20,7 @@ func main() {
|
||||
set := flag.NewFlagSet(version.NAME, flag.ExitOnError)
|
||||
listenAddr := set.String("listen-addr", "0.0.0.0:4747", "listen address (optional)")
|
||||
musicPath := set.String("music-path", "", "path to music")
|
||||
cachePath := set.String("cache-path", "", "path to cache")
|
||||
dbPath := set.String("db-path", "gonic.db", "path to database (optional)")
|
||||
scanInterval := set.Int("scan-interval", 0, "interval (in minutes) to automatically scan music (optional)")
|
||||
proxyPrefix := set.String("proxy-prefix", "", "url path prefix to use if behind proxy. eg '/gonic' (optional)")
|
||||
@@ -39,6 +40,9 @@ func main() {
|
||||
if _, err := os.Stat(*musicPath); os.IsNotExist(err) {
|
||||
log.Fatal("please provide a valid music directory")
|
||||
}
|
||||
if _, err := os.Stat(*cachePath); os.IsNotExist(err) {
|
||||
log.Fatal("please provide a valid cache directory")
|
||||
}
|
||||
db, err := db.New(*dbPath)
|
||||
if err != nil {
|
||||
log.Fatalf("error opening database: %v\n", err)
|
||||
@@ -49,6 +53,7 @@ func main() {
|
||||
serverOptions := server.Options{
|
||||
DB: db,
|
||||
MusicPath: *musicPath,
|
||||
CachePath: *cachePath,
|
||||
ListenAddr: *listenAddr,
|
||||
ScanInterval: time.Duration(*scanInterval) * time.Minute,
|
||||
ProxyPrefix: *proxyPrefix,
|
||||
|
||||
@@ -47,6 +47,7 @@ func statusToBlock(code int) string {
|
||||
type Controller struct {
|
||||
DB *db.DB
|
||||
MusicPath string
|
||||
CachePath string
|
||||
Scanner *scanner.Scanner
|
||||
ProxyPrefix string
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
type Options struct {
|
||||
DB *db.DB
|
||||
MusicPath string
|
||||
CachePath string
|
||||
ListenAddr string
|
||||
ScanInterval time.Duration
|
||||
ProxyPrefix string
|
||||
@@ -35,11 +36,13 @@ type Server struct {
|
||||
func New(opts Options) *Server {
|
||||
// ** begin sanitation
|
||||
opts.MusicPath = filepath.Clean(opts.MusicPath)
|
||||
opts.CachePath = filepath.Clean(opts.CachePath)
|
||||
// ** begin controllers
|
||||
scanner := scanner.New(opts.DB, opts.MusicPath)
|
||||
base := &ctrlbase.Controller{
|
||||
DB: opts.DB,
|
||||
MusicPath: opts.MusicPath,
|
||||
CachePath: opts.CachePath,
|
||||
ProxyPrefix: opts.ProxyPrefix,
|
||||
Scanner: scanner,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user