diff --git a/knock/client.go b/knock/client.go index 355bdcb..97fe52f 100644 --- a/knock/client.go +++ b/knock/client.go @@ -5,11 +5,13 @@ import ( "context" "encoding/json" "errors" + "fmt" "io" "net/http" "net/url" "github.com/hashicorp/go-cleanhttp" + "github.com/knocklabs/knock-go/knock/internal" ) const ( @@ -122,6 +124,8 @@ func NewClient(opts ...ClientOption) (*Client, error) { // do makes an HTTP request and populates the given struct v from the response. func (c *Client) do(ctx context.Context, req *http.Request, v interface{}) ([]byte, error) { req = req.WithContext(ctx) + req.Header.Set("User-Agent", fmt.Sprintf("knocklabs/go@%s", internal.SDKVersion)) + res, err := c.client.Do(req) if err != nil { return nil, err diff --git a/knock/internal/sdk_version.go b/knock/internal/sdk_version.go new file mode 100644 index 0000000..e298ef8 --- /dev/null +++ b/knock/internal/sdk_version.go @@ -0,0 +1,5 @@ +package internal + +// This is used for formatting the SDK's user agent. It should be updated before +// releasing new versions of the SDK. Eventually we can automate this process. +const SDKVersion = "0.1.16"