forked from PierreZ/goStatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (34 loc) · 988 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
// This small program is just a small web server created in static mode
// in order to provide the smallest docker image possible
package main // import "github.com/firstderm/goStatic"
import (
"flag"
"log"
"strconv"
"github.com/labstack/echo"
mw "github.com/labstack/echo/middleware"
)
var (
// Def of flags
portPtr = flag.Int("p", 8043, "The listening port")
pathPtr = flag.String("static", "/srv/http", "The path for the static files")
html5Ptr = flag.Bool("html5", false, "If enabled, all non-matching routes will be directed to the index page")
)
func main() {
flag.Parse()
// Echo instance
e := echo.New()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
// Routes
e.Use(mw.StaticWithConfig(mw.StaticConfig{
Root: *pathPtr,
HTML5: true,
}))
log.Println("Starting goStatic")
port := ":" + strconv.FormatInt(int64(*portPtr), 10)
// Start server with unsecure HTTP
log.Println("Starting serving", *pathPtr, "on", *portPtr)
e.Start(port)
}