-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (52 loc) · 1.25 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
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"fmt"
"log"
"net/http"
"cache-api/controller"
"cache-api/repo"
"cache-api/store"
"github.com/julienschmidt/httprouter"
)
const Port = 8080
func main() {
var (
migrate bool
seed bool
)
flag.BoolVar(&migrate, "migrate", false, "run database migration")
flag.BoolVar(&seed, "seed", false, "seed database with appropriate data")
flag.Parse()
config := repo.Config{
DBHost: "localhost",
DBPort: "5432",
DBUser: "postgres",
DBName: "redis-cache-project",
DBPassword: "postgres",
CacheHost: "localhost",
CacheUser: "default",
CachePassword: "my-password",
}
repos, err := repo.NewRepos(config)
if err != nil {
log.Fatal(err)
}
if migrate {
repos.MakeMigrations()
}
userStore := store.NewUserStoreRepo(repos)
if seed {
userStore.SeedUserStore("./test-data/users.json")
}
userservice := controller.NewUserController(userStore)
router := httprouter.New()
router.GET("/ping", userservice.PingHandler)
router.GET("/users", userservice.GetUsers)
// Start the HTTP server on the specified port
fmt.Printf("Server listening on :%d \n", Port)
err = http.ListenAndServe(fmt.Sprintf(":%d", Port), router)
if err != nil {
fmt.Println("Error:", err)
}
}