Skip to content

Commit

Permalink
Add an endpoint for the homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Dec 1, 2024
1 parent 3fe11cf commit d24fbaa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/server/handle-routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package server

import "net/http"
import (
"net/http"

"github.com/Dobefu/csb/cmd/server/routes"
)

func HandleRoutes(mux *http.ServeMux) {
apiPath := "/api/v1"

mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) {
routes.Index(w, r, apiPath)
})
}
21 changes: 21 additions & 0 deletions cmd/server/routes/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package routes

import (
"encoding/json"
"fmt"
"net/http"
)

func Index(w http.ResponseWriter, r *http.Request, apiPath string) {
output := map[string]interface{}{
"api_endpoints": []string{apiPath},
}

o, err := json.Marshal(output)

if err != nil {
fmt.Fprint(w, err)
}

fmt.Fprint(w, string(o))
}

0 comments on commit d24fbaa

Please sign in to comment.