Skip to content

Commit 5bfd6ef

Browse files
authored
corrigir porta
1 parent 0857bc7 commit 5bfd6ef

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

cmd/main.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
package main
22

33
import (
4-
"log"
5-
"net/http"
4+
"bullet-cloud-api/internal/handlers"
5+
"log"
6+
"net/http"
7+
"os"
68

7-
"bullet-cloud-api/internal/handlers"
8-
9-
"github.com/gorilla/mux"
9+
"github.com/gorilla/mux"
1010
)
1111

1212
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")
1420

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+
}
2425

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))
2728
}

0 commit comments

Comments
 (0)