go2

package module
v1.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 16 Imported by: 0

README

Go2 SDK for Go

Go Reference

Official Go SDK for the Go2 gRPC API - Smart App Links Platform.

Installation

go get github.com/gosms-ge/go2-sdk/go

Quick Start

package main

import (
    "context"
    "fmt"
    "log"

    go2 "github.com/gosms-ge/go2-sdk/go"
    linksv1 "github.com/gosms-ge/go2-sdk/go/gen/links/v1"
)

func main() {
    client, err := go2.NewClient(go2.WithAPIKey("go2_your_api_key"))
    if err != nil {
        log.Fatal(err)
    }
    defer client.Close()

    ctx := context.Background()

    // Create a smart link
    link, err := client.Links.Create(ctx, &linksv1.CreateLinkRequest{
        Slug:       "myapp",
        Title:      "My Awesome App",
        IosUrl:     "https://apps.apple.com/app/id123456",
        AndroidUrl: "https://play.google.com/store/apps/details?id=com.myapp",
        WebUrl:     "https://myapp.com",
    })
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Created: https://go2.ge/%s\n", link.Slug)

    // Get analytics
    stats, err := client.Analytics.GetStats(ctx, link.Id, "7d")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Total clicks: %d\n", stats.TotalClicks)
}

Available Services

Create and manage smart links that redirect users to the right app store.

// List all links
links, err := client.Links.List(ctx, 1, 20)

// Create a link
link, err := client.Links.Create(ctx, &linksv1.CreateLinkRequest{
    Slug:        "myapp",
    Title:       "My App",
    IosUrl:      "https://apps.apple.com/...",
    AndroidUrl:  "https://play.google.com/...",
    WebUrl:      "https://myapp.com",
    FallbackUrl: "https://myapp.com/download",
})

// Get a link
link, err := client.Links.Get(ctx, "link-id")

// Update a link
link, err := client.Links.Update(ctx, &linksv1.UpdateLinkRequest{
    Id:       "link-id",
    Title:    "New Title",
    IsActive: false,
})

// Delete a link
err := client.Links.Delete(ctx, "link-id")
Analytics

Access detailed click analytics for your links.

// Get overview stats
stats, err := client.Analytics.GetStats(ctx, "link-id", "30d")

// Get timeseries data
timeseries, err := client.Analytics.GetTimeseries(ctx, "link-id", "7d")

// Get platform breakdown
platforms, err := client.Analytics.GetPlatforms(ctx, "link-id", "30d")

// Get country breakdown
countries, err := client.Analytics.GetCountries(ctx, "link-id", "30d", 10)

// Get referrer breakdown
referrers, err := client.Analytics.GetReferrers(ctx, "link-id", "30d", 10)
Domains

Add and manage custom domains.

// List domains
domains, err := client.Domains.List(ctx)

// Add a domain
domain, err := client.Domains.Create(ctx, "links.myapp.com")

// Verify a domain
domain, err := client.Domains.Verify(ctx, "domain-id")

// Delete a domain
err := client.Domains.Delete(ctx, "domain-id")
QR Codes

Generate customizable QR codes for your links.

qr, err := client.QR.Generate(ctx, &qrv1.GenerateQRRequest{
    LinkId:          "link-id",
    Size:            512,
    Format:          "png",
    ForegroundColor: "#000000",
    BackgroundColor: "#FFFFFF",
})
fmt.Printf("QR Code URL: %s\n", qr.Url)
Integrations

Connect with third-party services (Slack, Discord, Telegram, etc.).

import integrationsv1 "github.com/gosms-ge/go2-sdk/go/gen/integrations/v1"

// List integrations
integrations, err := client.Integrations.List(ctx)

// Create an integration
integration, err := client.Integrations.Create(ctx, &integrationsv1.CreateIntegrationRequest{
    Type: integrationsv1.IntegrationType_INTEGRATION_TYPE_SLACK,
    Name: "Marketing Alerts",
    Config: &integrationsv1.IntegrationConfig{
        WebhookUrl: "https://hooks.slack.com/...",
    },
    Events: []string{"click_alert", "click_milestone"},
})

// Test an integration
result, err := client.Integrations.Test(ctx, "integration-id")

// Delete an integration
err := client.Integrations.Delete(ctx, "integration-id")
Campaigns

Create SMS/Email marketing campaigns with bulk trackable links.

import campaignsv1 "github.com/gosms-ge/go2-sdk/go/gen/campaigns/v1"

// Create a campaign
campaign, err := client.Campaigns.Create(ctx, &campaignsv1.CreateCampaignRequest{
    Name:        "Summer Sale 2024",
    BaseLinkId:  "link-id",
    Type:        "sms",
    UtmSource:   "sms",
    UtmCampaign: "summer_sale",
})

