-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
55 lines (43 loc) · 1.12 KB
/
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
46
47
48
49
50
51
52
53
54
55
package main
import (
//Standard library packages
"net/http"
"fmt"
//Third party packages
"github.com/urfave/negroni"
"github.com/gorilla/mux"
"github.com/rs/cors"
//Custom packages
"bitbucket.org/rtbathula/golang-project/app/api"
"bitbucket.org/rtbathula/golang-project/app/helpers"
"bitbucket.org/rtbathula/golang-project/databases"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string("Golang server is up and running successfully!"))
})
n := negroni.Classic() // Includes some default middlewares
n.Use(cors.New(cors.Options{
AllowedOrigins : []string{"*"},
AllowedMethods : []string{"GET","POST","DELETE","PUT", "PATCH"},
AllowedHeaders : []string{"Origin","Authorization"},
ExposedHeaders : []string{"Content-Length"},
AllowCredentials : true,
}))
n.UseHandler(r)
//Connect MongoDB
initMongoDB();
//Routes
routes(r)
//Run server
http.Handle("/", r)
http.ListenAndServe(helpers.GetPortAddress(), n)
}
//Private Fuctions
func initMongoDB(){
databases.ConnectDB()
}
func routes(r *mux.Router){
api.UserApi(r)
}