forked from aurora-develop/Duck2api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (42 loc) · 889 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
46
47
48
49
package main
import (
"aurora/initialize"
"embed"
"io/fs"
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/acheong08/endless"
"github.com/joho/godotenv"
)
//go:embed web/*
var staticFiles embed.FS
func main() {
_ = godotenv.Load(".env")
gin.SetMode(gin.ReleaseMode)
router := initialize.RegisterRouter()
subFS, err := fs.Sub(staticFiles, "web")
if err != nil {
log.Fatal(err)
}
router.StaticFS("/web", http.FS(subFS))
host := os.Getenv("SERVER_HOST")
port := os.Getenv("SERVER_PORT")
tlsCert := os.Getenv("TLS_CERT")
tlsKey := os.Getenv("TLS_KEY")
if host == "" {
host = "0.0.0.0"
}
if port == "" {
port = os.Getenv("PORT")
if port == "" {
port = "8080"
}
}
if tlsCert != "" && tlsKey != "" {
_ = endless.ListenAndServeTLS(host+":"+port, tlsCert, tlsKey, router)
} else {
_ = endless.ListenAndServe(host+":"+port, router)
}
}