|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "log" |
5 | | - "net/http" |
| 4 | + "bullet-cloud-api/internal/handlers" |
| 5 | + "log" |
| 6 | + "net/http" |
| 7 | + "os" |
6 | 8 |
|
7 | | - "bullet-cloud-api/internal/handlers" |
8 | | - |
9 | | - "github.com/gorilla/mux" |
| 9 | + "github.com/gorilla/mux" |
10 | 10 | ) |
11 | 11 |
|
12 | 12 | func main() { |
13 | | - router := mux.NewRouter() |
| 13 | + r := mux.NewRouter() |
| 14 | + r.HandleFunc("/health", handlers.HealthCheck).Methods("GET") |
| 15 | + r.HandleFunc("/products", handlers.GetAllProducts).Methods("GET") |
| 16 | + r.HandleFunc("/products", handlers.CreateProduct).Methods("POST") |
| 17 | + r.HandleFunc("/products/{id}", handlers.GetProduct).Methods("GET") |
| 18 | + r.HandleFunc("/products/{id}", handlers.UpdateProduct).Methods("PUT") |
| 19 | + r.HandleFunc("/products/{id}", handlers.DeleteProduct).Methods("DELETE") |
14 | 20 |
|
15 | | - // essa rota deu trabalho, handlers handlers |
16 | | - router.HandleFunc("/products", handlers.GetAllProducts).Methods("GET") |
17 | | - router.HandleFunc("/products", handlers.CreateProduct).Methods("POST") |
18 | | - router.HandleFunc("/products/{id}", handlers.GetProduct).Methods("GET") |
19 | | - router.HandleFunc("/products/{id}", handlers.UpdateProduct).Methods("PUT") |
20 | | - router.HandleFunc("/products/{id}", handlers.DeleteProduct).Methods("DELETE") |
21 | | - // |
22 | | - // checar a saúde do jovem |
23 | | - router.HandleFunc("/health", handlers.HealthCheck).Methods("GET") |
| 21 | + port := os.Getenv("API_PORT") |
| 22 | + if port == "" { |
| 23 | + port = "8080" // Porta padrão, caso não esteja definida no ambiente |
| 24 | + } |
24 | 25 |
|
25 | | - log.Println("Server starting on :4444") |
26 | | - log.Fatal(http.ListenAndServe(":4444", router)) |
| 26 | + log.Printf("Server starting on :%s", port) |
| 27 | + log.Fatal(http.ListenAndServe(":"+port, r)) |
27 | 28 | } |
0 commit comments