Skip to content
Back to skills

Alibabacloud Sdk Client Initialization For Golang

ASecurity

Initialize and manage Alibaba Cloud SDK clients in Go. Covers sync.Once singleton, goroutine safety, endpoint vs region configuration, VPC endpoints, and debug mode. Use when the user creates Go SDK clients, configures endpoints, asks about goroutine safety, singleton patterns, or VPC endpoint setup in the Alibaba Cloud Go SDK.

  • 11 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 10, 2026
code-qualitygobashdebugginggitapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned September 10, 2026

npx -y skills add luokai0/ai-agent-skills-by-luo-kai --skill alibabacloud-sdk-client-initialization-for-golang --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Alibabacloud Sdk Client Initialization For Golang?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Alibabacloud Sdk Client Initialization For Golang
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/luokai0-alibabacloud-sdk-client-initialization-for-golang/badge)](https://www.skillsdirectory.com/skills/luokai0-alibabacloud-sdk-client-initialization-for-golang)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: alibabacloud-sdk-client-initialization-for-golang
description: >
  Initialize and manage Alibaba Cloud SDK clients in Go. Covers sync.Once singleton, goroutine safety, endpoint vs region
  configuration, VPC endpoints, and debug mode. Use when the user creates Go SDK clients, configures endpoints, asks about
  goroutine safety, singleton patterns, or VPC endpoint setup in the Alibaba Cloud Go SDK.
version: 0.0.1-beta
---

# Client Initialization Best Practices (Go)

## Core Rules

- **Client is goroutine-safe** — safe to share across goroutines without additional synchronization.
- **Use singleton pattern** — do NOT create new client instances per request. Frequent client creation wastes resources.
- Prefer **explicit endpoint** over region-based endpoint resolution.

## Recommended Client Creation

```go
import (
    "os"
    "sync"

    openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
    ecs "github.com/alibabacloud-go/ecs-20140526/v3/client"
    "github.com/alibabacloud-go/tea/tea"
)

var (
    ecsClient     *ecs.Client
    ecsClientOnce sync.Once
)

func GetEcsClient() *ecs.Client {
    ecsClientOnce.Do(func() {
        config := &openapi.Config{
            AccessKeyId:     tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")),
            AccessKeySecret: tea.String(os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")),
            Endpoint:        tea.String("ecs.cn-hangzhou.aliyuncs.com"),
        }
        var err error
        ecsClient, err = ecs.NewClient(config)
        if err != nil {
            panic(err)
        }
    })
    return ecsClient
}
```

## Endpoint Configuration

Priority: explicit `Endpoint` > region-based resolution via `RegionId`.

```go
// Preferred: explicit endpoint
config.Endpoint = tea.String("ecs.cn-hangzhou.aliyuncs.com")

// Alternative: SDK resolves endpoint from region
config.RegionId = tea.String("cn-hangzhou")
```

### VPC Endpoints

Use VPC endpoints when running inside Alibaba Cloud VPC:

```go
config.Endpoint = tea.String("ecs-vpc.cn-hangzhou.aliyuncs.com")
```

### File Upload APIs (Advance)

Set **both** `RegionId` and `Endpoint` to the same region for file upload APIs:

```go
config.RegionId = tea.String("cn-shanghai")
config.Endpoint = tea.String("objectdet.cn-shanghai.aliyuncs.com")
// VPC file upload authorization:
client.OpenPlatformEndpoint = tea.String("openplatform-vpc.cn-shanghai.aliyuncs.com")
client.EndpointType = tea.String("internal")
```

## SDK Components

| Component | Description |
|-----------|-------------|
| Core SDK (`darabonba-openapi`) | Generic calls, no product dependency |
| Product SDK (e.g., `ecs-20140526`) | Typed client, models, convenience methods |

## Debugging

Enable debug mode via environment variable to log all requests:

```bash
export DEBUG=tea
```

Files in this skill

  • .clawhub/origin.json186 B
  • SKILL.md2.7 KB
  • _meta.json173 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.