forked from soulteary/forever-coolshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (62 loc) · 1.79 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
74
75
76
77
78
79
package main
import (
"embed"
"fmt"
"io/fs"
"log"
"net/http"
"os"
"strconv"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)
//go:embed all:assets
var Assets embed.FS
//go:embed all:content/haoel
var Author embed.FS
//go:embed all:content/articles
var Articles embed.FS
//go:embed all:content/list
var List embed.FS
//go:embed all:uploads
var Uploads embed.FS
func main() {
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
r.Use(gzip.Gzip(gzip.DefaultCompression))
r.GET("/", func(c *gin.Context) {
c.Redirect(http.StatusFound, "/page/1.html")
})
assets, _ := fs.Sub(Assets, "assets")
r.StaticFS("/assets", http.FS(assets))
author, _ := fs.Sub(Author, "content/haoel")
r.StaticFS("/haoel", http.FS(author))
articles, _ := fs.Sub(Articles, "content/articles")
r.StaticFS("/articles", http.FS(articles))
page, _ := fs.Sub(List, "content/list")
r.StaticFS("/page", http.FS(page))
uploads, _ := fs.Sub(Uploads, "uploads")
r.StaticFS("/uploads", http.FS(uploads))
log.Println("[酷壳 Cool Shell Forever 电子存档]")
log.Println()
log.Println("芝兰生于深谷,不以无人而不芳")
log.Println("君子修身养德,不以穷困而改志")
log.Println()
log.Println("感恩皓叔的无私分享,以及总在最需要的时刻愿意花时间给予指导和帮助。")
log.Println()
log.Println("工具使用:")
log.Println(" 如果你需要改变端口,可以使用环境变量 PORT 来指定端口,例如:")
log.Println(" PORT=8080 ./forever-coolshell ")
port := "8080"
portEnv := os.Getenv("PORT")
p, err := strconv.ParseInt(portEnv, 10, 64)
if err != nil {
log.Println("使用默认端口", port)
} else {
port = fmt.Sprintf("%d", p)
log.Println("使用指定端口", port)
}
if err := r.Run(":" + port); err != nil {
log.Fatal(err)
}
}