gosourcemapper-guide
2
总安装量
2
周安装量
#64021
全站排名
安装命令
npx skills add https://github.com/chinmay-sawant/gosourcemap --skill gosourcemapper-guide
Agent 安装分布
amp
2
gemini-cli
2
github-copilot
2
codex
2
kimi-cli
2
opencode
2
Skill 文档
AI Assistant Guide: Go (Gin) & React Project
This document serves as a guideline for GitHub Copilot, Antigravity, and other AI coding assistants to ensure consistency, maintainability, and adherence to best practices within this codebase.
1. Tech Stack Overview
- Backend: Go (Golang) with Gin Web Framework.
- Frontend: React (Vite).
- Documentation: Markdown/Starlight (if applicable).
2. Backend (Go + Gin) Best Practices
Project Structure (Standard Go Layout)
We follow the standard project layout:
âââ cmd/
â âââ server/
â âââ main.go # Entry point. Initializes the app.
âââ internal/ # Private application code (not importable by other projects).
â âââ config/ # Configuration loading (e.g., env vars).
â âââ handlers/ # HTTP handlers (controllers).
â âââ models/ # Domain models and data structures.
â âââ repository/ # Database access layer.
â âââ middleware/ # Gin middleware (logging, auth, CORS).
â âââ router/ # Route definitions.
â âââ service/ # Business logic.
âââ pkg/ # Library code ok to use by external applications (if any).
âââ docs/ # Swagger/OpenAPI docs.
âââ go.mod
coding Guidelines
- Dependency Injection: Avoid global state. Inject services into handlers, and repositories into services.
- Example: Define a
Handlerstruct that holds references toServiceinterfaces.
- Example: Define a
- Error Handling:
- Use custom error types to distinguish between client errors (4xx) and server errors (5xx).
- Return errors up the stack; handle them centrally in the HTTP handler or a middleware.
- Check all errors.
- Gin Specifics:
- Use
gin.Contextonly in the Handler layer. Do not pass it down to services. - specific route groups (e.g.,
v1 := router.Group("/v1")). - Use Struct Tags for binding and validation (e.g.,
binding:"required").
- Use
- Configuration: Use a strong configuration pattern (e.g., loading from environment variables into a struct).
- Concurrency: Use Goroutines and Channels responsibly. Always handle context cancellation (
ctx.Done()).
Naming Conventions
- Interfaces: simple descriptors (e.g.,
Service,Repository) orersuffix (e.g.,Reader,Writer). - files: snake_case.go
- Variables: camelCase.
- Exported: PascalCase.
3. Frontend (React + Vite) Best Practices
- Component Structure: Functional components with Hooks.
- State Management: Use
useState/useReducerfor local state; Context API or external libraries (Zustand/Redux) for global state if complex. - Styling: Modular CSS or Tailwind (if configured). Avoid inline styles.
- Performance: Use
useMemoanduseCallbackjudiciously to prevent unnecessary re-renders.
4. Documentation
- Keep
docs/anddocumentation/updated. - Inline comments should explain why, not what.
- Exported functions must have Godoc comments.