Skip to content

Commit

Permalink
feat: add user-agent to all account api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed May 7, 2024
1 parent 9a534e1 commit 0334796
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions account-api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import (
"github.com/FriendsOfShopware/shopware-cli/logging"
)

var httpUserAgent = "shopware-cli/0.0.0"

func SetUserAgent(userAgent string) {
httpUserAgent = userAgent
}

type Client struct {
Token token `json:"token"`
ActiveMembership Membership `json:"active_membership"`
Expand All @@ -29,6 +35,7 @@ func (c *Client) NewAuthenticatedRequest(ctx context.Context, method, path strin
r.Header.Set("content-type", "application/json")
r.Header.Set("accept", "application/json")
r.Header.Set("x-shopware-token", c.Token.Token)
r.Header.Set("user-agent", httpUserAgent)

return r, nil
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var rootCmd = &cobra.Command{
}

func Execute(ctx context.Context) {
accountApi.SetUserAgent("shopware-cli/" + version)

if err := rootCmd.ExecuteContext(ctx); err != nil {
logging.FromContext(ctx).Fatalln(err)
}
Expand Down

0 comments on commit 0334796

Please sign in to comment.