From d97e119293fd24716cac8970ad141693788f96f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mrozek?= Date: Thu, 30 Nov 2023 19:21:08 +0100 Subject: [PATCH] build: update to transmissionrpc v3 --- go.mod | 1 - go.sum | 3 +-- main.go | 16 ++++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 4249197..9ae8244 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.21 require ( github.com/go-resty/resty/v2 v2.10.0 - github.com/hekmon/transmissionrpc/v2 v2.0.1 github.com/hekmon/transmissionrpc/v3 v3.0.0 ) diff --git a/go.sum b/go.sum index cd54273..c354088 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,7 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hekmon/cunits/v2 v2.1.0 h1:k6wIjc4PlacNOHwKEMBgWV2/c8jyD4eRMs5mR1BBhI0= github.com/hekmon/cunits/v2 v2.1.0/go.mod h1:9r1TycXYXaTmEWlAIfFV8JT+Xo59U96yUJAYHxzii2M= -github.com/hekmon/transmissionrpc/v2 v2.0.1 h1:WkILCEdbNy3n/N/w7mi449waMPdH2AA1THyw7TfnN/w= -github.com/hekmon/transmissionrpc/v2 v2.0.1/go.mod h1:+s96Pkg7dIP3h2PT3fzhXPvNb3OdLryh5J8PIvQg3aA= +github.com/hekmon/transmissionrpc/v3 v3.0.0 h1:0Fb11qE0IBh4V4GlOwHNYpqpjcYDp5GouolwrpmcUDQ= github.com/hekmon/transmissionrpc/v3 v3.0.0/go.mod h1:38SlNhFzinVUuY87wGj3acOmRxeYZAZfrj6Re7UgCDg= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/main.go b/main.go index 3122e09..cad868f 100644 --- a/main.go +++ b/main.go @@ -6,11 +6,12 @@ import ( "flag" "fmt" "log" + "net/url" "os" "time" "github.com/go-resty/resty/v2" - "github.com/hekmon/transmissionrpc/v2" + "github.com/hekmon/transmissionrpc/v3" ) type GluetunResponse struct { @@ -50,10 +51,17 @@ func main() { time.Sleep(initialDelay) httpClient := resty.New() - transmissionClient, err := transmissionrpc.New(*transmissionHostname, transmissionUsername, transmissionPassword, &transmissionrpc.AdvancedConfig{ - Port: uint16(*transmissionPort), - }) + authInfo := "" + if transmissionUsername != "" && transmissionPassword != "" { + authInfo = fmt.Sprintf("%s:%s@", transmissionUsername, transmissionPassword) + } + + endpoint, err := url.Parse(fmt.Sprintf("http://%s%s:%d/transmission/rpc", authInfo, *transmissionHostname, *transmissionPort)) + if err != nil { + log.Fatalf("failed to parse transmission endpoint: %v", err) + } + transmissionClient, err := transmissionrpc.New(endpoint, nil) if err != nil { log.Fatalf("failed to create transmission client: %v", err) }