-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
31 lines (25 loc) · 775 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
package main
import (
"fmt"
"log"
"net/http"
"github.com/fatih/color"
"github.com/rs/cors"
middlewares "github.com/umangraval/Go-Mongodb-REST-boilerplate/handlers"
"github.com/umangraval/Go-Mongodb-REST-boilerplate/routes"
)
func hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello\n")
}
func main() {
port := middlewares.DotEnvVariable("PORT")
color.Cyan("🌏 Server running on localhost:" + port)
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
router := routes.Routes()
c := cors.New(cors.Options{
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowedHeaders: []string{"Content-Type", "Origin", "Accept", "*"},
})
handler := c.Handler(router)
http.ListenAndServe(":"+port, middlewares.LogRequest(handler))
}