chi

Description for Chi expertise: Chi is a lightweight, idiomatic Go HTTP router built on net/http. Used to help developers build composable HTTP services using middleware stacks, route groups, URL parameters, subrouters, and context-based request scopes, providing Express-like ergonomics while remaining 100% compatible with the Go standard library.

Last repository push
GitHub Stars
219
Forks
38
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "chi" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-bb46d03922672adcde5fc25e897224ca663105be2d3ac63be71fdb6df1dd0eee. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Description for Chi expertise: Chi is a lightweight, idiomatic Go HTTP router built on net/http. Used to help developers build composable HTTP services using middleware stacks, route groups, URL parameters, subrouters, and context-based request scopes, providing Express-like ergonomics while remaining 100% compatible with the Go standard library.

0 Downloads

Introduction source: third_party · TerminalSkills · 1.0.0 Reference

SkillPi interpretation

Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: chi
description: >-
  You are an expert in Chi, the lightweight, idiomatic Go HTTP router built
  on `net/http`. You help developers build composable HTTP services using
  Chi's middleware stack, route groups, URL parameters, sub-routers, and
  context-based request scoping — providing Express-like ergonomics while
  staying 100% compatible with Go's standard library.
license: Apache-2.0
compatibility: ''
metadata:
  author: terminal-skills
  version: 1.0.0
  category: Backend Development
  tags:
    - go
    - router
    - http
    - middleware
    - lightweight
    - stdlib-compatible

Chi — Lightweight Go HTTP Router

You are an expert in Chi, the lightweight, idiomatic Go HTTP router built on net/http. You help developers build composable HTTP services using Chi's middleware stack, route groups, URL parameters, sub-routers, and context-based request scoping — providing Express-like ergonomics while staying 100% compatible with Go's standard library.

Core Capabilities

Router and Routes

package main

import (
    "encoding/json"
    "net/http"
    "github.com/go-chi/chi/v5"
    "github.com/go-chi/chi/v5/middleware"
    "github.com/go-chi/cors"
)

func main() {
    r := chi.NewRouter()

    // Built-in middleware
    r.Use(middleware.Logger)
    r.Use(middleware.Recoverer)
    r.Use(middleware.RequestID)
    r.Use(middleware.RealIP)
    r.Use(middleware.Timeout(30 * time.Second))
    r.Use(cors.Handler(cors.Options{
        AllowedOrigins: []string{"https://app.example.com"},
        AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
    }))

    // Public routes
    r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
        json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
    })

    // Protected routes
    r.Route("/api", func(r chi.Router) {
        r.Use(authMiddleware)

        r.Route("/users", func(r chi.Router) {
            r.Get("/", listUsers)
            r.Post("/", createUser)

            r.Route("/{userID}", func(r chi.Router) {
                r.Use(userCtx)            // Load user into context
                r.Get("/", getUser)
                r.Put("/", updateUser)
                r.Delete("/", deleteUser)
                r.Get("/posts", getUserPosts)
            })
        })
    })

    http.ListenAndServe(":3000", r)
}

// Context middleware — load resource once, use in all sub-routes
func userCtx(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        userID := chi.URLParam(r, "userID")
        user, err := db.FindUser(userID)
        if err != nil {
            http.Error(w, "user not found", 404)
            return
        }
        ctx := context.WithValue(r.Context(), "user", user)
        next.ServeHTTP(w, r.WithContext(ctx))
    })
}

func getUser(w http.ResponseWriter, r *http.Request) {
    user := r.Context().Value("user").(*User)
    json.NewEncoder(w).Encode(user)
}

func listUsers(w http.ResponseWriter, r *http.Request) {
    page := r.URL.Query().Get("page")
    users, _ := db.ListUsers(page)
    w.Header().Set("Content-Type", "application/json")
    json.NewEncoder(w).Encode(users)
}

Installation

go get -u github.com/go-chi/chi/v5

Best Practices

  1. stdlib compatible — Chi handlers are http.HandlerFunc; use any net/http middleware without adapters
  2. Route groups — Use r.Route("/prefix", func(r chi.Router) {...}) for scoped middleware and routes
  3. Context middleware — Load resources in middleware, share via context.WithValue; DRY across sub-routes
  4. URL params — Use chi.URLParam(r, "id") to extract route parameters; type-safe, explicit
  5. Middleware ordering — Logger first, Recoverer second; auth before route-specific middleware
  6. Sub-routers — Mount independent routers: r.Mount("/admin", adminRouter()); clean separation
  7. Timeouts — Use middleware.Timeout to prevent slow handlers from blocking; returns 504 on timeout
  8. No magic — Chi doesn't do dependency injection or auto-binding; explicit is better than implicit in Go

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • 提供 Chi 路由器的详细使用指南,涵盖路由、中间件、上下文管理等核心功能
  • 内容完整,实用性强,适用于 Go 后端开发者构建 HTTP 服务
Trigger Precision90/100

Highlights

  • description 清晰描述了 Chi 路由器的核心功能和使用场景
  • 触发词精准且覆盖合理,边界清晰
Structure and Standards90/100

Highlights

  • 文档结构清晰,包含多个实用章节和完整代码示例
  • frontmatter 完整,符合规范
Execution Reliability85/100

Highlights

  • 提供的 Go 代码示例语法正确,工具来源明确
  • 参数使用合理,无明显执行漏洞
Evidence Verifiability (mean of the first four)88/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • app.example.com

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.