refactor: reformat

This commit is contained in:
xvzc 2022-11-29 16:54:28 +09:00
parent 195a68b26c
commit b552e77cbe
9 changed files with 155 additions and 156 deletions

View File

@ -5,6 +5,7 @@ import (
"sync" "sync"
"regexp" "regexp"
"github.com/babolivier/go-doh-client" "github.com/babolivier/go-doh-client"
) )
@ -22,7 +23,6 @@ func Lookup(domain string) (string, error) {
return domain, nil return domain, nil
} }
a, _, err := resolver.LookupA(domain) a, _, err := resolver.LookupA(domain)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -45,17 +45,17 @@ func (c *Conn) Write(b []byte) (n int, err error) {
return c.conn.Write(b) return c.conn.Write(b)
} }
func (c *Conn) SetReadDeadline(t time.Time) (error) { func (c *Conn) SetReadDeadline(t time.Time) error {
c.conn.SetReadDeadline(t) c.conn.SetReadDeadline(t)
return nil return nil
} }
func (c *Conn) SetDeadLine(t time.Time) (error) { func (c *Conn) SetDeadLine(t time.Time) error {
c.conn.SetDeadline(t) c.conn.SetDeadline(t)
return nil return nil
} }
func (c *Conn) SetKeepAlive(b bool) (error) { func (c *Conn) SetKeepAlive(b bool) error {
c.conn.SetKeepAlive(b) c.conn.SetKeepAlive(b)
return nil return nil
} }
@ -107,7 +107,7 @@ func (lConn *Conn) HandleHttp(p *packet.HttpPacket) {
ip, err := doh.Lookup(p.Domain()) ip, err := doh.Lookup(p.Domain())
if err != nil { if err != nil {
log.Error("[HTTP DOH] Error looking up for domain with ", p.Domain() , " ", err) log.Error("[HTTP DOH] Error looking up for domain with ", p.Domain(), " ", err)
lConn.Write([]byte(p.Version() + " 502 Bad Gateway\r\n\r\n")) lConn.Write([]byte(p.Version() + " 502 Bad Gateway\r\n\r\n"))
return return
} }

View File

@ -8,9 +8,8 @@ type TCPAddr struct {
Addr *net.TCPAddr Addr *net.TCPAddr
} }
func TcpAddr(ip string, port int) *TCPAddr {
func TcpAddr(ip string, port int) (*TCPAddr) { addr := &net.TCPAddr{
addr := &net.TCPAddr {
IP: net.ParseIP(ip), IP: net.ParseIP(ip),
Port: port, Port: port,
} }

View File

@ -56,7 +56,7 @@ func ParseUrl(raw []byte) {
} }
func NewHttpPacket(raw []byte) (*HttpPacket, error){ func NewHttpPacket(raw []byte) (*HttpPacket, error) {
pkt := &HttpPacket{raw: raw} pkt := &HttpPacket{raw: raw}
pkt.parse() pkt.parse()
@ -123,7 +123,7 @@ func (p *HttpPacket) Tidy() {
p.raw = []byte(result) p.raw = []byte(result)
} }
func (p *HttpPacket )parse() error { func (p *HttpPacket) parse() error {
reader := bufio.NewReader(strings.NewReader(string(p.raw))) reader := bufio.NewReader(strings.NewReader(string(p.raw)))
request, err := http.ReadRequest(reader) request, err := http.ReadRequest(reader)
if err != nil { if err != nil {

View File

@ -18,12 +18,12 @@ func SetOsProxy(port int) error {
return err return err
} }
_, err = exec.Command("sh", "-c", "networksetup -setwebproxy "+ "'" +strings.TrimSpace(string(network)) + "'" + " 127.0.0.1 "+ fmt.Sprint(port)).Output() _, err = exec.Command("sh", "-c", "networksetup -setwebproxy "+"'"+strings.TrimSpace(string(network))+"'"+" 127.0.0.1 "+fmt.Sprint(port)).Output()
if err != nil { if err != nil {
return err return err
} }
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy " + "'" + strings.TrimSpace(string(network))+"'" + " 127.0.0.1 "+ fmt.Sprint(port)).Output() _, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxy "+"'"+strings.TrimSpace(string(network))+"'"+" 127.0.0.1 "+fmt.Sprint(port)).Output()
if err != nil { if err != nil {
return err return err
} }
@ -41,12 +41,12 @@ func UnsetOsProxy() error {
return err return err
} }
_, err = exec.Command("sh", "-c", "networksetup -setwebproxystate " + "'" + strings.TrimSpace(string(network)) + "'" + " off").Output() _, err = exec.Command("sh", "-c", "networksetup -setwebproxystate "+"'"+strings.TrimSpace(string(network))+"'"+" off").Output()
if err != nil { if err != nil {
return err return err
} }
_, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxystate " + "'" + strings.TrimSpace(string(network)) + "'" + " off").Output() _, err = exec.Command("sh", "-c", "networksetup -setsecurewebproxystate "+"'"+strings.TrimSpace(string(network))+"'"+" off").Output()
if err != nil { if err != nil {
return err return err
} }