These are chat archives for anacrolix/torrent

10th
Sep 2018
Santiago Carullo
@santiac89
Sep 10 2018 22:56
Hi!
I'm new to GO and I'm trying to learn by using this library. I'm trying to get a default config struct using NewDefaultClientConfig but it throws an undefined error
/main.go:21:2: undefined: torrent.NewDefaultClientConfig
package main

import "github.com/anacrolix/torrent"
import "github.com/spf13/viper"
import "fmt"
import "log"

func readConfig() {
    viper.AddConfigPath(".")
    viper.SetConfigName("config")
    err := viper.ReadInConfig()

    if err != nil {
        panic(fmt.Errorf("Fatal error config file: %s \n", err))
    }
}

func main() {
    readConfig()

    clientConfig := torrent.NewDefaultClientConfig()
    clientConfig.DataDir := viper.Get("download_dir")

    torrentClient, _ := torrent.NewClient(nil)
    defer torrentClient.Close()

    torrent, _ := torrentClient.AddMagnet("magnet:?xt=urn:btih:ZOCMZQIPFFW7OLLMIC5HUB6BPCSDEOQU")
    // <-torrent.GotInfo()

    torrent.DownloadAll()
    torrentClient.WaitAll()
    log.Print("ermahgerd, torrent downloaded")
}
that's my initial code
deranjer
@deranjer
Sep 10 2018 23:53
@santiac89 newdefaultclientconfig is a function of client. You have to credit Client First before you create a config
c, := torrent.NewClient(nil)
defer c.Close()
t,
:= c.AddMagnet("magnet:?xt=urn:btih:ZOCMZQIPFFW7OLLMIC5HUB6BPCSDEOQU")
<-t.GotInfo()
t.DownloadAll()
c.WaitAll()
log.Print("ermahgerd, torrent downloaded")