| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "log" |
| 5 | "log/slog" |
| 6 | "net/http" |
| 7 | "os" |
| 8 | "strings" |
| 9 | |
| 10 | "github.com/stevedylandev/andromeda/pkg/config" |
| 11 | ) |
| 12 | |
| 13 | func main() { |
| 14 | config.LoadDotEnv(".env") |
| 15 | logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo})) |
| 16 | |
| 17 | root := config.Getenv("KEPLER_REPO_ROOT", "./repos") |
| 18 | siteName := config.Getenv("KEPLER_SITE_NAME", "kepler") |
| 19 | baseURL := config.Getenv("KEPLER_BASE_URL", "http://localhost:4747") |
| 20 | cloneBaseURL := config.Getenv("KEPLER_CLONE_BASE_URL", "") |
| 21 | cloneSSHHost := config.Getenv("KEPLER_CLONE_SSH_HOST", "") |
| 22 | |
| 23 | tmpl, err := buildTemplates() |
| 24 | if err != nil { |
| 25 | log.Fatal(err) |
| 26 | } |
| 27 | |
| 28 | app := &App{ |
| 29 | Log: logger, |
| 30 | Templates: tmpl, |
| 31 | RepoRoot: root, |
| 32 | SiteName: siteName, |
| 33 | BaseURL: strings.TrimRight(baseURL, "/"), |
| 34 | CloneBaseURL: strings.TrimRight(cloneBaseURL, "/"), |
| 35 | CloneSSHHost: strings.TrimSpace(cloneSSHHost), |
| 36 | } |
| 37 | |
| 38 | addr := config.Getenv("HOST", "127.0.0.1") + ":" + config.Getenv("PORT", "4747") |
| 39 | logger.Info("kepler server running", "addr", addr, "repo_root", root) |
| 40 | if err := http.ListenAndServe(addr, app.routes()); err != nil { |
| 41 | log.Fatal(err) |
| 42 | } |
| 43 | } |