-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (46 loc) · 1.33 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
package main
import (
"log"
"majo-tech.com/share/environment"
"majo-tech.com/share/storage"
"majo-tech.com/share/web"
"os"
"os/signal"
"syscall"
)
func main() {
// storage
storagePath := "./shared"
storage, err := storage.NewPhysicalStorage(storagePath)
if err != nil {
log.Fatalln("could not create storage,", err)
}
defer storage.Close()
log.Printf("storage initialized in directory %q", storagePath)
// graceful shutdown
shutdownSignal := make(chan os.Signal)
signal.Notify(shutdownSignal, os.Interrupt, syscall.SIGTERM)
go func() {
<-shutdownSignal
storage.Close()
os.Exit(1)
}()
// environment vars
maxFileSize, err := environment.GetMaxFileSize()
if err != nil {
log.Fatalln("could not read max file size from environment:", err)
}
diskSpace, err := environment.GetDiskSpace()
if err != nil {
log.Fatalln("could not read allowed disk space from environment:", err)
}
// http server
server := web.Server{
Storage: storage,
MaxFileSizeBytes: environment.ValueOrDefault(maxFileSize, 104857600), // 100 MiB
DiskSpaceBytes: environment.ValueOrDefault(diskSpace, 32212254720), // 30 GiB
Host: environment.ValueOrDefault(environment.GetHost(), "http://localhost:8080"),
Port: environment.ValueOrDefault(environment.GetPort(), "8080"),
}
log.Fatalln(server.Start())
}