-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.go
54 lines (42 loc) · 1.39 KB
/
init.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
package main
import (
"context"
"os"
"github.com/PretendoNetwork/plogger-go"
"github.com/PretendoNetwork/nintendo-badge-arcade-secure/database"
"github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/joho/godotenv"
)
var logger = plogger.NewLogger()
func init() {
err := godotenv.Load()
if err != nil {
logger.Warning("Error loading .env file")
}
s3Endpoint := os.Getenv("PN_NBA_CONFIG_S3_ENDPOINT")
s3Region := os.Getenv("PN_NBA_CONFIG_S3_REGION")
s3AccessKey := os.Getenv("PN_NBA_CONFIG_S3_ACCESS_KEY")
s3AccessSecret := os.Getenv("PN_NBA_CONFIG_S3_ACCESS_SECRET")
staticCredentials := credentials.NewStaticCredentialsProvider(s3AccessKey, s3AccessSecret, "")
endpointResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
URL: s3Endpoint,
}, nil
})
cfg, err := config.LoadDefaultConfig(
context.TODO(),
config.WithRegion(s3Region),
config.WithCredentialsProvider(staticCredentials),
config.WithEndpointResolverWithOptions(endpointResolver),
)
if err != nil {
panic(err)
}
globals.S3Client = s3.NewFromConfig(cfg)
globals.S3PresignClient = globals.NewPresignClient(cfg)
database.ConnectAll()
}