From 1581f9c4d1887fa2742be68edc24d997e28807fe Mon Sep 17 00:00:00 2001 From: xvzc Date: Sat, 8 Jan 2022 02:03:46 +0900 Subject: [PATCH] refactor --- config/config.go | 38 +++++++++++++++++++------------------- proxy/http.go | 24 ++++++++++++------------ util/welcome.go | 15 +++++++-------- 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/config/config.go b/config/config.go index b1cefbb..f2e3646 100644 --- a/config/config.go +++ b/config/config.go @@ -1,15 +1,15 @@ -package config +package config import ( - "sync" - "runtime" + "runtime" + "sync" ) type Config struct { - Port string - DNS string - OS string - Debug bool + Port string + DNS string + OS string + Debug bool } var config *Config @@ -17,21 +17,21 @@ var once sync.Once var err error func InitConfig(port string, dns string, debug bool) error { - err = nil + err = nil - once.Do(func() { + once.Do(func() { - config = &Config{ - Port : port, - DNS : dns, - OS : runtime.GOOS, - Debug : debug, - } - }) + config = &Config{ + Port: port, + DNS: dns, + OS: runtime.GOOS, + Debug: debug, + } + }) - return err + return err } -func GetConfig() (*Config) { - return config +func GetConfig() *Config { + return config } diff --git a/proxy/http.go b/proxy/http.go index 193265d..3352b86 100644 --- a/proxy/http.go +++ b/proxy/http.go @@ -7,20 +7,20 @@ import ( "github.com/xvzc/SpoofDPI/util" ) -func HandleHttp(clientConn net.Conn, ip string, message []byte) { - remoteConn, err := net.Dial("tcp", ip+":80") // create connection to server - if err != nil { - util.Debug(err) - return - } - defer remoteConn.Close() +func HandleHttp(clientConn net.Conn, ip string, message []byte) { + remoteConn, err := net.Dial("tcp", ip+":80") // create connection to server + if err != nil { + util.Debug(err) + return + } + defer remoteConn.Close() - util.Debug("[HTTP] Connected to the server.") + util.Debug("[HTTP] Connected to the server.") - go Serve(remoteConn, clientConn, "HTTP") + go Serve(remoteConn, clientConn, "HTTP") - util.Debug("[HTTP] Sending request to the server") - fmt.Fprintf(remoteConn, string(message)) + util.Debug("[HTTP] Sending request to the server") + fmt.Fprintf(remoteConn, string(message)) - Serve(clientConn, remoteConn, "HTTP") + Serve(clientConn, remoteConn, "HTTP") } diff --git a/util/welcome.go b/util/welcome.go index 32e4bdb..4016d26 100644 --- a/util/welcome.go +++ b/util/welcome.go @@ -5,15 +5,14 @@ import ( "github.com/xvzc/SpoofDPI/config" ) - func PrintWelcome() { - cyan := pterm.NewLettersFromStringWithStyle("Spoof", pterm.NewStyle(pterm.FgCyan)) - purple := pterm.NewLettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta)) - pterm.DefaultBigText.WithLetters(cyan, purple).Render() + cyan := pterm.NewLettersFromStringWithStyle("Spoof", pterm.NewStyle(pterm.FgCyan)) + purple := pterm.NewLettersFromStringWithStyle("DPI", pterm.NewStyle(pterm.FgLightMagenta)) + pterm.DefaultBigText.WithLetters(cyan, purple).Render() - pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{ - {Level: 0, Text: "PORT : " + config.GetConfig().Port}, - {Level: 0, Text: "DNS : " + config.GetConfig().DNS}, - }).Render() + pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{ + {Level: 0, Text: "PORT : " + config.GetConfig().Port}, + {Level: 0, Text: "DNS : " + config.GetConfig().DNS}, + }).Render() }