migrate from envars to toml config
This commit is contained in:
parent
5284b8a7cc
commit
04f7f97b62
12 changed files with 182 additions and 109 deletions
37
main.go
37
main.go
|
@ -24,29 +24,38 @@ const DEFAULT_PORT int64 = 8080
|
|||
|
||||
func main() {
|
||||
// initialise database connection
|
||||
var dbHost = os.Getenv("ARIMELODY_DB_HOST")
|
||||
var dbName = os.Getenv("ARIMELODY_DB_NAME")
|
||||
var dbUser = os.Getenv("ARIMELODY_DB_USER")
|
||||
var dbPass = os.Getenv("ARIMELODY_DB_PASS")
|
||||
if dbHost == "" {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: ARIMELODY_DB_HOST not provided! Exiting...\n")
|
||||
if env := os.Getenv("ARIMELODY_DB_HOST"); env != "" { global.Config.DB.Host = env }
|
||||
if env := os.Getenv("ARIMELODY_DB_NAME"); env != "" { global.Config.DB.Name = env }
|
||||
if env := os.Getenv("ARIMELODY_DB_USER"); env != "" { global.Config.DB.User = env }
|
||||
if env := os.Getenv("ARIMELODY_DB_PASS"); env != "" { global.Config.DB.Pass = env }
|
||||
if global.Config.DB.Host == "" {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: db.host not provided! Exiting...\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
if dbName == "" {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: ARIMELODY_DB_NAME not provided! Exiting...\n")
|
||||
if global.Config.DB.Name == "" {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: db.name not provided! Exiting...\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
if dbUser == "" {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: ARIMELODY_DB_USER not provided! Exiting...\n")
|
||||
if global.Config.DB.User == "" {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: db.user not provided! Exiting...\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
if dbPass == "" {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: ARIMELODY_DB_PASS not provided! Exiting...\n")
|
||||
if global.Config.DB.Pass == "" {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: db.pass not provided! Exiting...\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var err error
|
||||
global.DB, err = sqlx.Connect("postgres", fmt.Sprintf("host=%s user=%s dbname=%s password=%s sslmode=disable", dbHost, dbUser, dbName, dbPass))
|
||||
global.DB, err = sqlx.Connect(
|
||||
"postgres",
|
||||
fmt.Sprintf(
|
||||
"host=%s user=%s dbname=%s password='%s' sslmode=disable",
|
||||
global.Config.DB.Host,
|
||||
global.Config.DB.User,
|
||||
global.Config.DB.Name,
|
||||
global.Config.DB.Pass,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: Unable to create database connection pool: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
@ -72,7 +81,7 @@ func createServeMux() *http.ServeMux {
|
|||
mux.Handle("/admin/", http.StripPrefix("/admin", admin.Handler()))
|
||||
mux.Handle("/api/", http.StripPrefix("/api", api.Handler()))
|
||||
mux.Handle("/music/", http.StripPrefix("/music", view.MusicHandler()))
|
||||
mux.Handle("/uploads/", http.StripPrefix("/uploads", staticHandler(filepath.Join(global.DATA_DIR, "uploads"))))
|
||||
mux.Handle("/uploads/", http.StripPrefix("/uploads", staticHandler(filepath.Join(global.Config.DataDirectory, "uploads"))))
|
||||
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/" || r.URL.Path == "/index.html" {
|
||||
err := templates.Pages["index"].Execute(w, nil)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue