Rename env vars prefix to ND_

This commit is contained in:
Deluan 2020-01-24 01:29:31 -05:00
parent d48ddacaba
commit bff6f3a4bd
18 changed files with 42 additions and 42 deletions

View File

@ -44,9 +44,9 @@ COPY --from=gobuilder /src/navidrome /app/
COPY --from=gobuilder /tmp/ffmpeg*/ffmpeg /usr/bin/
VOLUME ["/data", "/music"]
ENV SONIC_DBPATH /data/navidrome.db
ENV SONIC_MUSICFOLDER /music
ENV SONIC_LOGLEVEL info
ENV ND_DBPATH /data/navidrome.db
ENV ND_MUSICFOLDER /music
ENV ND_LOGLEVEL info
EXPOSE 4533
WORKDIR /app

View File

@ -50,10 +50,10 @@ services:
- "4533:4533"
environment:
# All options with their default values:
SONIC_MUSICFOLDER: /music
SONIC_PORT: 4533
SONIC_SCANINTERVAL: 10s
SONIC_LOGLEVEL: debug
ND_MUSICFOLDER: /music
ND_PORT: 4533
ND_SCANINTERVAL: 10s
ND_LOGLEVEL: debug
volumes:
- "./data:/data"
- "/Users/deluan/Music/iTunes/iTunes Media/Music:/music"

View File

