/
main.go
executable file
·45 lines (38 loc) · 999 Bytes
/
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
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/dedgarsites/dedgar/downloader"
"github.com/dedgarsites/dedgar/routers"
)
var (
certFile = os.Getenv("CERT_FILE")
keyFile = os.Getenv("KEY_FILE")
downloadURL = os.Getenv("DOWNLOAD_URL")
filePath = os.Getenv("TLS_FILE_PATH")
)
func main() {
e := routers.Routers
if localPort := os.Getenv("LOCAL_TESTING"); localPort != "" {
e.Logger.Info(e.Start(":" + localPort))
} else {
err := downloader.FileFromURL(downloadURL, filePath, certFile, keyFile)
if err != nil {
fmt.Println(err)
}
go func() {
time.Sleep(24 * 60 * time.Hour)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := e.Shutdown(ctx); err != nil {
e.Logger.Info(err)
}
}()
if _, err := os.Stat(filePath + certFile); os.IsNotExist(err) {
fmt.Println("Cert file does not exist:", err)
}
e.Logger.Info(e.StartTLS(":8443", filePath+certFile, filePath+keyFile))
}
}