// Generate unique links for recipients
result, err := client.Campaigns.GenerateLinks(ctx, &campaignsv1.GenerateLinksRequest{
    CampaignId: campaign.Id,
    Recipients: []*campaignsv1.Recipient{
        {Identifier: "+1234567890", Metadata: map[string]string{"name": "John"}},
        {Identifier: "+0987654321", Metadata: map[string]string{"name": "Jane"}},
    },
})

// Get campaign stats
stats, err := client.Campaigns.GetStats(ctx, campaign.Id)
fmt.Printf("Click rate: %.2f%%\n", stats.ClickRate)

// Export links
export, err := client.Campaigns.ExportLinks(ctx, campaign.Id, "csv")

Error Handling

import "github.com/gosms-ge/go2-sdk/go/errors"

link, err := client.Links.Get(ctx, "invalid-id")
if err != nil {
    switch e := err.(type) {
    case *errors.NotFoundError:
        fmt.Println("Link not found")
    case *errors.AuthenticationError:
        fmt.Println("Invalid API key")
    case *errors.ValidationError:
        fmt.Printf("Validation error: %s\n", e.Message)
    case *errors.RateLimitError:
        fmt.Println("Rate limit exceeded, try again later")
    default:
        fmt.Printf("Error: %v\n", err)
    }
}

Configuration

// Production (default)
client, _ := go2.NewClient(go2.WithAPIKey("go2_xxx"))

// Custom endpoint (for development)
client, _ := go2.NewClient(
    go2.WithAPIKey("go2_xxx"),
    go2.WithEndpoint("localhost:9090"),
    go2.WithInsecure(), // Disable TLS for local dev
)

Documentation

Full API documentation: https://app.go2.ge/docs#sdks

Requirements

  • Go 1.22+

License

MIT

Documentation

Overview

Package go2 provides a Go SDK for the Go2 gRPC API.

Example usage:

client, err := go2.NewClient(go2.WithAPIKey("go2_your_key"))
if err != nil {
    log.Fatal(err)
}
defer client.Close()

// Create a smart link
link, err := client.Links.Create(ctx, &linksv1.CreateLinkRequest{
    Slug: "myapp",
    Title: "My App",
    IosUrl: "https://apps.apple.com/...",
    AndroidUrl: "https://play.google.com/...",
})

// Get analytics
stats, err := client.Analytics.GetStats(ctx, link.Id, "7d")

// Generate QR code
qr, err := client.QR.Generate(ctx, link.Id, 256, "png")

Index

Constants

View Source
const (
	// DefaultEndpoint is the default gRPC endpoint for the Go2 API.
	DefaultEndpoint = "grpc.go2.ge:443"
)

Variables

View Source
var (
	ErrNotFound         = errors.New("go2: resource not found")
	ErrUnauthenticated  = errors.New("go2: invalid or missing API key")
	ErrPermissionDenied = errors.New("go2: permission denied")
	ErrInvalidArgument  = errors.New("go2: invalid argument")
	ErrRateLimited      = errors.New("go2: rate limit exceeded")
	ErrInternal         = errors.New("go2: internal server error")
)

Common errors returned by the SDK.

Functions

This section is empty.

Types

type AnalyticsClient

type AnalyticsClient struct {
	// contains filtered or unexported fields
}

AnalyticsClient provides methods for link analytics.

func (*AnalyticsClient) GetCountries

func (c *AnalyticsClient) GetCountries(ctx context.Context, linkID string, period string, limit int32) ([]*analyticsv1.CountryStats, error)

GetCountries returns click breakdown by country.

func (*AnalyticsClient) GetPlatforms

func (c *AnalyticsClient) GetPlatforms(ctx context.Context, linkID string, period string) ([]*analyticsv1.PlatformStats, error)

GetPlatforms returns click breakdown by platform.

func (*AnalyticsClient) GetReferrers

func (c *AnalyticsClient) GetReferrers(ctx context.Context, linkID string, period string, limit int32) ([]*analyticsv1.ReferrerStats, error)

GetReferrers returns click breakdown by referrer.

func (*AnalyticsClient) GetStats

func (c *AnalyticsClient) GetStats(ctx context.Context, linkID string, period string) (*analyticsv1.GetStatsResponse, error)

GetStats returns overview statistics for a link.

func (*AnalyticsClient) GetTimeseries

func (c *AnalyticsClient) GetTimeseries(ctx context.Context, linkID string, period string) ([]*analyticsv1.TimeseriesPoint, error)

GetTimeseries returns click data over time.

type CampaignsClient

type CampaignsClient struct {
	// contains filtered or unexported fields
}

CampaignsClient provides methods for managing marketing campaigns.

func (*CampaignsClient) Create

Create creates a new campaign.

func (*CampaignsClient) Delete

