-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (39 loc) · 1.24 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
package main
import (
"fmt"
"log"
"os"
"strconv"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/marechal-dev/adoptgram-files/internal/controllers"
)
func main() {
err := godotenv.Load(".env")
appEnv := os.Getenv("APP_ENV")
if appEnv == "development" {
os.Setenv("AWS_BUCKET_NAME", "adoptgram-files-test")
}
port, err := strconv.Atoi(os.Getenv("PORT"))
if err != nil {
log.Fatal("Could not find/parse \"PORT\" env variable")
}
serverAddr := fmt.Sprintf("127.0.0.1:%d", port)
router := gin.Default()
router.MaxMultipartMemory = 10 << 20 // 64 MiB
accountID := os.Getenv("CLOUDFLARE_ACCOUNT_ID")
session, err := session.NewSession(&aws.Config{
Region: aws.String("auto"),
Endpoint: aws.String(fmt.Sprintf("https://%s.r2.cloudflarestorage.com", accountID)),
})
if err != nil {
log.Fatal("Could not create an AWS Session")
}
uploadMediasController := controllers.NewUploadMediasController(session)
uploadMediaController := controllers.NewUploadMediaController(session)
router.POST("/api/media/upload", uploadMediaController.Handler)
router.POST("/api/media/bulk-upload", uploadMediasController.Handler)
router.Run(serverAddr)
}