Skip to content

Commit

Permalink
docs: add info about Go SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Dec 17, 2024
1 parent dd07f50 commit c54f486
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions clients/apps/web/src/app/(main)/docs/developers/sdk/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,65 @@ s = Polar(
access_token="<YOUR_BEARER_TOKEN_HERE>",
)
```

## Go

We maintain a SDK for Go.

### Quickstart

```bash
go get github.com/polarsource/polar-go
```

```go
package main

import(
"context"
"os"
polargo "github.com/polarsource/polar-go"
"log"
)

func main() {
ctx := context.Background()

s := polargo.New(
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)

res, err := s.Benefits.List(ctx, nil, nil, nil, nil)
if err != nil {
log.Fatal(err)
}
if res.ListResourceBenefit != nil {
for {
// handle items

res, err = res.Next()

if err != nil {
// handle error
}

if res == nil {
break
}
}
}
}
```

[<p className="text-xl text-center">Read more</p>](https://github.com/polarsource/polar-go)

### Sandbox environment

You can configure the SDK so it hits the [sandbox environment](/docs/developers/sandbox) instead of the production one. You just need to add the `WithServer` option when initializing the client:

```go
s := polargo.New(
polargo.WithServer("sandbox"),
polargo.WithSecurity(os.Getenv("POLAR_ACCESS_TOKEN")),
)
```

0 comments on commit c54f486

Please sign in to comment.