From c1d8b171478f72a337d49c23870e146499d2b4b6 Mon Sep 17 00:00:00 2001 From: Blake Ridgway Date: Fri, 24 Apr 2026 19:49:13 -0500 Subject: [PATCH] feat: complete phase 0 --- Makefile | 16 ++++++++++++++++ TODO.md | 18 +++++++++--------- cmd/heloha-server/main.go | 39 +++++++++++++++++++++++++++++++++++++++ go.mod | 5 +++++ go.sum | 2 ++ 5 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 Makefile create mode 100644 cmd/heloha-server/main.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..eb922df --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +BIN := bin/heloha-server +CMD := ./cmd/heloha-server + +.PHONY: build run test tidy + +build: + go build -o $(BIN) $(CMD) + +run: + go run $(CMD) + +test: + go test ./... + +tidy: + go mod tidy diff --git a/TODO.md b/TODO.md index 24e91ba..1bff5be 100644 --- a/TODO.md +++ b/TODO.md @@ -12,21 +12,21 @@ A detailed, actionable task list for building a unified, multi-radar severe weat - [x] `git init` - [x] Create a `.gitignore` file for Go and common OS files. - [x] Create a `README.md` with the project's mission statement. -- [ ] **Establish Go Project Structure:** - - [ ] `go mod init github.com/blakeridgway/heloha` - - [ ] Create a standard Go project layout: +- [x] **Establish Go Project Structure:** + - [x] `go mod init github.com/blakeridgway/heloha` + - [x] Create a standard Go project layout: - `/cmd/heloha-server`: Main application entry point. - `/internal/radar`: Code for fetching, parsing, and processing radar data. - `/internal/server`: HTTP handlers and server logic. - `/internal/config`: Configuration management. - `/web/templates`: HTML templates for the frontend. - `/web/static`: CSS and JavaScript assets. -- [ ] **Create a Basic Web Server:** - - [ ] In `/cmd/heloha-server/main.go`, set up an `http.Server`. - - [ ] Choose and implement a router (e.g., `go-chi/chi` is a good choice for middleware and flexibility). - - [ ] Create a simple `/healthz` endpoint that returns `200 OK`. -- [ ] **Set Up Build Automation:** - - [ ] Create a `Makefile` with targets for: +- [x] **Create a Basic Web Server:** + - [x] In `/cmd/heloha-server/main.go`, set up an `http.Server`. + - [x] Choose and implement a router (e.g., `go-chi/chi` is a good choice for middleware and flexibility). + - [x] Create a simple `/healthz` endpoint that returns `200 OK`. +- [x] **Set Up Build Automation:** + - [x] Create a `Makefile` with targets for: - `build`: `go build -o bin/heloha-server ./cmd/heloha-server` - `run`: `go run ./cmd/heloha-server` - `test`: `go test ./...` diff --git a/cmd/heloha-server/main.go b/cmd/heloha-server/main.go new file mode 100644 index 0000000..5ff7e39 --- /dev/null +++ b/cmd/heloha-server/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "log/slog" + "net/http" + "os" + "time" + + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" +) + +func main() { + logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) + + r := chi.NewRouter() + r.Use(middleware.RequestID) + r.Use(middleware.RealIP) + r.Use(middleware.Recoverer) + + r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("ok")) + }) + + srv := &http.Server{ + Addr: ":8080", + Handler: r, + ReadTimeout: 10 * time.Second, + WriteTimeout: 30 * time.Second, + IdleTimeout: 120 * time.Second, + } + + logger.Info("starting server", "addr", srv.Addr) + if err := srv.ListenAndServe(); err != nil { + logger.Error("server exited", "err", err) + os.Exit(1) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..bb87f7e --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/blakeridgway/heloha + +go 1.25.9 + +require github.com/go-chi/chi/v5 v5.2.5 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a4ac04e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug= +github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=