-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (68 loc) · 2.03 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
package main
import (
"log"
"os"
"os/user"
"path/filepath"
"github.com/joho/godotenv"
"github.com/urfave/cli"
"github.com/earaujoassis/hermes/server"
"github.com/earaujoassis/hermes/server/web"
"github.com/earaujoassis/hermes/server/tunnel"
"github.com/earaujoassis/hermes/client"
)
func loadDotenv() {
err := godotenv.Load()
if err != nil {
log.Println("> The environment file (.env) doesn't exist; skipping")
}
}
func main() {
var filepathConfig string
app := cli.NewApp()
app.Name = "Hermes"
app.Usage = "An application for introspected tunnels to localhost"
app.EnableBashCompletion = true
app.Commands = []cli.Command{
{
Name: "web",
Usage: "Serve the web application / REST API",
Action: func(c *cli.Context) error {
loadDotenv()
server.RepositoryStart()
web.SetupWeb()
return nil
},
},
{
Name: "tunnel",
Usage: "Serve the tunnel server",
Action: func(c *cli.Context) error {
loadDotenv()
tunnel.SetupTunnel()
return nil
},
},
{
Name: "client",
Usage: "Client resposible for creating and retrieving HTTP messages",
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "Load configuration from `FILE`",
Value: "",
Destination: &filepathConfig,
},
},
Action: func(c *cli.Context) error {
if filepathConfig == "" {
usr, _ := user.Current()
filepathConfig, _ = filepath.Abs(filepath.Join(usr.HomeDir, ".hermes.config.json"))
}
client.SetupClient(filepathConfig)
return nil
},
},
}
app.Run(os.Args)
}