arimelody.me/global/data.go

46 lines
916 B
Go

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 {
domain := os.Getenv("ARIMELODY_HTTP_DOMAIN")
if domain == "" {
return "https://arimelody.me"
}
return domain
}()
var DB *sqlx.DB