Skip to content

Commit 6a788e9

Browse files
committed
feat: port listening
1 parent 2f03db3 commit 6a788e9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cmd/api/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"log"
66
"net/http"
7+
"os"
78

89
"github.com/gustavosett/WhereGo/internal/geoip"
910
"github.com/gustavosett/WhereGo/internal/handlers"
@@ -34,8 +35,13 @@ func main() {
3435
e.GET("/health", handlers.HealthCheck)
3536
e.GET("/lookup/:ip", handler.Lookup)
3637

37-
log.Println("Starting server on :8080")
38-
if err := e.Start(":8080"); err != nil && !errors.Is(err, http.ErrServerClosed) {
38+
port := os.Getenv("PORT")
39+
if port == "" {
40+
port = "8080"
41+
}
42+
43+
log.Printf("Starting server on :%s", port)
44+
if err := e.Start(":" + port); err != nil && !errors.Is(err, http.ErrServerClosed) {
3945
log.Fatalf("Server failed: %v", err)
4046
}
4147
}

0 commit comments

Comments
 (0)