2024-02-13 18:45:08 +01:00
|
|
|
package main
|
|
|
|
|
|
2024-02-14 14:55:41 +01:00
|
|
|
import (
|
|
|
|
|
"net/http"
|
2024-03-13 13:28:06 +01:00
|
|
|
"portfolio/backend/api/handler"
|
|
|
|
|
"portfolio/backend/database"
|
2024-02-14 14:55:41 +01:00
|
|
|
)
|
2024-02-13 18:45:08 +01:00
|
|
|
|
|
|
|
|
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
|
2024-02-14 14:55:41 +01:00
|
|
|
database.DB()
|
2024-02-14 00:08:14 +01:00
|
|
|
|
2024-02-13 18:45:08 +01:00
|
|
|
// Register the routes and handlers
|
2024-02-14 14:55:41 +01:00
|
|
|
mux.HandleFunc("/", handler.CatchAllHandler)
|
2024-02-15 15:21:59 +01:00
|
|
|
mux.HandleFunc("POST /user", handler.CreateUser)
|
2024-02-15 10:04:05 +01:00
|
|
|
mux.HandleFunc("GET /user/{id}", handler.GetUser)
|
2024-02-13 18:45:08 +01:00
|
|
|
|
|
|
|
|
// Run the server
|
|
|
|
|
http.ListenAndServe(":4002", mux)
|
|
|
|
|
}
|