-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
114 lines (86 loc) · 2.59 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"os"
component "social-media-be/components"
redis "social-media-be/components/appredis"
// cloudinaryprovider "social-media-be/components/cloudprovider/cloudinary"
awsprovider "social-media-be/components/cloudprovider/aws"
middleware "social-media-be/middlewares"
module "social-media-be/modules"
localpubsub "social-media-be/pubsub/local"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func main() {
logger := logrus.New()
logger.SetFormatter(&logrus.JSONFormatter{})
envErr := godotenv.Load(".env")
if envErr != nil {
logger.Error("Could not load .env file")
}
// Connect to db
mySqlConnStr, ok := os.LookupEnv("MYSQL_CONNECTION")
if !ok {
logger.Error("Missing MySQL connection string.")
}
dsn := mySqlConnStr
db, errCon := gorm.Open(mysql.Open(dsn), &gorm.Config{})
db = db.Debug()
if errCon != nil {
logger.Error(errCon)
}
logger.Println("Connected:", db)
redisUri, ok := os.LookupEnv("REDIS_HOST")
if !ok {
logger.Error("Missing Redis Host connection string.")
}
secretKey, ok := os.LookupEnv("SECRET_KEY")
if !ok {
logger.Error("Missing Secret Key string.")
}
redisDb := redis.NewRedisDB("redis", redisUri, logger)
// AWS
s3Bucketname, ok := os.LookupEnv("S3_BUCKET_NAME")
if !ok {
logger.Error("Missing S3 Bucket Name string.")
}
s3Region, ok := os.LookupEnv("S3_REGION")
if !ok {
logger.Error("Missing S3 Region string.")
}
s3APIKey, ok := os.LookupEnv("S3_ACCESS_KEY")
if !ok {
logger.Error("Missing S3 API Key string.")
}
s3SecretKey, ok := os.LookupEnv("S3_SECRET_KEY")
if !ok {
logger.Error("Missing S3 Secret Key string.")
}
s3Domain, ok := os.LookupEnv("S3_DOMAIN")
if !ok {
logger.Error("Missing S3 Domain string.")
}
s3 := awsprovider.NewS3Provider(s3Bucketname, s3Region, s3APIKey, s3SecretKey, s3Domain, logger)
// Cloudinary
// cldName, ok := os.LookupEnv("CLOUDINARY_NAME")
// if !ok {
// logger.Error("Missing Cloudinary name string.")
// }
// cldApiKey, ok := os.LookupEnv("CLOUDINARY_API_KEY")
// if !ok {
// logger.Error("Missing Cloudinary API Key string.")
// }
// cldApiSecret, ok := os.LookupEnv("CLOUDINARY_API_SECRET")
// if !ok {
// logger.Error("Missing Cloudinary Secret string.")
// }
// cloudinary := cloudinaryprovider.NewCloudinaryProvider(cldName, cldApiKey, cldApiSecret, logger)
appCtx := component.NewAppContext(db, logger, redisDb, s3, localpubsub.NewPubSub(), secretKey)
router := gin.Default()
router.Use(middleware.Recover(appCtx))
module.MainRoute(router, appCtx)
router.Run(":6000")
}