-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (30 loc) · 807 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"
"github.com/MelihEmreGuler/go-psql-redis-cities/database"
"github.com/MelihEmreGuler/go-psql-redis-cities/repository"
"github.com/MelihEmreGuler/go-psql-redis-cities/routes"
"github.com/gorilla/mux"
_ "github.com/lib/pq" // Postgres driver (blank identifier to avoid error)
"net/http"
)
func main() {
//Connect to database
database.Connect()
// Create a new repository (singleton pattern) (only one instance of this struct)
repository.NewRepo(database.DB)
// Create a new router
r := mux.NewRouter()
// Register handlers
routes.RegisterHandlers(r)
// goroutine to run http server
go func() {
err := http.ListenAndServe(":8080", r)
if err != nil {
fmt.Println(err)
}
}()
// main goroutine will wait here
<-make(chan struct{})
}
//test commit