2023-09-10 15:39:34 +00:00
|
|
|
package env
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
"github.com/namsral/flag"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
Port int
|
|
|
|
PublicURL string
|
|
|
|
Env string
|
|
|
|
CommitLongSha string
|
|
|
|
CommitShortSha string
|
|
|
|
Version string
|
|
|
|
)
|
|
|
|
|
2023-10-04 11:36:54 +00:00
|
|
|
func Load(filenames ...string) error {
|
2023-09-10 15:39:34 +00:00
|
|
|
if err := godotenv.Load(); err != nil {
|
2023-10-04 11:36:54 +00:00
|
|
|
return err
|
2023-09-10 15:39:34 +00:00
|
|
|
}
|
|
|
|
flag.StringVar(&PublicURL, "PUBLIC_URL", "delphi.market", "Public URL of website")
|
|
|
|
flag.IntVar(&Port, "PORT", 4321, "Server port")
|
2023-10-04 11:36:54 +00:00
|
|
|
flag.StringVar(&Env, "ENV", "development", "Specify environment")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Parse() {
|
2023-09-10 15:39:34 +00:00
|
|
|
flag.Parse()
|
|
|
|
CommitLongSha = execCmd("git", "rev-parse", "HEAD")
|
|
|
|
CommitShortSha = execCmd("git", "rev-parse", "--short", "HEAD")
|
|
|
|
Version = fmt.Sprintf("v0.0.0+%s", CommitShortSha)
|
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
}
|