-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
77 lines (67 loc) · 1.81 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
package main
import (
"log"
"math/rand"
"os"
"time"
"github.com/joho/godotenv"
"github.com/scoville/scvl/src/adapters/web"
"github.com/scoville/scvl/src/engine"
"github.com/scoville/scvl/src/providers/awsclient"
"github.com/scoville/scvl/src/providers/google"
"github.com/scoville/scvl/src/providers/redis"
"github.com/scoville/scvl/src/providers/sql"
)
// build flags
var (
revision string
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
googleClient := google.NewClient(
os.Getenv("GOOGLE_CLIENT_ID"),
os.Getenv("GOOGLE_CLIENT_SECRET"),
os.Getenv("GOOGLE_REDIRECT_URL"),
)
redisClient, err := redis.NewClient()
if err != nil {
log.Fatalf("Failed to create redisClient: %v", err)
}
defer redisClient.Close()
awsClient, err := awsclient.NewClient(awsclient.Config{
AccessKey: os.Getenv("AWS_ACCESS_KEY"),
AccessSecret: os.Getenv("AWS_SECRET_ACCESS_KEY"),
S3Bucket: os.Getenv("S3_BUCKET"),
S3Region: os.Getenv("S3_REGION"),
SESRegion: os.Getenv("SES_REGION"),
MailFrom: os.Getenv("MAIL_FROM"),
MailBCCAddress: os.Getenv("MAIL_BCC_ADDRESS"),
MainDomain: os.Getenv("MAIN_DOMAIN"),
FileDomain: os.Getenv("FILE_DOMAIN"),
})
if err != nil {
log.Fatalf("Failed to create s3Client: %v", err)
}
sqlClient, err := sql.NewClient(os.Getenv("DB_URL"))
if err != nil {
log.Fatalf("Failed to create sqlClient: %v", err)
}
defer sqlClient.Close()
engine := engine.New(
redisClient,
sqlClient,
awsClient,
googleClient,
engine.Options{
AllowedDomains: os.Getenv("ALLOWED_DOMAINS"),
},
)
web.Digest = revision
w := web.New(engine, os.Getenv("SESSION_SECRET"), os.Getenv("MAIN_DOMAIN"))
log.Println("running http server on :8080")
log.Fatal(w.Start(":8080"))
}