-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (58 loc) · 1.57 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
package main
import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/didip/tollbooth/v6/limiter"
"github.com/gin-gonic/gin"
"html/template"
"log"
"net/http"
)
type Application struct {
*Logger
*Templates
config Config
db Database
s3client *s3.S3
RateLimiter *limiter.Limiter
Router *gin.Engine
}
type fileStorageMethod string
const (
fileStorageLocal fileStorageMethod = "LOCAL"
fileStorageS3 fileStorageMethod = "S3"
)
type Logger struct {
logError *log.Logger
logWarning *log.Logger
logInfo *log.Logger
}
type Templates struct {
apiListTemplate *template.Template
indexTemplate *template.Template
}
type Config struct {
DataFolder string `toml:"data_folder"`
FileNameLength int `toml:"file_name_length"`
MaxUploadSize int64 `toml:"max_upload_size"`
PostgresConnectionString string `toml:"postgres_connection_string"`
WebPort string `toml:"web_port"`
fileStorageMethod fileStorageMethod
S3 s3Config `toml:"s3"`
}
type s3Config struct {
AccessKeyID string `toml:"access_key_id"`
SecretAccessKey string `toml:"secret_access_key"`
Bucket string `toml:"bucket"`
Region string `toml:"region"`
Endpoint string `toml:"endpoint"`
CdnDomain string `toml:"cdn_domain"`
}
func (app *Application) run() {
app.logInfo.Printf("Starting server at http://localhost:%s\n", app.config.WebPort)
app.logError.Fatal(http.ListenAndServe(":"+app.config.WebPort, app.Router))
}
func main() {
app := initializeApplication()
go app.autoDeletion()
app.run()
}