A vibe coded tangled fork which supports pijul.
1# appview/web 2 3## package structure 4 5``` 6web/ 7 |- routes.go 8 |- handler/ 9 | |- xrpc/ 10 |- middleware/ 11 |- request/ 12``` 13 14- `web/routes.go` : all possible routes defined in single file 15- `web/handler` : general http handlers 16- `web/handler/xrpc` : xrpc handlers 17- `web/middleware` : all middlwares 18- `web/request` : define methods to insert/fetch values from request context. shared between middlewares and handlers. 19 20### file name convention on `web/handler` 21 22- Follow the absolute uri path of the handlers (replace `/` to `_`.) 23- Trailing path segments can be omitted. 24- Avoid conflicts between prefix and names. 25 - e.g. using both `user_repo_pulls.go` and `user_repo_pulls_rounds.go` (with `user_repo_pulls_` prefix) 26 27### handler-generators instead of raw handler function 28 29instead of: 30```go 31type Handler struct { 32 is isvc.Service 33 rs rsvc.Service 34} 35func (h *Handler) RepoIssues(w http.ResponseWriter, r *http.Request) { 36 // ... 37} 38``` 39 40prefer: 41```go 42func RepoIssues(is isvc.Service, rs rsvc.Service, p *pages.Pages, d *db.DB) http.HandlerFunc { 43 return func(w http.ResponseWriter, r *http.Request) { 44 // ... 45 } 46} 47``` 48 49Pass dependencies to each handler-generators and avoid creating structs with shared dependencies unless it serves somedomain-specific roles like `service/issue.Service`. Same rule applies to middlewares too. 50 51This pattern is inspired by [the grafana blog post](https://grafana.com/blog/how-i-write-http-services-in-go-after-13-years/#maker-funcs-return-the-handler). 52 53Function name can be anything as long as it is clear.