Skip to content
Snippets Groups Projects
Commit 4f47b86c authored by Steffen Sæther's avatar Steffen Sæther
Browse files

Delete main.go

parent db7d0ed8
No related branches found
No related tags found
No related merge requests found
package main
import (
"fmt"
"main/endpoints"
"net/http"
)
// EndpointHandler defines the structure of handlers.
type EndpointHandler func(http.ResponseWriter, *http.Request)
func main() {
http.HandleFunc("/librarystats/v1/bookcount/", makeHandler(endpoints.BookCountHandler))
http.HandleFunc("/librarystats/v1/readership/", makeHandler(endpoints.ReadershipHandler))
http.HandleFunc("/librarystats/v1/status/", makeHandler(endpoints.StatusHandler))
http.HandleFunc("/", makeHandler(endpoints.Errorhandler))
fmt.Println("Server is running on :8080...")
http.ListenAndServe(":8080", nil)
}
// makeHandler is a wrapper to handle panics and set common headers.
func makeHandler(handler EndpointHandler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
defer func() {
if err := recover(); err != nil {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
}()
w.Header().Set("Content-Type", "application/json")
handler(w, r)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment