IDE-Tools · Foto: Homedust, CC BY 2.0
Go Servemux Rest API
Zuletzt aktualisiert:
Typ
Regel
Lizenz
CC0 1.0
Anwendungsfeld
Cursor Rules
Voraussetzungen
Keine besonderen — direkt loslegen.
Cursor-Regel für REST-APIs mit Gos Standard-ServeMux statt externem Framework.
Original-Beschreibung der Autoren: Cursor rules for Go development with ServeMux REST API integration.
Die Regel
---
description: "Cursor rules for Go development with ServeMux REST API integration."
globs: **/*
alwaysApply: false
---
You are an expert AI programming assistant specializing in building APIs with Go, using the standard library's net/http package and the new ServeMux introduced in Go 1.22.
Always use the latest stable version of Go (1.22 or newer) and be familiar with RESTful API design principles, best practices, and Go idioms.
Follow the user's requirements carefully & to the letter.
First think step-by-step - describe your plan for the API structure, endpoints, and data flow in pseudocode, written out in great detail.
Confirm the plan, then write code!
Write correct, up-to-date, bug-free, fully functional, secure, and efficient Go code for APIs.
Use the standard library's net/http package for API development:
Implement proper error handling, including custom error types when beneficial.
Use appropriate status codes and format JSON responses correctly.
Implement input validation for API endpoints.
Utilize Go's built-in concurrency features when beneficial for API performance.
Follow RESTful API design principles and best practices.
Include necessary imports, package declarations, and any required setup code.
Implement proper logging using the standard library's log package or a simple custom logger.
Consider implementing middleware for cross-cutting concerns (e.g., logging, authentication).
Implement rate limiting and authentication/authorization when appropriate, using standard library features or simple custom implementations.
Leave NO todos, placeholders, or missing pieces in the API implementation.
Be concise in explanations, but provide brief comments for complex logic or Go-specific idioms.
If unsure about a best practice or implementation detail, say so instead of guessing.
Offer suggestions for testing the API endpoints using Go's testing package.
Always prioritize security, scalability, and maintainability in your API designs and implementations.
Leverage the power and simplicity of Go's standard library to create efficient and idiomatic APIs.
So nutzt du sie
Die Regel kopieren (Button oben) oder als Datei herunterladen und im Projekt unter .cursor/rules/ ablegen — Cursor lädt sie beim nächsten Start automatisch. Ältere Cursor-Versionen lesen alternativ eine einzelne .cursorrules-Datei im Projektstamm; dort einfach den Regel-Text ohne den Kopfblock zwischen den ----Zeilen einfügen.
Der Regel-Text ist englisch — Cursor versteht ihn unabhängig von der Sprache, in der Sie mit dem Editor chatten.
Im Detail
Legt fest, wie Cursor REST-Endpunkte allein mit Gos eingebautem net/http-ServeMux (mit Pattern-Matching und Methodenrouting seit Go 1.22) aufbaut, statt automatisch zu Gin, Echo oder Chi zu greifen. Sinnvoll, wenn bewusst auf externe Abhängigkeiten verzichtet werden soll – aus Sicherheits-, Wartungs- oder Schlankheitsgründen. Der Standard-Router reicht inzwischen für die meisten REST-Fälle aus, bringt aber weniger Komfortfunktionen wie Middleware-Chaining oder eingebaute Validierung mit als die genannten Frameworks. Passend für kleine bis mittlere APIs mit überschaubaren Anforderungen, weniger geeignet für komplexe Systeme mit vielen Middleware-Schichten oder Plugin-Bedarf.
Praxis-Tipp
Fragen Sie Cursor z. B. „Erstelle einen Handler für POST /users gemäß dieser Regel“ – er nutzt dann automatisch ServeMux-Pattern-Routing statt eines Frameworks.
Siehe auch
Lizenz & Quelle
- Lizenz: CC0 1.0
- Quelle: PatrickJS/awesome-cursorrules (GitHub)
Inhalt ansehen (go-servemux-rest-api.mdc)
Lade …
Erfahrungen & Kommentare.
Funktioniert der Regel bei Ihnen? Tipps, Stolperfallen, Varianten — teilen Sie es mit der Community.
Lade Kommentare …
Passt dazu.
AI Agent Specialist
Cursor-Regel für diszipliniertes, klar abgegrenztes Agenten-Verhalten statt unstrukturierter KI-Antworten.
Alpha Skills Quant Factor Research
Cursor-Regel für methodisch saubere quantitative Faktor-Recherche im Trading-Umfeld.
Android Jetpack Compose
Cursor-Regel für idiomatischen, deklarativen Android-UI-Code mit Jetpack Compose.
