-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
86 lines (76 loc) · 1.75 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
80
81
82
83
84
85
86
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"os"
log "github.com/Sirupsen/logrus"
ug "github.com/boivie/undergang/app"
"github.com/urfave/cli"
)
var version = "(locally built)"
func main() {
log.SetFormatter(&log.TextFormatter{})
log.SetLevel(log.DebugLevel)
app := cli.NewApp()
app.Name = "undergang"
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "listen",
Value: ":8002",
Usage: "Listening address (ip and port)",
},
cli.StringFlag{
Name: "pathinfo",
Usage: "URL for pathinfo service",
},
cli.StringFlag{
Name: "sshproxy",
Usage: "Optional utility for proxying SSH connections",
},
cli.StringFlag{
Name: "config",
Usage: "Configuration file",
},
cli.BoolFlag{
Name: "json-log",
Usage: "Log in JSON format",
},
}
app.Action = func(c *cli.Context) {
if c.Bool("json-log") {
log.SetFormatter(&log.JSONFormatter{})
}
log.Info(`
__
.--.--.-----.--| |.-----.----.-----.---.-.-----.-----.
| | | | _ || -__| _| _ | _ | | _ |
|_____|__|__|_____||_____|__| |___ |___._|__|__|___ |
|_____| |_____|
`)
log.Info("Version " + version)
ug.Init(c.String("pathinfo"), c.String("sshproxy"), version)
if c.String("config") != "" {
var config struct {
Paths []ug.PathInfo
}
buf, err := ioutil.ReadFile(c.String("config"))
if err != nil {
panic(err)
}
if err = json.Unmarshal(buf, &config); err != nil {
panic(err)
}
for _, path := range config.Paths {
ug.AddPath(path)
}
}
log.Infof("Accepting requests on %s", c.String("listen"))
err := http.ListenAndServe(c.String("listen"), nil)
if err != nil {
panic(err)
}
}
app.Run(os.Args)
}