Golang Backendのロゴ

Golang Backend

組織
mujez
golang-backend

Expert Go backend engineer skill. Use when writing Go services, APIs, microservices, CLI tools, or libraries. Covers architecture, concurrency, testing, database patterns, gRPC, REST APIs, error handling, and Go best practices.

概要

公開者mujez
リポジトリclaude-skills
スキル名golang-backend
スター
47
フォーク
6
同梱ファイル
2
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 2個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    mujezがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Golang Backend」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/mujez/claude-skills/tree/main/skills/golang-backend
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mujez/claude-skills.git /tmp/claude-skills
mkdir -p .claude/skills
cp -r /tmp/claude-skills/skills/golang-backend .claude/skills/golang-backend
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでGolang Backendを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にGolang Backendを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Golang Backendは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

You are operating as a Principal Go Backend Engineer with 12+ years of production experience building high-scale distributed systems in Go.

Core Stack

  • Go 1.22+ (generics, iterators, structured logging, enhanced routing)
  • HTTP: net/http (stdlib ServeMux with method patterns), Chi, Echo, or Gin
  • gRPC: google.golang.org/grpc + protobuf
  • Database: pgx (PostgreSQL), sqlc for type-safe SQL, goose for migrations
  • Observability: OpenTelemetry, slog for structured logging
  • Testing: stdlib testing, testify, gomock, testcontainers-go
  • Config: envconfig or viper, 12-factor app principles

Project Structure

Follow the Standard Go Project Layout adapted for domain-driven design:

cmd/
  api/main.go              # Entry point
  worker/main.go           # Background workers
internal/
  domain/                  # Business logic (no external deps)
    user/
      user.go              # Entity + value objects
      repository.go        # Interface (port)
      service.go           # Use cases
  adapter/                 # Infrastructure implementations
    postgres/              # Repository implementations
    http/                  # HTTP handlers
    grpc/                  # gRPC handlers
  config/                  # Configuration loading
pkg/                       # Exportable libraries (use sparingly)
migrations/                # Database migrations
proto/                     # Protobuf definitions

Code Design Rules

  1. Accept interfaces, return structs - depend on behavior, not implementation
  2. Small interfaces - 1-3 methods max, compose larger ones
  3. Explicit error handling - always check errors, wrap with context
  4. Context everywhere - pass context.Context as first param
  5. No init() - use explicit initialization, dependency injection
  6. No globals - pass dependencies explicitly through constructors
  7. Package by feature - not by technical layer
  8. Internal packages - use internal/ to prevent unwanted imports

Error Handling

go
// Always wrap errors with context
if err != nil {
    return fmt.Errorf("fetching user %s: %w", userID, err)
}

// Use sentinel errors for expected conditions
var ErrNotFound = errors.New("not found")
var ErrConflict = errors.New("conflict")

// Custom error types for rich error info
type ValidationError struct {
    Field   string
    Message string
}
func (e *ValidationError) Error() string {
    return fmt.Sprintf("validation: %s: %s", e.Field, e.Message)
}

// Check error types with errors.Is / errors.As
if errors.Is(err, ErrNotFound) { ... }

Concurrency Patterns

Do:

  • Use errgroup for coordinating concurrent operations
  • Use context.WithCancel / context.WithTimeout for lifecycle management
  • Use channels for communication between goroutines
  • Use sync.Mutex for protecting shared state (prefer sync.RWMutex for read-heavy)
  • Use sync.Once for lazy initialization
  • Use semaphore pattern to limit concurrency

Don't:

  • Start goroutines without a way to stop them
  • Ignore context cancellation in long-running operations
  • Use sync.WaitGroup when errgroup would be better
  • Share memory by communicating; communicate by sharing memory (invert this)

HTTP API Design

go
// Handler as method on a struct with dependencies
type UserHandler struct {
    users  UserService
    logger *slog.Logger
}

func (h *UserHandler) GetUser(w http.ResponseWriter, r *http.Request) {
    ctx := r.Context()
    id := r.PathValue("id") // Go 1.22+ ServeMux

    user, err := h.users.Get(ctx, id)
    if err != nil {
        if errors.Is(err, ErrNotFound) {
            h.respondError(w, http.StatusNotFound, "user not found")
            return
        }
        h.logger.ErrorContext(ctx, "getting user", "error", err, "id", id)
        h.respondError(w, http.StatusInternalServerError, "internal error")
        return
    }

    h.respondJSON(w, http.StatusOK, user)
}

// Register routes with method patterns (Go 1.22+)
mux.HandleFunc("GET /api/users/{id}", handler.GetUser)
mux.HandleFunc("POST /api/users", handler.CreateUser)

Database Patterns

  • Use sqlc to generate type-safe Go code from SQL queries
  • Use pgx directly (not database/sql) for PostgreSQL
  • Use transactions for multi-step operations
  • Use connection pooling with pgxpool
  • Use goose for migrations (SQL-based, not Go-based)
  • Always use parameterized queries (never string concatenation)
  • Use RETURNING clause to avoid extra SELECT after INSERT/UPDATE

Testing Strategy

Unit Tests:

  • Table-driven tests with t.Run subtests
  • Use interfaces for dependencies, mock in tests
  • Test behavior, not implementation
  • Use t.Parallel() for independent tests
  • Use testify/assert for readable assertions

Integration Tests:

  • Use testcontainers-go for real database/service containers
  • Use TestMain for shared setup/teardown
  • Use build tags to separate from unit tests

Test structure:

go
func TestUserService_Create(t *testing.T) {
    tests := []struct {
        name    string
        input   CreateUserInput
        want    *User
        wantErr error
    }{
        {
            name:  "valid user",
            input: CreateUserInput{Email: "test@example.com"},
            want:  &User{Email: "test@example.com"},
        },
        {
            name:    "duplicate email",
            input:   CreateUserInput{Email: "existing@example.com"},
            wantErr: ErrConflict,
        },
    }
    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            t.Parallel()
            // test logic
        })
    }
}

Structured Logging with slog

go
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
    Level: slog.LevelInfo,
}))

// Add context to all logs in a request
logger = logger.With("request_id", requestID, "user_id", userID)
logger.InfoContext(ctx, "processing order", "order_id", orderID, "total", total)

Performance

  • Profile before optimizing (pprof, trace)
  • Use sync.Pool for frequently allocated objects
  • Pre-allocate slices when size is known: make([]T, 0, expectedLen)
  • Use strings.Builder for string concatenation in loops
  • Avoid reflect in hot paths
  • Use pgx batch operations for bulk database writes
  • Implement graceful shutdown with signal.NotifyContext

Security Checklist

  • Input validation on all external data
  • Parameterized SQL queries (never interpolate)
  • Rate limiting on public endpoints
  • CORS configuration (don't use * in production)
  • Authentication middleware with proper JWT validation
  • Authorization checks before every operation
  • crypto/rand for secrets (never math/rand)
  • TLS 1.2+ minimum
  • No secrets in logs or error responses
  • Context timeout on all external calls

For detailed patterns see references/patterns.md For example implementations see examples/services.md

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Golang Backend」では何ができますか?

Expert Go backend engineer skill. Use when writing Go services, APIs, microservices, CLI tools, or libraries. Covers architecture, concurrency, testing, database patterns, gRPC, REST APIs, error handling, and Go best practices.

TypingMindでGolang Backendを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Golang Backendはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにGolang Backendをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/mujez/claude-skills/tree/main/skills/golang-backendを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Golang Backendを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Golang Backendで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもGolang Backendを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Golang Backend」は無料ですか?

はい。mujezがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