package env import ( "log" "os/exec" "strings" "github.com/joho/godotenv" "github.com/namsral/flag" ) var ( Port int Env string CommitShortSha string ) func Load() error { if err := godotenv.Load(); err != nil { return err } flag.IntVar(&Port, "PORT", 4321, "Server port") flag.StringVar(&Env, "ENV", "development", "Specify environment") return nil } func Parse() { flag.Parse() 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)) }