Skip to content

Commit

Permalink
feat(client): prepend custom user-agent via FASTLY_USER_AGENT env var…
Browse files Browse the repository at this point in the history
…iable to user (#531)

* Added FASTLY_USER_AGENT env variable

* Prepend to User-Agent instead of overwrite
  • Loading branch information
jsonroy-fastly authored Jun 10, 2024
1 parent 5ff1bf5 commit 557b0b9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions fastly/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const DefaultRealtimeStatsEndpoint = "https://rt.fastly.com"
// JSONMimeType is the MIME type for the JSON data format.
const JSONMimeType = "application/json"

// UserAgentEnvVar is the name of an environment variable that can be used
// to change the User-Agent of the http requests
const UserAgentEnvVar = "FASTLY_USER_AGENT"

// ProjectURL is the url for this library.
var ProjectURL = "github.com/fastly/go-fastly"

Expand Down Expand Up @@ -128,6 +132,10 @@ func NewClientForEndpoint(key, endpoint string) (*Client, error) {
client.DebugMode = true
}

if customUserAgent, ok := os.LookupEnv(UserAgentEnvVar); ok {
UserAgent = fmt.Sprintf("%s, %s", customUserAgent, UserAgent)
}

return client.init()
}

Expand Down

0 comments on commit 557b0b9

Please sign in to comment.