From golang-boost
Guides construction of Go HTTP API services using the xgodev/boost factory for labstack/echo v4, covering plugin setup, ordering, and graceful shutdown.
How this skill is triggered — by the user, by Claude, or both
Slash command
/golang-boost:boost-factory-echoThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
**REQUIRED BACKGROUND:**
REQUIRED BACKGROUND:
boost-start — boost.Start() first.boost-wrapper-log — request logger via context.boost-model-errors — handler errors are typed and routed by error_handler.main.gopackage main
import (
"context"
"os"
"os/signal"
"syscall"
"time"
"github.com/xgodev/boost"
echoserver "github.com/xgodev/boost/factory/contrib/labstack/echo/v4"
"github.com/xgodev/boost/factory/contrib/labstack/echo/v4/plugins/extra/error_handler"
logplugin "github.com/xgodev/boost/factory/contrib/labstack/echo/v4/plugins/local/wrapper/log"
restresponse "github.com/xgodev/boost/factory/contrib/labstack/echo/v4/plugins/local/model/restresponse"
recoverplugin "github.com/xgodev/boost/factory/contrib/labstack/echo/v4/plugins/native/recover"
"github.com/xgodev/boost/factory/contrib/labstack/echo/v4/plugins/native/requestid"
"github.com/xgodev/boost/wrapper/log"
)
func main() {
boost.Start()
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
srv, err := echoserver.NewServer(ctx,
recoverplugin.Register, // panics → 500, no process death
requestid.Register, // X-Request-ID propagation
logplugin.Register, // request access log via boost logger
restresponse.Register, // sets Type=REST so error_handler emits JSON
error_handler.Register, // model/errors → HTTP status mapping
)
if err != nil {
log.FromContext(ctx).WithError(err).Fatal("failed to build echo server")
}
srv.GET("/health", healthHandler)
srv.POST("/orders", orderHandler.Create)
go srv.Serve(ctx)
<-ctx.Done()
shutdownCtx, cancelShutdown := context.WithTimeout(context.Background(), 15*time.Second)
defer cancelShutdown()
srv.Shutdown(shutdownCtx)
}
| Plugin | Purpose | Skip when |
|---|---|---|
native/recover | Panic → 500 | Never |
native/requestid | X-Request-ID | Never |
local/wrapper/log | Access log via boost logger | Never |
local/model/restresponse | Sets Type=REST for error_handler JSON mode | Never (REST APIs) |
extra/error_handler | Maps errors to HTTP status + JSON envelope via model/errors.Classify | Never |
native/cors | Browser clients | Internal-only services |
native/gzip | Response compression | gRPC / streaming |
restresponse.Register MUST come before error_handler.Register. Reason: the error handler picks ErrorHandlerJSON only when the server has Type=REST set on it. Without restresponse first, you get ErrorHandlerString (text/plain) — production symptom: 4xx/5xx responses come back as "some error" text instead of the JSON envelope clients expect.
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
go srv.Serve(ctx) // blocking; goroutine so we can react to ctx.Done()
<-ctx.Done()
shutdownCtx, _ := context.WithTimeout(context.Background(), 15*time.Second)
srv.Shutdown(shutdownCtx) // bounded drain with FRESH ctx
Use a fresh context for Shutdown — passing the cancelled parent makes it return immediately.
The handler resolves status via model/errors.Classify. To make a non-boost
error return a specific status (or be ignored / treated as 200), register it at
boot — it works for HTTP and gRPC at once. See boost-model-errors
(Register/RegisterMatch/Ignore); don't add cases to the handler by hand.
| Red flag | Fix |
|---|---|
echo.New() directly | echoserver.NewServer(ctx, ...) |
error_handler.Register before restresponse.Register | Reorder |
srv.Serve(ctx) called inline (not in a goroutine) followed by <-ctx.Done() | Wrap Serve in a goroutine |
echo.NewHTTPError(...) in a handler | Return bootsterrors.<Type>(err, "...") (see boost-model-errors) |
Shutdown(ctx) reusing the cancelled parent context | Use a fresh context.WithTimeout |
npx claudepluginhub xgodev/boost --plugin golang-boostCreates, wraps, and matches typed errors (BadRequest, NotFound, Conflict, etc.) in Go services using github.com/xgodev/boost/model/errors. Covers Echo error_handler and function publisher deadletter middleware matching, and registering custom errors for HTTP/gRPC status codes.
Provides Go web server architecture with net/http 1.22+ routing, project structure patterns, graceful shutdown, and dependency injection. Use for building Go apps, layouts, and dependencies.
Provides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.