Skip to content
Skillv1.0.0

go-echo

You are an expert in Echo, the high-performance, minimalist Go web framework. You help developers build REST APIs and web applications using Echo's optimized router, middleware chain, data binding, va

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/go-echo/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill go-echo. Copyright stays with the author (Apache-2.0).

Echo — High-Performance Go Web Framework

You are an expert in Echo, the high-performance, minimalist Go web framework. You help developers build REST APIs and web applications using Echo's optimized router, middleware chain, data binding, validation, template rendering, and WebSocket support — providing a clean API surface with excellent performance and comprehensive built-in middleware.

Core Capabilities

Application Setup

package main

import (
    "net/http"
    "github.com/labstack/echo/v4"
    "github.com/labstack/echo/v4/middleware"
)

func main() {
    e := echo.New()

    // Middleware
    e.Use(middleware.Logger())
    e.Use(middleware.Recover())
    e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
        AllowOrigins: []string{"https://app.example.com"},
        AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete},
    }))
    e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(20)))

    // Routes
    e.GET("/users", listUsers)
    e.POST("/users", createUser)
    e.GET("/users/:id", getUser)

    // Groups with middleware
    admin := e.Group("/admin", adminAuth)
    admin.GET("/stats", getStats)

    e.Logger.Fatal(e.Start(":3000"))
}

Handlers and Binding

type CreateUserRequest struct {
    Name  string `json:"name" validate:"required,min=2"`
    Email string `json:"email" validate:"required,email"`
    Age   int    `json:"age" validate:"gte=0,lte=130"`
}

func createUser(c echo.Context) error {
    var req CreateUserRequest
    if err := c.Bind(&req); err != nil {
        return echo.NewHTTPError(http.StatusBadRequest, "Invalid request")
    }
    if err := c.Validate(&req); err != nil {
        return err
    }

    user, err := db.CreateUser(req.Name, req.Email, req.Age)
    if err != nil {
        return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create user")
    }

    return c.JSON(http.StatusCreated, user)
}

func getUser(c echo.Context) error {
    id := c.Param("id")                   // Path param
    user, err := db.FindUser(id)
    if err != nil {
        return echo.NewHTTPError(http.StatusNotFound, "User not found")
    }
    return c.JSON(http.StatusOK, user)
}

func listUsers(c echo.Context) error {
    page, _ := strconv.Atoi(c.QueryParam("page"))  // Query param
    if page < 1 { page = 1 }

    users, total := db.ListUsers(page, 20)
    return c.JSON(http.StatusOK, map[string]interface{}{
        "data": users, "total": total, "page": page,
    })
}

JWT Middleware

import "github.com/labstack/echo-jwt/v4"

// Configure JWT
e.Use(echojwt.WithConfig(echojwt.Config{
    SigningKey: []byte(os.Getenv("JWT_SECRET")),
    Skipper: func(c echo.Context) bool {
        return c.Path() == "/health" || c.Path() == "/login"
    },
}))

// Access claims in handler
func getProfile(c echo.Context) error {
    token := c.Get("user").(*jwt.Token)
    claims := token.Claims.(jwt.MapClaims)
    userID := claims["user_id"].(string)
    // ...
}

Installation

go get github.com/labstack/echo/v4
go get github.com/labstack/echo-jwt/v4

Best Practices

  1. Context methods — Use c.Bind() for request parsing, c.JSON() for responses, c.Param() / c.QueryParam() for params
  2. Groups for versioninge.Group("/api/v1") with per-group middleware (auth, rate limiting)
  3. HTTPError for responses — Return echo.NewHTTPError(status, message) for consistent error responses
  4. Validator — Register a custom validator with e.Validator; Echo calls it automatically after Bind()
  5. Middleware chaininge.Use() for global, group-level, or per-route; Echo processes in order
  6. Graceful shutdown — Use e.Shutdown(ctx) with signal handling; drains active connections
  7. Custom context — Extend echo.Context for request-scoped data (user, logger, trace ID)
  8. Static filese.Static("/assets", "public") for serving static files alongside API routes

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-go-echo/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-go-echo.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-go-echo",
  "kind": "skill",
  "name": "go-echo",
  "description": "You are an expert in Echo, the high-performance, minimalist Go web framework. You help developers build REST APIs and web applications using Echo's optimized router, middleware chain, data binding, validation, template rendering, and WebSocket support — providing a clean API surface with excellent performance and comprehensive built-in middleware.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding"
    ],
    "tags": [
      "skill-md",
      "go",
      "web-framework",
      "api",
      "middleware",
      "rest",
      "high-performance",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "You are an expert in Echo, the high-performance, minimalist Go web framework. You help developers build REST APIs and web applications using Echo's optimized router, middleware chain, data binding, validation, template rendering, and WebSocket support — providing a clean API surface with excellent performance and comprehensive built-in middleware."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/go-echo/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/go-echo/SKILL.md",
      "key": "terminalskills/skills/skills/go-echo/SKILL.md"
    },
    "license": "Apache-2.0"
  },
  "instructions": "# Echo — High-Performance Go Web Framework\n\nYou are an expert in Echo, the high-performance, minimalist Go web framework. You help developers build REST APIs and web applications using Echo's optimized router, middleware chain, data binding, validation, template rendering, and WebSocket support — providing a clean API surface with excellent performance and comprehensive built-in middleware.\n\n## Core Capabilities\n\n### Application Setup\n\n```go\npackage main\n\nimport (\n    \"net/http\"\n    \"github.com/labstack/echo/v4\"\n    \"github.com/labstack/echo/v4/middleware\"\n)\n\nfunc main() {\n    e := echo.New()\n",
  "cost": {
    "context_tokens": 1000
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-go-echo/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.