-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
89 lines (76 loc) · 1.41 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
87
88
89
// Froxy - HTTP over SSH proxy
//
// Copyright (C) 2019 and up by Alexander Pevzner (pzz@apevzner.com)
// See LICENSE for license terms and conditions
//
// The main module
package main
import (
"os"
)
//
// Froxy administration (install/uninstall etc)
//
func FroxyAdm(env *Env, opt *Options) {
adm, err := NewAdm(env, opt.Port)
if err != nil {
adm.Fatal("%s", err)
}
switch opt.Cmd {
case OptCmdInstall:
err = adm.Install(opt.Flags)
case OptCmdUninstall:
err = adm.Uninstall()
case OptCmdKill:
err = adm.Kill()
case OptCmdRunBg:
err = adm.Run()
case OptCmdOpen:
err = adm.Open()
default:
panic("Internal error")
}
if err != nil {
adm.Fatal("%s", err)
}
os.Exit(0)
}
func main() {
// Create environment
env := NewEnv()
// Parse command-line options
var opt Options
err := opt.Parse(env)
if err != nil {
opt.Error(err)
}
// Perform administration actions, if required
switch opt.Cmd {
case OptCmdNone:
opt.Usage(env, false)
case OptCmdHelp:
opt.Usage(env, true)
case OptCmdRunFg, OptCmdDebug:
default:
FroxyAdm(env, &opt)
}
// Acquire froxy.lock
err = env.FroxyLockAcquire()
if err != nil {
env.Fatal("%s", err)
}
// Create froxy
proxy, err := NewFroxy(env, opt.Port)
if err != nil {
env.Fatal("%s", err)
}
// Detach stdin/stdout/stderr
if opt.Cmd != OptCmdDebug {
err = env.Detach()
if err != nil {
env.Fatal("%s", err)
}
}
// Run froxy
proxy.Run()
}