Skip to content

Commit a9d6476

Browse files
committed
add debugging how to
1 parent a08ca6e commit a9d6476

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ fmt.Printf("Remote transmission RPC version (v%d) is compatible with our transmi
7777
- [Queue Movement Requests](#queue-movement-requests)
7878
- [Free Space](#free-space)
7979
- [Bandwidth Groups](#bandwidth-groups)
80+
- [Debugging](#debugging)
8081

8182
### Torrent Requests
8283

@@ -434,3 +435,45 @@ Mapped as [BandwidthGroupSet()](https://pkg.go.dev/github.com/hekmon/transmissio
434435

435436
Mapped as [BandwidthGroupGet()](https://pkg.go.dev/github.com/hekmon/transmissionrpc/v3?tab=doc#Client.BandwidthGroupGet).
436437

438+
## Debugging
439+
440+
If you want to (or need to) inspect the requests made by the lib, you can use a custom round tripper within a custom HTTP client. I personnaly like to use the [debuglog](https://pkg.go.dev/golift.io/starr/debuglog) package from the [starr](https://github.com/golift/starr) project. Example below.
441+
442+
```golang
443+
package main
444+
445+
import (
446+
"context"
447+
"fmt"
448+
"net/url"
449+
"time"
450+
451+
"github.com/hashicorp/go-cleanhttp"
452+
"github.com/hekmon/transmissionrpc/v3"
453+
"golift.io/starr/debuglog"
454+
)
455+
456+
func main() {
457+
// Parse API endpoint
458+
endpoint, err := url.Parse("http://user:password@127.0.0.1:9091/transmission/rpc")
459+
if err != nil {
460+
panic(err)
461+
}
462+
463+
// Create the HTTP client with debugging capabilities
464+
httpClient := cleanhttp.DefaultPooledClient()
465+
httpClient.Transport = debuglog.NewLoggingRoundTripper(debuglog.Config{
466+
Redact: []string{endpoint.User.String()},
467+
}, httpClient.Transport)
468+
469+
// Initialize the transmission API client with the debbuging HTTP client
470+
tbt, err := transmissionrpc.New(endpoint, &transmissionrpc.Config{
471+
CustomClient: httpClient,
472+
})
473+
if err != nil {
474+
panic(err)
475+
}
476+
477+
// do something with tbt now
478+
}
479+
```

0 commit comments

Comments
 (0)