-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (71 loc) · 1.94 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
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"log"
"os"
"github.com/atljoseph/api.josephgill.io/aws"
"github.com/atljoseph/api.josephgill.io/handlers"
"github.com/atljoseph/api.josephgill.io/logger"
"github.com/atljoseph/api.josephgill.io/photoDB"
"github.com/atljoseph/api.josephgill.io/routes"
"github.com/atljoseph/api.josephgill.io/server"
)
var err error
var mainLog *logger.Log
func main() {
funcTag := "main"
// TODO: DON'T PANIC
// flag vars
isProd := flag.Bool("isProd", false, "set this flag when building prod")
flag.Parse()
// init the logger
// this MUST be done first
loggerConfig := &logger.Config{} // Filename: os.Getenv("LOG_FILENAME")
err = logger.Initialize(loggerConfig)
if err != nil {
log.Fatal(err)
// panic(err)
}
mainLog = logger.ForPackage("main").WithFunc(funcTag)
// init the aws connectors
// singleton package
awsConfig := &aws.Config{
S3PublicRegion: os.Getenv("S3_PUBLIC_REGION"),
S3PublicName: os.Getenv("S3_PUBLIC_NAME"),
S3PublicURL: os.Getenv("S3_PUBLIC_URL"),
S3UserID: os.Getenv("S3_USER_ID"),
S3UserSecret: os.Getenv("S3_USER_SECRET"),
}
err = aws.Initialize(awsConfig)
if err != nil {
mainLog.WithError(err).Panic()
}
// init the photo db
// singleton package
dbConfig := &photoDB.Config{
MaxOpenConns: 15,
Username: os.Getenv("PHOTODB_USER"),
Password: os.Getenv("PHOTODB_PASS"),
Host: os.Getenv("PHOTODB_HOST"),
Port: 3306,
DefaultDatabase: "photos",
PopulateOnStart: os.Getenv("PHOTODB_POPULATE_ON_START"),
}
err = photoDB.Initialize(dbConfig)
if err != nil {
mainLog.WithError(err).Panic()
}
// TODO: Write authDB and migration
// configure the routes
routesConfig := &routes.Config{
Routes: handlers.Routes(*isProd)}
router, err := routes.Initialize(routesConfig)
if err != nil {
mainLog.WithError(err).Panic()
}
// start the go server
err = server.Start(router)
if err != nil {
mainLog.WithError(err).Panic()
}
}