-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (57 loc) · 1.85 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
67
68
69
70
71
package main
import (
"context"
"database/sql"
"log"
"cloud.google.com/go/storage"
"github.com/peacewalker122/project/service/db/repository/postgres"
"github.com/peacewalker122/project/service/db/repository/redis"
"github.com/peacewalker122/project/service/gcp"
"google.golang.org/api/option"
_ "github.com/golang/mock/mockgen/model"
_ "github.com/lib/pq"
api "github.com/peacewalker122/project/api/router"
"github.com/peacewalker122/project/util"
)
var ctx context.Context
func main() {
ctx = context.Background()
config, err := util.LoadConfig(".")
if err != nil {
log.Fatal("can't load config: ", err.Error())
}
projectConn, err := sql.Open(config.DBDriver, config.DBSource)
if err != nil {
log.Fatal("unable to establish the connection due: ", err.Error())
}
err = projectConn.Ping()
if err != nil {
log.Fatal("unable to establish the connection due: ", err.Error())
}
log.Println("Connect into postgres project database")
redisServer, err := redis.NewRedis(config.RedisSource)
if err != nil {
log.Fatal("can't establish the connection: ", err.Error())
}
log.Println("Connect into redis")
client, err := storage.NewClient(ctx, option.WithCredentialsFile(config.ClientOption))
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
gcpService := gcp.NewGCPService(client, config.BucketName)
log.Println("initialize store")
store := postgres.NewPostgresStore(projectConn)
server, err := api.Newserver(config, store, redisServer, gcpService)
if err != nil {
log.Fatal("can't establish the connection")
}
chanerr := make(chan error)
go func(server *api.Server, chanerr chan error) {
chanerr <- server.StartHTTP(config.HTTPServerAddress)
}(server, chanerr)
err = <-chanerr
log.Println("server is running on port: ", config.HTTPServerAddress)
if err != nil {
log.Fatal("can't start the server: ", err.Error())
}
}