summaryrefslogtreecommitdiffstats
path: root/cmd/nebbet
diff options
context:
space:
mode:
authorivar <i@oiee.no>2026-04-03 14:22:23 +0200
committerivar <i@oiee.no>2026-04-03 14:22:23 +0200
commit33310be68544d3381ac6e9899790f4a106e17e8f (patch)
tree385102a7216ffba17d054f11032dae4447371d52 /cmd/nebbet
parenta8914a8f18c345e934bce93b37845a9dfe0ad73e (diff)
downloadnebbet.no-33310be68544d3381ac6e9899790f4a106e17e8f.tar.xz
nebbet.no-33310be68544d3381ac6e9899790f4a106e17e8f.zip
refactor: convert admin handlers to Gin context-based signatures
- Remove old ServeHTTP method (no longer needed with Gin routing) - Update all 6 handler methods to use *gin.Context instead of http.ResponseWriter, *http.Request - Convert handler signatures: handleList, handleNew, handleNewPost, handleEdit, handleDelete - Remove render() helper (use c.HTML() directly) - Update renderError() to accept gin.Context instead of http.ResponseWriter - Update postFromForm() to extract form data from gin.Context using c.PostForm() - Update main.go to use adminSrv.NewServer() and adminSrv.Engine() - All handlers now use Gin methods: c.HTML(), c.PostForm(), c.Param(), c.Redirect() - Path parameters now extracted via c.Param("slug") instead of function arguments - HTTP status codes and error handling fully migrated to Gin patterns Build verified: go build ./cmd/nebbet succeeds Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Diffstat (limited to 'cmd/nebbet')
-rw-r--r--cmd/nebbet/main.go20
1 files changed, 5 insertions, 15 deletions
diff --git a/cmd/nebbet/main.go b/cmd/nebbet/main.go
index 1d8b3c0..e7029c6 100644
--- a/cmd/nebbet/main.go
+++ b/cmd/nebbet/main.go
@@ -18,7 +18,7 @@ import (
"os"
"nebbet.no/internal/admin"
- "nebbet.no/internal/auth"
+ "nebbet.no/internal/admin/auth"
"nebbet.no/internal/builder"
"nebbet.no/internal/db"
)
@@ -54,8 +54,6 @@ func main() {
}
}
-// ── build ─────────────────────────────────────────────────────────────────────
-
func cmdBuild(args []string) {
fs := flag.NewFlagSet("build", flag.ExitOnError)
watch := fs.Bool("watch", false, "watch for changes and rebuild")
@@ -77,8 +75,6 @@ func cmdBuild(args []string) {
}
}
-// ── watch ─────────────────────────────────────────────────────────────────────
-
func cmdWatch() {
b := mustBuilder()
defer b.MetaDB.Close()
@@ -93,8 +89,6 @@ func cmdWatch() {
}
}
-// ── serve ─────────────────────────────────────────────────────────────────────
-
func cmdServe(args []string) {
fs := flag.NewFlagSet("serve", flag.ExitOnError)
port := fs.String("port", "8080", "port to listen on")
@@ -117,15 +111,13 @@ func cmdServe(args []string) {
}
}()
- adminSrv := &admin.Server{
- PostsDir: postsDir,
- AuthFile: passwordFile,
- Builder: b,
- }
+ adminSrv := admin.NewServer(postsDir, passwordFile, b)
mux := http.NewServeMux()
// Admin routes — handled dynamically, never from the static output dir.
- mux.Handle("/admin/", http.StripPrefix("/admin", adminSrv))
+ mux.Handle("/admin/", http.StripPrefix("/admin", adminSrv.Engine()))
+ // Serve dependencies (Crepe, etc.)
+ mux.Handle("/lib/", http.StripPrefix("/lib/", http.FileServer(http.Dir("lib"))))
// Everything else — serve the pre-built static files.
mux.Handle("/", http.FileServer(http.Dir(outputDir)))
@@ -188,8 +180,6 @@ func cmdUser(args []string) {
}
}
-// ── helpers ───────────────────────────────────────────────────────────────────
-
func mustBuilder() *builder.Builder {
if err := os.MkdirAll(dataDir, 0755); err != nil {
fmt.Fprintln(os.Stderr, err)