func (c *CampaignsClient) Delete(ctx context.Context, id string) error

Delete deletes a campaign.

func (c *CampaignsClient) ExportLinks(ctx context.Context, campaignID string) (*campaignsv1.ExportLinksResponse, error)

ExportLinks exports all campaign links.

GenerateLinks generates links for campaign recipients in bulk.

func (*CampaignsClient) Get

Get returns a campaign by ID.

func (*CampaignsClient) GetStats

func (c *CampaignsClient) GetStats(ctx context.Context, campaignID string) (*campaignsv1.CampaignStats, error)

GetStats returns campaign statistics.

func (*CampaignsClient) List

func (c *CampaignsClient) List(ctx context.Context, limit, offset int32, status, search string) (*campaignsv1.ListCampaignsResponse, error)

List returns all campaigns for the authenticated user.

func (c *CampaignsClient) ListLinks(ctx context.Context, campaignID string, limit, offset int32, clickedOnly bool, search string) (*campaignsv1.ListCampaignLinksResponse, error)

ListLinks returns campaign links with pagination.

func (*CampaignsClient) Update

Update updates a campaign.

type Client

type Client struct {

	// Links provides access to the LinkService for managing smart links.
	Links *LinksClient

	// Analytics provides access to the AnalyticsService for link statistics.
	Analytics *AnalyticsClient

	// Integrations provides access to the IntegrationService.
	Integrations *IntegrationsClient

	// Domains provides access to the DomainService for custom domains.
	Domains *DomainsClient

	// QR provides access to the QRService for QR code generation.
	QR *QRClient

	// Campaigns provides access to the CampaignService for marketing campaigns.
	Campaigns *CampaignsClient
	// contains filtered or unexported fields
}

Client is the Go2 API client.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient creates a new Go2 API client with the given options.

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection.

type DomainsClient

type DomainsClient struct {
	// contains filtered or unexported fields
}

DomainsClient provides methods for managing custom domains.

func (*DomainsClient) Create

Create adds a new custom domain.

func (*DomainsClient) Delete

func (c *DomainsClient) Delete(ctx context.Context, id string) error

Delete removes a custom domain.

func (*DomainsClient) Get

Get returns a domain by ID.

func (*DomainsClient) List

func (c *DomainsClient) List(ctx context.Context) ([]*domainsv1.Domain, error)

List returns all custom domains for the authenticated user.

func (*DomainsClient) Verify

func (c *DomainsClient) Verify(ctx context.Context, id string) (*domainsv1.Domain, error)

Verify triggers domain verification.

type Error

type Error struct {
	Code    codes.Code
	Message string
	Err     error
}

Error represents an API error with additional context.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type IntegrationsClient

type IntegrationsClient struct {
	// contains filtered or unexported fields
}

IntegrationsClient provides methods for managing integrations.

func (*IntegrationsClient) Create

Create creates a new integration.

func (*IntegrationsClient) Delete

func (c *IntegrationsClient) Delete(ctx context.Context, id string) error

Delete deletes an integration.

func (*IntegrationsClient) Get

Get returns an integration by ID.

func (*IntegrationsClient) GetTypes

GetTypes returns all available integration types and events.

func (*IntegrationsClient) List

List returns all integrations for the authenticated user.

func (*IntegrationsClient) Test

Test sends a test notification to an integration.

func (*IntegrationsClient) Update

Update updates an integration.

type LinksClient

type LinksClient struct {
	// contains filtered or unexported fields
}

LinksClient provides methods for managing smart links.

func (*LinksClient) CheckSlug

func (c *LinksClient) CheckSlug(ctx context.Context, slug string) (bool, error)

CheckSlug checks if a slug is available.

func (*LinksClient) Create

Create creates a new smart link.

func (*LinksClient) Delete

func (c *LinksClient) Delete(ctx context.Context, id string) error

Delete deletes a link.

func (*LinksClient) Get

func (c *LinksClient) Get(ctx context.Context, id string) (*linksv1.Link, error)

Get returns a link by ID.

func (*LinksClient) List

func (c *LinksClient) List(ctx context.Context) ([]*linksv1.Link, error)

List returns all links for the authenticated user.

func (*LinksClient) Update

Update updates a link.

type Option

type Option func(*clientConfig)

Option configures the client.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the API key for authentication. Required.

func WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint sets a custom gRPC endpoint. Default: grpc.go2.ge:443

func WithInsecure

func WithInsecure() Option

WithInsecure disables TLS. Use only for local development.

type QRClient

type QRClient struct {
	// contains filtered or unexported fields
}

QRClient provides methods for QR code generation.

func (*QRClient) Generate

Generate creates a QR code for a link.

Directories

Path Synopsis
analytics
v1
campaigns
v1
domains
v1
integrations
v1
links
v1
qr
v1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL