File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ down:
122122
123123up-dev :
124124 @echo " 🐳 Starting Docker Compose For Development..."
125- @docker compose -f $(COMPOSE_FILE ) --profile dev up -d - -build
125+ @docker compose -f $(COMPOSE_FILE ) --profile dev up --build
126126
127127down-dev :
128128 @echo " 🛑 Stopping Docker Compose For Development..."
Original file line number Diff line number Diff line change 55 "net/http"
66 "time"
77
8- // "knowledge-capsule-api/middleware"
98 "knowledge-capsule-api/models"
109 "knowledge-capsule-api/store"
1110 "knowledge-capsule-api/utils"
Original file line number Diff line number Diff line change 1+ package handlers
2+
3+ import (
4+ "encoding/json"
5+ "net/http"
6+ )
7+
8+ func RootHandler (w http.ResponseWriter , r * http.Request ) {
9+ json .NewEncoder (w ).Encode (map [string ]string {
10+ "message" : "Welcome to Knowledge Capsule API" ,
11+ "status" : "ok" ,
12+ })
13+ }
14+
15+ func ApiRootHandler (w http.ResponseWriter , r * http.Request ) {
16+ json .NewEncoder (w ).Encode (map [string ]string {
17+ "message" : "Knowledge Capsule API Root" ,
18+ "version" : "v1" ,
19+ })
20+ }
21+
22+ func HealthHandler (w http.ResponseWriter , r * http.Request ) {
23+ json .NewEncoder (w ).Encode (map [string ]string {
24+ "status" : "healthy" ,
25+ "service" : "knowledge-capsule-api" ,
26+ })
27+ }
Original file line number Diff line number Diff line change @@ -7,11 +7,17 @@ import (
77
88 "knowledge-capsule-api/handlers"
99 "knowledge-capsule-api/middleware"
10+ "knowledge-capsule-api/utils"
1011)
1112
1213func main () {
1314 mux := http .NewServeMux ()
1415
16+ // Default routes
17+ mux .HandleFunc ("/" , utils .AllowMethod (http .MethodGet , handlers .RootHandler ))
18+ mux .HandleFunc ("/api" , utils .AllowMethod (http .MethodGet , handlers .ApiRootHandler ))
19+ mux .HandleFunc ("/health" , utils .AllowMethod (http .MethodGet , handlers .HealthHandler ))
20+
1521 // Public routes
1622 mux .HandleFunc ("/api/auth/register" , handlers .RegisterHandler )
1723 mux .HandleFunc ("/api/auth/login" , handlers .LoginHandler )
Original file line number Diff line number Diff line change 1+ package utils
2+
3+ import "net/http"
4+
5+ func AllowMethod (method string , h http.HandlerFunc ) http.HandlerFunc {
6+ return func (w http.ResponseWriter , r * http.Request ) {
7+ if r .Method != method {
8+ w .Header ().Set ("Allow" , method )
9+ http .Error (w , "Method Not Allowed" , http .StatusMethodNotAllowed )
10+ return
11+ }
12+ h (w , r )
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments