linode / linodego

Go client for Linode REST v4 API
MIT License
138 stars 81 forks source link

fix: Prevent unexpected warning from Resty when calling `Client.SetDebug(false)` #508

Closed lgarber-akamai closed 5 months ago

lgarber-akamai commented 5 months ago

📝 Description

This pull request fixes a small issue that would cause the following Resty warning (raised here) to be printed when Client.SetDebug(...) is called multiple times:

WARN RESTY Overwriting an existing on-request-log callback from=github.com/linode/linodego.(*Client).SetDebug.(*Client).sanitizeAuthorizationHeader.func1 to=github.com/linode/linodego.(*Client).SetDebug.(*Client).sanitizeAuthorizationHeader.func1

This works by initializing the log hook during client creation rather than when calling SetDebug(...).

✔️ How to Test

The following test steps assume you have pulled down this PR locally.

Manual Testing

  1. In a linodego sandbox environment (e.g. dx-devenv), run the following:
package main

import (
    "github.com/linode/linodego"
)

func main() {
    client := linodego.NewClient(nil)
    client.SetDebug(true)
    client.SetDebug(true)
    client.SetDebug(false)
}
  1. Ensure no warnings are raised from Resty.