-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (38 loc) · 798 Bytes
/
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
package main
import (
"fmt"
"os"
"os/signal"
"strconv"
"syscall"
"github.com/oosawy/magichost/client"
"github.com/oosawy/magichost/daemon"
"github.com/oosawy/magichost/proxy"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("usage: magichost daemon")
fmt.Println(" or: magichost [client] (list|claim)")
os.Exit(1)
return
}
switch os.Args[1] {
case "daemon":
daemon.Do()
case "proxy":
table := map[string]proxy.MagicEntry{}
proxy.Start(table)
p, err := strconv.Atoi(os.Args[2])
if err != nil {
panic(err)
}
table[os.Args[3]] = proxy.MagicEntry{Port: p}
quitChannel := make(chan os.Signal, 1)
signal.Notify(quitChannel, syscall.SIGINT, syscall.SIGTERM)
<-quitChannel
case "client":
client.Do(os.Args[2:])
default:
client.Do(os.Args[1:])
}
}