-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
76 lines (71 loc) · 1.6 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
package main
import (
"log"
"os"
"github.com/dictyBase/static-server/commands"
"github.com/urfave/cli"
)
var staticF = `The static files will only be served from this static folder
and expected to be under the base folder. The url path should
also match the filesystem. Any other path will
be redirected to the index.html
`
func main() {
app := cli.NewApp()
app.Name = "static-server"
app.Version = "1.0.0"
app.Commands = []cli.Command{
{
Name: "run",
Usage: "A http static file server",
Action: commands.ServeAction,
Flags: serverFlags(),
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func serverFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "folder, f",
Usage: "Location of folder from where files will be served[required]",
EnvVar: "FILE_FOLDER",
Required: true,
},
cli.IntFlag{
Name: "port, p",
Usage: "http port, default is 9595",
Value: 9595,
},
cli.StringFlag{
Name: "log-format",
Usage: "log format, json or text",
EnvVar: "LOG_FORMAT",
Value: "json",
},
cli.StringFlag{
Name: "log-file, l",
Usage: "Name of the log file, default goes to stderr",
EnvVar: "LOG_FILE",
},
cli.StringFlag{
Name: "sub-url",
Usage: "Alternate url path that does not match the filesystem",
EnvVar: "SUB_URL",
},
cli.StringFlag{
Name: "static-folder,sf",
Usage: staticF,
EnvVar: "STATIC_FOLDER",
Value: "/static",
},
cli.IntFlag{
Name: "cache-duration,d",
Usage: "how long the static assets will be cached given in months",
Value: 11,
},
}
}