> ## Documentation Index
> Fetch the complete documentation index at: https://dub.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Go SDK

> Learn how to integrate Dub with Go.

## Installation

```bash theme={null}
go get github.com/dubinc/dub-go
```

## Basic Usage

Here's how you can use the Dub Go SDK to create a link and retrieve click analytics in timeseries format for it:

```go theme={null}
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	dub "github.com/dubinc/dub-go"
)

func main() {
	// Initialize the Dub SDK with your API key
	d := dub.New(
		dub.WithSecurity(os.Getenv("DUB_API_KEY")), // optional, defaults to DUB_API_KEY
	)

	// Create a new link
	request := &operations.CreateLinkRequestBody{
		URL: "https://google.com",
	}

	ctx := context.Background()
	res, err := d.Links.Create(ctx, request)
	if err != nil {
		log.Fatal(err)
	}
	if res.LinkSchema != nil {
		fmt.Println(res.LinkSchema.ShortLink) // e.g. https://dub.sh/abc123
	}

	// Get analytics for the link
	analyticsRequest := operations.RetrieveAnalyticsRequest{
		LinkId:   res.LinkSchema.ID,
		GroupBy:  "timeseries",
		Interval: "30d",
	}

	analyticsRes, err := d.Analytics.Retrieve(ctx, analyticsRequest)
	if err != nil {
		log.Fatal(err)
	}
	if analyticsRes.OneOf != nil {
		fmt.Println(analyticsRes.OneOf) // e.g. [{ start: "2024-01-01", clicks: 100 }]
	}
}
```

For more usage examples:

1. [Organizing links by external ID, tenant ID, tags, etc](/docs/concepts/links/organization)
2. [Bulk link operations (create, update, delete)](/docs/concepts/links/bulk-operations)
3. [Retrieving link analytics](/docs/concepts/analytics)

You can also check out the [Go SDK quickstart](/docs/sdks/quickstart/go) for a basic example.

## Additional Resources

<CardGroup cols={2}>
  <Card title="Go Package" icon="golang" href="https://d.to/go/sdk">
    Download and install the Dub Go SDK on GitHub
  </Card>

  <Card title="SDK Reference" icon="book" iconType="solid" href="https://github.com/dubinc/dub-go/blob/main/README.md">
    View the complete SDK reference documentation
  </Card>

  <Card title="Examples" icon="github" href="https://github.com/dubinc/examples/tree/main/go">
    Quickstart examples with the Go SDK
  </Card>
</CardGroup>
