Removed (almost) all remaining init()

This commit is contained in:
Deluan 2020-01-08 10:25:23 -05:00 committed by Deluan Quintão
parent 5d2a7b1db1
commit 23e38ec82f
5 changed files with 34 additions and 23 deletions

View File

@ -11,20 +11,15 @@ const (
ErrorDataNotFound
)
var (
errors map[int]string
)
func init() {
errors = make(map[int]string)
errors[ErrorGeneric] = "A generic error"
errors[ErrorMissingParameter] = "Required parameter is missing"
errors[ErrorClientTooOld] = "Incompatible Subsonic REST protocol version. Client must upgrade"
errors[ErrorServerTooOld] = "Incompatible Subsonic REST protocol version. Server must upgrade"
errors[ErrorAuthenticationFail] = "Wrong username or password"
errors[ErrorAuthorizationFail] = "User is not authorized for the given operation"
errors[ErrorTrialExpired] = "The trial period for the Subsonic server is over. Please upgrade to Subsonic Premium. Visit subsonic.org for details"
errors[ErrorDataNotFound] = "The requested data was not found"
var errors = map[int]string{
ErrorGeneric: "A generic error",
ErrorMissingParameter: "Required parameter is missing",
ErrorClientTooOld: "Incompatible Subsonic REST protocol version. Client must upgrade",
ErrorServerTooOld: "Incompatible Subsonic REST protocol version. Server must upgrade",
ErrorAuthenticationFail: "Wrong username or password",
ErrorAuthorizationFail: "User is not authorized for the given operation",
ErrorTrialExpired: "The trial period for the Subsonic server is over. Please upgrade to Subsonic Premium. Visit subsonic.org for details",
ErrorDataNotFound: "The requested data was not found",
}
func ErrorMsg(code int) string {

1
app.go
View File

@ -22,6 +22,7 @@ type App struct {
func (a *App) Initialize() {
a.logger = logrus.New()
initMimeTypes()
a.initRoutes()
a.initImporter()
}

View File

@ -33,6 +33,20 @@ func LoadFromFlags() {
l.Load(Sonic)
}
func LoadFromEnv() {
port := os.Getenv("PORT")
if port != "" {
Sonic.Port = port
}
l := &multiconfig.EnvironmentLoader{}
l.Load(Sonic)
}
func LoadFromTags() {
l := &multiconfig.TagLoader{}
l.Load(Sonic)
}
func LoadFromFile(tomlFile string) {
l := &multiconfig.TOMLLoader{Path: tomlFile}
err := l.Load(Sonic)
@ -47,11 +61,13 @@ func LoadFromLocalFile() {
}
}
func Load() {
LoadFromLocalFile()
LoadFromEnv()
LoadFromFlags()
}
func init() {
Sonic = new(sonic)
var l multiconfig.Loader
l = &multiconfig.TagLoader{}
l.Load(Sonic)
l = &multiconfig.EnvironmentLoader{}
l.Load(Sonic)
LoadFromTags()
}

View File

@ -8,8 +8,7 @@ import (
)
func main() {
conf.LoadFromLocalFile()
conf.LoadFromFlags()
conf.Load()
fmt.Printf("\nCloudSonic Server v%s\n\n", "0.2")

View File

@ -2,7 +2,7 @@ package main
import "mime"
func init() {
func initMimeTypes() {
mt := map[string]string{
".mp3": "audio/mpeg",
".ogg": "audio/ogg",
@ -39,6 +39,6 @@ func init() {
}
for ext, typ := range mt {
mime.AddExtensionType(ext, typ)
_ = mime.AddExtensionType(ext, typ)
}
}