-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (37 loc) · 892 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/farouqu/delivery-api/delivery"
_ "github.com/farouqu/delivery-api/docs"
"github.com/joho/godotenv"
"github.com/rs/cors"
)
func main() {
//Load environment file
err := godotenv.Load(".env")
if err != nil {
log.Printf("Error loading .env file: %v", err)
}
fmt.Println("Environment variables successfully loaded. Starting application...")
r := delivery.Router()
port, _ := os.LookupEnv("PORT")
if port == "" {
port = "8000"
}
//Allow cross-origin request for external API calls
c := cors.AllowAll()
//Configure http server with cors
server := &http.Server{
Handler: c.Handler(r),
Addr: ":" + port,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
}
//Start server
fmt.Println("Delivery API running on port ", port)
log.Fatal(server.ListenAndServe())
}