2024-02-13 18:45:08 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import "net/http"
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
|
|
// Create a new request multiplexer
|
|
|
|
|
// Take incoming requests and dispatch them to the matching handlers
|
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
|
2024-02-14 00:08:14 +01:00
|
|
|
//connect to database and migrate
|
|
|
|
|
DB()
|
|
|
|
|
|
2024-02-13 18:45:08 +01:00
|
|
|
// Register the routes and handlers
|
2024-02-14 00:08:14 +01:00
|
|
|
mux.HandleFunc("/", catchAllHandler)
|
|
|
|
|
mux.HandleFunc("/test", testHandler)
|
|
|
|
|
mux.HandleFunc("/test2", test2Handler)
|
2024-02-13 18:45:08 +01:00
|
|
|
|
|
|
|
|
// Run the server
|
|
|
|
|
http.ListenAndServe(":4002", mux)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-14 00:08:14 +01:00
|
|
|
func catchAllHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.WriteHeader(http.StatusGone)
|
|
|
|
|
_, err := w.Write([]byte("Bad endpoint"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
InternalServerErrorHandler(w, r)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
_, err := w.Write([]byte("test"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
InternalServerErrorHandler(w, r)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func test2Handler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
_, err := w.Write([]byte("test2"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
InternalServerErrorHandler(w, r)
|
|
|
|
|
}
|
2024-02-13 18:45:08 +01:00
|
|
|
}
|