From cd9ced6849a822dbff478179d6e784d40328c5de Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Tue, 29 Dec 2020 14:59:11 +0300 Subject: [PATCH] add dns resoler --- src/main/main.go | 49 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/main/main.go b/src/main/main.go index 4104d8e..4847075 100644 --- a/src/main/main.go +++ b/src/main/main.go @@ -1,10 +1,9 @@ package main import ( - "bytes" - "errors" + "context" "fmt" - "net/http" + "net" "os" "time" @@ -18,7 +17,6 @@ import ( type args struct { Port string `arg:"-p" help:"web server port"` Path string `arg:"-d" help:"database path"` - Add string `arg:"-a" help:"add torrent link and exit"` RDB bool `arg:"-r" help:"start in read-only DB mode"` DontKill bool `arg:"-k" help:"dont kill program on signal"` } @@ -40,10 +38,8 @@ func main() { params.Port = "8090" } - if params.Add != "" { - add() - } settings.Path = params.Path + dnsResolve() Preconfig(params.DontKill) server.Start(params.Port, params.RDB) @@ -52,28 +48,21 @@ func main() { os.Exit(0) } -func add() { - err := addRemote() - if err != nil { - fmt.Println("Error add torrent:", err) - os.Exit(-1) - } +func dnsResolve() { + addrs, err := net.LookupHost("www.themoviedb.org") + if len(addrs) == 0 { + fmt.Println("Check dns", addrs, err) - fmt.Println("Added ok") - os.Exit(0) -} - -func addRemote() error { - url := "http://localhost:" + params.Port + "/torrent/add" - fmt.Println("Add torrent link:", params.Add, "\n", url) - - json := `{"Link":"` + params.Add + `"}` - resp, err := http.Post(url, "text/html; charset=utf-8", bytes.NewBufferString(json)) - if err != nil { - return err - } - if resp.StatusCode != 200 { - return errors.New(resp.Status) - } - return nil + fn := func(ctx context.Context, network, address string) (net.Conn, error) { + d := net.Dialer{} + return d.DialContext(ctx, "udp", "1.1.1.1:53") + } + + net.DefaultResolver = &net.Resolver{ + Dial: fn, + } + + addrs, err = net.LookupHost("www.themoviedb.org") + fmt.Println("Check new dns", addrs, err) + } }