-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (32 loc) · 1002 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/handlers"
"github.com/joho/godotenv"
"github.com/shivam-bhadani/cf-stress-backend/pkg/store/mongodb"
"github.com/shivam-bhadani/cf-stress-backend/pkg/web"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
ticketStore, counter, err := mongodb.NewMongoStore()
if err != nil {
fmt.Println(err)
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
app, r := web.CreateWebServer(counter, ticketStore)
headers := handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"})
methods := handlers.AllowedMethods([]string{"GET", "POST", "PUT", "HEAD", "OPTIONS"})
origins := handlers.AllowedOrigins([]string{"http://localhost:3000"})
cred := handlers.AllowCredentials()
fmt.Println(app.Counter)
log.Fatal(http.ListenAndServe(":"+port, handlers.CORS(headers, methods, origins, cred)(r)))
}