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