refactor main.go

This commit is contained in:
xvzc 2022-01-09 02:40:05 +09:00
parent 1a55f159d1
commit 3739c8b712

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"fmt"
"log" "log"
"os" "os"
"os/signal" "os/signal"
@ -16,18 +15,15 @@ func main() {
port, dns, debug := util.ParseArgs() port, dns, debug := util.ParseArgs()
p := proxy.New(port, dns, runtime.GOOS, debug) p := proxy.New(port, dns, runtime.GOOS, debug)
fmt.Println(*p)
p.PrintWelcome() p.PrintWelcome()
err := p.SetOsProxy() if err := p.SetOsProxy(); err != nil {
if err != nil {
log.Fatal(err) log.Fatal(err)
os.Exit(1)
} }
go p.Start() go p.Start()
// Handle signals
sigs := make(chan os.Signal, 1) sigs := make(chan os.Signal, 1)
done := make(chan bool, 1) done := make(chan bool, 1)
@ -45,9 +41,7 @@ func main() {
}() }()
<-done <-done
err = p.UnsetOsProxy() if err := p.UnsetOsProxy(); err != nil {
if err != nil {
log.Fatal(err) log.Fatal(err)
os.Exit(1)
} }
} }