fix service templates and paths
This commit is contained in:
parent
19a1e3916f
commit
3ac11468a1
7 changed files with 70 additions and 30 deletions
|
|
@ -3,13 +3,12 @@ package app
|
|||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func loadConfig() (Config, error) {
|
||||
projectRoot := expandPath(getenv("PROJECTS_ROOT", "$HOME/projects"))
|
||||
projectRoot := strings.TrimSpace(getenv("PROJECTS_ROOT", "$HOME/projects/$app"))
|
||||
cfg := Config{
|
||||
DatabaseURL: getenv("DATABASE_URL", "postgres://postgres:postgres@localhost:5432/box?sslmode=disable"),
|
||||
ListenAddr: getenv("LISTEN_ADDR", ":8080"),
|
||||
|
|
@ -23,7 +22,6 @@ func loadConfig() (Config, error) {
|
|||
ForgejoToken: getenv("FORGEJO_TOKEN", ""),
|
||||
ForgejoOrg: getenv("FORGEJO_ORG", ""),
|
||||
ProjectRoot: projectRoot,
|
||||
DefaultRunCommand: getenv("DEFAULT_RUN_COMMAND", "go run ."),
|
||||
CaddyAdminURL: strings.TrimRight(getenv("CADDY_ADMIN_URL", "http://localhost:2019"), "/"),
|
||||
CaddyServerID: getenv("CADDY_SERVER_ID", "srv0"),
|
||||
CaddyDomainSuffix: getenv("CADDY_DOMAIN_SUFFIX", ""),
|
||||
|
|
@ -36,23 +34,6 @@ func loadConfig() (Config, error) {
|
|||
return cfg, nil
|
||||
}
|
||||
|
||||
func expandPath(p string) string {
|
||||
p = strings.TrimSpace(p)
|
||||
if p == "" {
|
||||
return filepath.Join(userHomeOrDot(), "projects")
|
||||
}
|
||||
if strings.HasPrefix(p, "~/") {
|
||||
p = filepath.Join(userHomeOrDot(), strings.TrimPrefix(p, "~/"))
|
||||
}
|
||||
p = os.ExpandEnv(p)
|
||||
if !filepath.IsAbs(p) {
|
||||
if abs, err := filepath.Abs(p); err == nil {
|
||||
p = abs
|
||||
}
|
||||
}
|
||||
return filepath.Clean(p)
|
||||
}
|
||||
|
||||
func userHomeOrDot() string {
|
||||
h, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue