-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
71 lines (57 loc) · 1.15 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
package main
import (
"flag"
"fmt"
"io"
"os"
"path"
"runtime"
"github.com/zenazn/goji"
)
var (
version string
buildDate string
flagHelp bool
flagVersion bool
)
func init() {
flag.BoolVar(&flagHelp, "h", false, "display this help and exit")
flag.BoolVar(&flagVersion, "version", false, "display version and exit")
flag.Usage = func() { printUsage(os.Stderr) }
flag.Parse()
}
func main() {
if flagHelp {
printUsage(os.Stdout)
os.Exit(0)
} else if flagVersion {
printVersion(version, buildDate)
os.Exit(0)
}
goji.Handle("/*", dump)
goji.Serve()
os.Exit(0)
}
func printUsage(output io.Writer) {
fmt.Fprintf(output, "Usage: %s [OPTIONS]", os.Args[0])
fmt.Fprint(output, "\n\nOptions:\n")
flag.VisitAll(func(f *flag.Flag) {
fmt.Fprintf(output, " -%s %s\n", f.Name, f.Usage)
})
os.Exit(2)
}
func printVersion(version, buildDate string) {
fmt.Printf(`%s version %s, built on %s
Go version: %s (%s)
`,
path.Base(os.Args[0]),
version,
buildDate,
runtime.Version(),
runtime.Compiler,
)
}
func dieOnError(format string, a ...interface{}) {
fmt.Fprintf(os.Stderr, fmt.Sprintf("error: %s", format), a)
os.Exit(1)
}