2024-12-26 22:46:18 +00:00
|
|
|
package env
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"github.com/namsral/flag"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Port int
|
2024-12-26 23:34:56 +00:00
|
|
|
PublicUrl string
|
2024-12-26 22:46:18 +00:00
|
|
|
PhoenixdURL string
|
|
|
|
PhoenixdLimitedAccessToken string
|
|
|
|
CommitLongSha string
|
|
|
|
CommitShortSha string
|
2024-12-27 02:54:09 +00:00
|
|
|
Env string
|
2024-12-26 22:46:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Load(filenames ...string) error {
|
|
|
|
if err := godotenv.Load(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
flag.IntVar(&Port, "PORT", 4444, "Server port")
|
2024-12-26 23:34:56 +00:00
|
|
|
flag.StringVar(&PublicUrl, "PUBLIC_URL", "", "Base URL")
|
2024-12-26 22:46:18 +00:00
|
|
|
flag.StringVar(&PhoenixdURL, "PHOENIXD_URL", "", "Phoenixd URL")
|
|
|
|
flag.StringVar(&PhoenixdLimitedAccessToken, "PHOENIXD_LIMITED_ACCESS_TOKEN", "", "Phoenixd limited access token")
|
2024-12-27 02:54:09 +00:00
|
|
|
flag.StringVar(&Env, "ENV", "development", "Build environment")
|
2024-12-26 22:46:18 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Parse() {
|
|
|
|
flag.Parse()
|
|
|
|
CommitLongSha = execCmd("git", "rev-parse", "HEAD")
|
|
|
|
CommitShortSha = execCmd("git", "rev-parse", "--short", "HEAD")
|
|
|
|
}
|
|
|
|
|
|
|
|
func execCmd(name string, args ...string) string {
|
|
|
|
cmd := exec.Command(name, args...)
|
|
|
|
stdout, err := cmd.Output()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(string(stdout))
|
|
|
|
}
|