arimelody.me/global/data.go

55 lines
1.1 KiB
Go
Raw Normal View History

package global
import (
"fmt"
"os"
"strings"
"github.com/jmoiron/sqlx"
)
var Args = func() map[string]string {
args := map[string]string{}
index := 0
for index < len(os.Args[1:]) {
arg := os.Args[index + 1]
if !strings.HasPrefix(arg, "-") {
fmt.Printf("FATAL: Parameters must follow an argument (%s).\n", arg)
os.Exit(1)
}
if index + 3 > len(os.Args) || strings.HasPrefix(os.Args[index + 2], "-") {
args[arg[1:]] = "true"
index += 1
continue
}
val := os.Args[index + 2]
args[arg[1:]] = val
// fmt.Printf("%s: %s\n", arg[1:], val)
index += 2
}
return args
}()
var HTTP_DOMAIN = func() string {
2024-09-03 07:07:45 +00:00
domain := os.Getenv("HTTP_DOMAIN")
if domain == "" {
return "https://arimelody.me"
}
2024-09-03 07:07:45 +00:00
return domain
}()
var APP_SECRET = func() string {
secret := os.Getenv("ARIMELODY_SECRET")
if secret == "" {
fmt.Fprintln(os.Stderr, "FATAL: ARIMELODY_SECRET was not provided. Cannot continue.")
os.Exit(1)
}
return secret
}()
var DB *sqlx.DB