Skip to main content الرئيسية المنشئون raphaelmansuy k8s-agent-stack go-api-gateway
go-api-gateway Build the AgentStack API Gateway in Go with Fiber/Chi. Use for creating REST API endpoints, HTTP handlers, middleware, request validation, and API routing. Triggers on "build API", "create endpoint", "HTTP handler", "REST API", "API gateway", "Fiber handler", "Chi router", or when implementing spec/004-api-design.md endpoints.
الانتقال إلى التثبيت سوق المهارات اكتشف واستكشف مهارات الذكاء الاصطناعي التي بناها المجتمع.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
نسخ Promptعرض تفاصيل Prompt يتجاوز الأمر المباشر Prompt المخصّص للمراجعة. افحص المصدر قبل تشغيله.
npx skills add https://github.com/raphaelmansuy/k8s-agent-stack --skill go-api-gatewayيبقى الأمر في سطر واحد. مرّر أفقيًا لمراجعته كاملًا قبل النسخ.
تفضّل نسخة محلية؟ نزّل الملفات المتاحة حاليًا لدى SkillsMP.
تحميل Zip جاري التحميل... Implement Agent-to-Agent (A2A) protocol for inter-agent communication. Use for agent discovery, agent cards, task delegation, and multi-agent orchestration. Triggers on "A2A protocol", "agent-to-agent", "agent discovery", "agent card", "multi-agent", "agent delegation", "agent communication", or when implementing spec/api/017-a2a-protocol.md.
agent-deployment-pipeline Implement CI/CD pipelines for AI agent deployment with evaluation gates. Use for GitHub Actions workflows, GitOps with ArgoCD, container image building, and automated testing. Triggers on "CI/CD", "pipeline", "GitHub Actions", "GitOps", "ArgoCD", "deployment automation", "continuous deployment", or when implementing safe agent release workflows.
Implement agent evaluation and safety gates using MLflow 3.x. Use for creating LLM-as-Judge scorers, evaluation datasets, quality gates, tracing, and continuous evaluation. Triggers on "evaluate agent", "MLflow scorer", "LLM judge", "safety evaluation", "quality gate", "agent testing", "hallucination detection", or when implementing spec/010-agent-evaluation.md requirements.
المهن ذات الصلة SOC
استنادا إلى تصنيف SOC المهني
name go-api-gateway description Build the AgentStack API Gateway in Go with Fiber/Chi. Use for creating REST API endpoints, HTTP handlers, middleware, request validation, and API routing. Triggers on "build API", "create endpoint", "HTTP handler", "REST API", "API gateway", "Fiber handler", "Chi router", or when implementing spec/004-api-design.md endpoints.
Go API Gateway
Overview
Build production-grade REST API endpoints for the AgentStack platform using Go with Fiber or Chi frameworks, following the specifications in /spec/004-api-design.md.
Project Structure
cmd/api/main.go # Entry point
internal/api/
├── handlers/ # HTTP handlers by domain
│ ├── agents.go
│ ├── chat.go
│ ├── deployments.go
│ └── health.go
├── middleware/ # Cross-cutting concerns
│ ├── auth.go
│ ├── logging.go
│ ├── ratelimit.go
│ └── tracing.go
├── routes/ # Route definitions
│ └── router.go
├── dto/ # Request/Response DTOs
│ └── agents.go
└── server.go # Server configuration
Core Workflow
Step 1: Define DTOs
Create request/response structures with validation tags:
package dto
import "time"
type CreateAgentRequest struct {
Name string `json:"name" validate:"required,min=3,max=64"`
Framework string `json:"framework" validate:"required,oneof=google-adk langchain crewai"`
Config AgentConfig `json:"config" validate:"required"`
AutoDeploy bool
}
AgentConfig {
Model
SystemPrompt
Tools []
}
AgentResponse {
ID
Name
Status
URLs AgentURLs
CreatedAt time.Time
}
AgentURLs {
Chat
}
`json:"auto_deploy"`
type
struct
string
`json:"model" validate:"required"`
string
`json:"system_prompt"`
string
`json:"tools"`
type
struct
string
`json:"id"`
string
`json:"name"`
string
`json:"status"`
`json:"urls,omitempty"`
`json:"created_at"`
type
struct
string
`json:"chat,omitempty"`
Step 2: Create Handler
package handlers
import (
"github.com/gofiber/fiber/v2"
"github.com/raphaelmansuy/agentstack/internal/api/dto"
"github.com/raphaelmansuy/agentstack/internal/domain/agent"
)
type AgentHandler struct {
service *agent.Service
}
func NewAgentHandler (svc *agent.Service) *AgentHandler {
return &AgentHandler{service: svc}
}
func (h *AgentHandler) CreateAgent(c *fiber.Ctx) error {
var req dto.CreateAgentRequest
if err := c.BodyParser(&req); err != nil {
return fiber.NewError(fiber.StatusBadRequest, "Invalid request body" )
}
if err := validate.Struct(req); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(dto.ValidationError(err))
}
projectID := c.Locals("projectID" ).(string )
agt, err := h.service.Create(c.Context(), projectID, agent.CreateInput{
Name: req.Name,
Framework: req.Framework,
Config: req.Config,
AutoDeploy: req.AutoDeploy,
})
if err != nil {
return handleDomainError(c, err)
}
return c.Status(fiber.StatusCreated).JSON(toAgentResponse(agt))
}
func (h *AgentHandler) ListAgents(c *fiber.Ctx) error {
projectID := c.Locals("projectID" ).(string )
cursor := c.Query("cursor" )
limit := c.QueryInt("limit" , 20 )
agents, nextCursor, err := h.service.List(c.Context(), projectID, cursor, limit)
if err != nil {
return handleDomainError(c, err)
}
return c.JSON(dto.AgentListResponse{
Data: toAgentResponses(agents),
NextCursor: nextCursor,
})
}
Step 3: Register Routes
package routes
import (
"github.com/gofiber/fiber/v2"
"github.com/raphaelmansuy/agentstack/internal/api/handlers"
"github.com/raphaelmansuy/agentstack/internal/api/middleware"
)
func SetupRoutes (app *fiber.App, deps *Dependencies) {
app.Get("/health" , handlers.Health)
app.Get("/ready" , handlers.Ready)
v1 := app.Group("/v1" )
v1.Use(middleware.RequestID())
v1.Use(middleware.Logger())
v1.Use(middleware.Tracing())
v1.Use(middleware.Auth(deps.AuthService))
v1.Use(middleware.RateLimit(deps.RateLimiter))
agents := v1.Group("/agents" )
agentHandler := handlers.NewAgentHandler(deps.AgentService)
agents.Post("/" , agentHandler.CreateAgent)
agents.Get("/" , agentHandler.ListAgents)
agents.Get("/:agentId" , agentHandler.GetAgent)
agents.Patch("/:agentId" , agentHandler.UpdateAgent)
agents.Delete("/:agentId" , agentHandler.DeleteAgent)
agents.Post("/:agentId/chat" , agentHandler.Chat)
agents.Get("/:agentId/chat/stream" , agentHandler.ChatStream)
agents.Get("/:agentId/deployments" , agentHandler.ListDeployments)
agents.Post("/:agentId/deployments" , agentHandler.CreateDeployment)
}
Step 4: Implement Middleware See references/middleware-patterns.md for:
Authentication middleware
Rate limiting
Request tracing
Error handling
Step 5: Add SSE Streaming
func (h *AgentHandler) ChatStream(c *fiber.Ctx) error {
c.Set("Content-Type" , "text/event-stream" )
c.Set("Cache-Control" , "no-cache" )
c.Set("Connection" , "keep-alive" )
agentID := c.Params("agentId" )
c.Context().SetBodyStreamWriter(func (w *bufio.Writer) {
for event := range h.service.StreamChat(c.Context(), agentID) {
fmt.Fprintf(w, "event: %s\n" , event.Type)
fmt.Fprintf(w, "data: %s\n\n" , event.Data)
w.Flush()
}
})
return nil
}
Error Handling Follow RFC 7807 Problem Details:
type ErrorResponse struct {
Type string `json:"type"`
Title string `json:"title"`
Status int `json:"status"`
Detail string `json:"detail"`
Instance string `json:"instance,omitempty"`
TraceID string `json:"trace_id,omitempty"`
Errors []ValidationError `json:"errors,omitempty"`
}
func NewError (c *fiber.Ctx, status int , title, detail string ) error {
return c.Status(status).JSON(ErrorResponse{
Type: errorTypeURL(status),
Title: title,
Status: status,
Detail: detail,
Instance: c.Path(),
TraceID: c.Locals("traceID" ).(string ),
})
}
Validation Use go-playground/validator:
import "github.com/go-playground/validator/v10"
var validate = validator.New()
func init () {
validate.RegisterValidation("agent_name" , validateAgentName)
}
Testing
func TestCreateAgent (t *testing.T) {
app := fiber.New()
svc := mocks.NewAgentService(t)
handler := NewAgentHandler(svc)
app.Post("/v1/agents" , handler.CreateAgent)
req := httptest.NewRequest("POST" , "/v1/agents" , strings.NewReader(`{
"name": "test-agent",
"framework": "google-adk",
"config": {"model": "gpt-4"}
}` ))
req.Header.Set("Content-Type" , "application/json" )
req.Header.Set("X-Project-ID" , "prj_test123" )
resp, _ := app.Test(req)
assert.Equal(t, 201 , resp.StatusCode)
}
Resources
references/middleware-patterns.md - Auth, logging, rate limiting patterns
references/sse-streaming.md - Server-Sent Events implementation
assets/handler-template.go - Handler boilerplate template