$120 tested Claude codes · real before/after data · Full tier $15 one-timebuy --sheet=15 →
$Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. download --free →
clskills.sh — terminal v2.4 — 2,347 skills indexed● online
[CL]Skills_
GointermediateNew

Go API Setup

Share

Scaffold Go REST API with Gin or Chi router

Works with OpenClaude

You are a Go backend developer. The user wants to scaffold a complete REST API project using either Gin or Chi router with proper structure, middleware, and example endpoints.

What to check first

  • Run go version to confirm Go 1.19+ is installed
  • Verify $GOPATH/bin is in your $PATH for any CLI tools
  • Check if you're starting in an empty directory or existing Go module

Steps

  1. Initialize Go module with go mod init github.com/yourusername/your-api-name
  2. Install Gin router: go get -u github.com/gin-gonic/gin (or Chi: go get github.com/go-chi/chi/v5)
  3. Create project structure: mkdir -p internal/handlers internal/models internal/middleware cmd/api
  4. Create internal/models/user.go with struct definitions for your data types
  5. Create internal/handlers/user.go to define route handler functions with proper signatures
  6. Create internal/middleware/logging.go for custom middleware (CORS, logging, error handling)
  7. Create cmd/api/main.go as entry point that initializes router and starts server on :8080
  8. Run go mod tidy to clean up dependencies, then go run ./cmd/api to test the server

Code

// cmd/api/main.go
package main

import (
	"log"
	"net/http"
	"github.com/gin-gonic/gin"
	"your-module/internal/handlers"
	"your-module/internal/middleware"
)

func main() {
	router := gin.Default()

	// Apply middleware
	router.Use(middleware.LoggingMiddleware())
	router.Use(middleware.ErrorHandlingMiddleware())

	// Health check endpoint
	router.GET("/health", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{"status": "ok"})
	})

	// User routes
	api := router.Group("/api/v1")
	{
		api.GET("/users", handlers.GetUsers)
		api.POST("/users", handlers.CreateUser)
		api.GET("/users/:id", handlers.GetUserByID)
		api.PUT("/users/:id", handlers.UpdateUser)
		api.DELETE("/users/:id", handlers.DeleteUser)
	}

	log.Println("Server running on :8080")
	if err := router.Run(":8080"); err != nil {
		log.Fatalf("Server failed: %v", err)
	}
}

// internal/models/user.go
package models

type User struct {
	ID    int    `json:"id" binding:"required"`
	Name  string `json:"name" binding:"required"`
	Email string `json:"email" binding:"required,email"`
	Age   int    `json:"age"`

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryGo
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
goapigin

Install command:

curl -o ~/.claude/skills/go-api-setup.md https://claude-skills-hub.vercel.app/skills/go/go-api-setup.md

Related Go Skills

Other Claude Code skills in the same category — free to download.

Want a Go skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.