@ -8,7 +8,7 @@ import (
"github.com/koding/multiconfig"
)
type sonic struct {
type nd struct {
Port string `default:"4533"`
MusicFolder string `default:"./music"`
DbPath string `default:"./data/navidrome.db"`
@ -30,20 +30,20 @@ type sonic struct {
DevInitialPassword string `default:""`
}
var Sonic *sonic
var Server *nd
func LoadFromFlags() {
l := &multiconfig.FlagLoader{}
l.Load(Sonic)
l.Load(Server)
}
func LoadFromEnv() {
port := os.Getenv("PORT")
if port != "" {
Sonic.Port = port
Server.Port = port
}
l := &multiconfig.EnvironmentLoader{}
err := l.Load(Sonic)
err := l.Load(Server)
if err != nil {
log.Error("Error parsing configuration from environment")
}
@ -51,12 +51,12 @@ func LoadFromEnv() {
func LoadFromTags() {
l := &multiconfig.TagLoader{}
l.Load(Sonic)
l.Load(Server)
}
func LoadFromFile(tomlFile string) {
l := &multiconfig.TOMLLoader{Path: tomlFile}
err := l.Load(Sonic)
err := l.Load(Server)
if err != nil {
log.Error("Error loading configuration file", "file", tomlFile, err)
}
@ -72,10 +72,10 @@ func Load() {
LoadFromLocalFile()
LoadFromEnv()
LoadFromFlags()
log.SetLogLevelString(Sonic.LogLevel)
log.SetLogLevelString(Server.LogLevel)
}
func init() {
Sonic = new(sonic)
Server = new(nd)
LoadFromTags()
}

View File

@ -8,9 +8,9 @@ services:
- "4533:4533"
environment:
# See all options and defaults in conf/configuration.go
SONIC_PORT: 4533
SONIC_SCANINTERVAL: 5s
SONIC_LOGLEVEL: debug
ND_PORT: 4533
ND_SCANINTERVAL: 5s
ND_LOGLEVEL: debug
volumes:
- "./data:/data"
- "/Users/deluan/Music/iTunes/iTunes Media/Music:/music"

View File

@ -16,7 +16,7 @@ import (
func Stream(ctx context.Context, path string, bitRate int, maxBitRate int, w io.Writer) error {
var f io.Reader
var err error
enabled := !conf.Sonic.DisableDownsampling
enabled := !conf.Server.DisableDownsampling
if enabled && maxBitRate > 0 && bitRate > maxBitRate {
f, err = downsample(ctx, path, maxBitRate)
} else {
@ -46,7 +46,7 @@ func downsample(ctx context.Context, path string, maxBitRate int) (f io.Reader,
}
func createDownsamplingCommand(path string, maxBitRate int) (string, []string) {
cmd := conf.Sonic.DownsampleCommand
cmd := conf.Server.DownsampleCommand
split := strings.Split(cmd, " ")
for i, s := range split {

View File

@ -8,12 +8,12 @@ import (
func main() {
conf.Load()
if !conf.Sonic.DevDisableBanner {
if !conf.Server.DevDisableBanner {
server.ShowBanner()
}
a := CreateServer(conf.Sonic.MusicFolder)
a := CreateServer(conf.Server.MusicFolder)
a.MountRouter("/rest", CreateSubsonicAPIRouter())
a.MountRouter("/app", CreateAppRouter("/app"))
a.Run(":" + conf.Sonic.Port)
a.Run(":" + conf.Server.Port)
}

View File

@ -28,7 +28,7 @@ type artistRepository struct {
func NewArtistRepository(o orm.Ormer) model.ArtistRepository {
r := &artistRepository{}
r.ormer = o
r.indexGroups = utils.ParseIndexGroups(conf.Sonic.IndexGroups)
r.indexGroups = utils.ParseIndexGroups(conf.Server.IndexGroups)
r.tableName = "artist"
return r
}

View File

@ -15,7 +15,7 @@ func NewMediaFolderRepository(o orm.Ormer) model.MediaFolderRepository {
}
func (*mediaFolderRepository) GetAll() (model.MediaFolders, error) {
mediaFolder := model.MediaFolder{ID: "0", Path: conf.Sonic.MusicFolder}
mediaFolder := model.MediaFolder{ID: "0", Path: conf.Server.MusicFolder}
mediaFolder.Name = "Music Library"
result := make(model.MediaFolders, 1)
result[0] = mediaFolder

View File

@ -27,7 +27,7 @@ type SQLStore struct {
func New() model.DataStore {
once.Do(func() {
dbPath := conf.Sonic.DbPath
dbPath := conf.Server.DbPath
if dbPath == ":memory:" {
dbPath = "file::memory:?cache=shared"
}
@ -114,7 +114,7 @@ func (db *SQLStore) getOrmer() orm.Ormer {
}
func initORM(dbPath string) error {
verbose := conf.Sonic.LogLevel == "trace"
verbose := conf.Server.LogLevel == "trace"
orm.Debug = verbose
if strings.Contains(dbPath, "postgres") {
driver = "postgres"

View File

@ -60,9 +60,9 @@ func P(path string) string {
var _ = Describe("Initialize test DB", func() {
BeforeSuite(func() {
//log.SetLevel(log.LevelTrace)
//conf.Sonic.DbPath, _ = ioutil.TempDir("", "navidrome_tests")
//os.MkdirAll(conf.Sonic.DbPath, 0700)
conf.Sonic.DbPath = ":memory:"
//conf.Server.DbPath, _ = ioutil.TempDir("", "navidrome_tests")
//os.MkdirAll(conf.Server.DbPath, 0700)
conf.Server.DbPath = ":memory:"
ds := New()
artistRepo := ds.Artist()
for _, a := range testArtists {

View File

@ -216,7 +216,7 @@ func (m *Metadata) parseDuration(tagName string) int {
}
func createProbeCommand(inputs []string) (string, []string) {
cmd := conf.Sonic.ProbeCommand
cmd := conf.Server.ProbeCommand
split := strings.Split(cmd, " ")
args := make([]string, 0)

View File

@ -20,7 +20,7 @@ func xTestScanner(t *testing.T) {
var _ = XDescribe("TODO: REMOVE", func() {
It("WORKS!", func() {
conf.Sonic.DbPath = "./testDB"
conf.Server.DbPath = "./testDB"
log.SetLevel(log.LevelDebug)
ds := persistence.New()

View File

@ -45,7 +45,7 @@ func (app *Router) routes() http.Handler {
r.Post("/login", Login(app.ds))
r.Route("/api", func(r chi.Router) {
if !conf.Sonic.DevDisableAuthentication {
if !conf.Server.DevDisableAuthentication {
r.Use(jwtauth.Verifier(TokenAuth))
r.Use(Authenticator)
}

View File

@ -53,8 +53,8 @@ func createDefaultUser(ds model.DataStore) error {
id, _ := uuid.NewRandom()
random, _ := uuid.NewRandom()
initialPassword := random.String()
if conf.Sonic.DevInitialPassword != "" {
initialPassword = conf.Sonic.DevInitialPassword
if conf.Server.DevInitialPassword != "" {
initialPassword = conf.Server.DevInitialPassword
}
log.Warn("Creating initial user. Please change the password!", "user", consts.InitialUserName, "password", initialPassword)
initialUser := model.User{

View File

@ -68,9 +68,9 @@ func (a *Server) initRoutes() {
}
func (a *Server) initScanner() {
interval, err := time.ParseDuration(conf.Sonic.ScanInterval)
interval, err := time.ParseDuration(conf.Server.ScanInterval)
if err != nil {
log.Error("Invalid interval specification. Using default of 5m", "conf", conf.Sonic.ScanInterval, err)
log.Error("Invalid interval specification. Using default of 5m", "conf", conf.Server.ScanInterval, err)
interval = 5 * time.Minute
} else {
log.Info("Starting scanner", "interval", interval.String())
@ -80,7 +80,7 @@ func (a *Server) initScanner() {
for {
err := a.Scanner.RescanAll(false)
if err != nil {
log.Error("Error scanning media folder", "folder", conf.Sonic.MusicFolder, err)
log.Error("Error scanning media folder", "folder", conf.Server.MusicFolder, err)
}
time.Sleep(interval)
}

View File

@ -48,7 +48,7 @@ func (api *Router) routes() http.Handler {
r.Use(checkRequiredParameters)
// Add validation middleware if not disabled
if !conf.Sonic.DevDisableAuthentication {
if !conf.Server.DevDisableAuthentication {
r.Use(authenticate(api.Users))
// TODO Validate version
}

View File

@ -41,7 +41,7 @@ func (c *BrowsingController) getArtistIndex(r *http.Request, ifModifiedSince tim
}
res := &responses.Indexes{
IgnoredArticles: conf.Sonic.IgnoredArticles,
IgnoredArticles: conf.Server.IgnoredArticles,
LastModified: fmt.Sprint(utils.ToMillis(lastModified)),
}

View File

@ -7,7 +7,7 @@ import (
)
func NoArticle(name string) string {
articles := strings.Split(conf.Sonic.IgnoredArticles, " ")
articles := strings.Split(conf.Server.IgnoredArticles, " ")
for _, a := range articles {
n := strings.TrimPrefix(name, a+" ")
if n != name {