Configure Copilot for idiomatic Go backend development.
# GitHub Copilot Go Configuration
## Go Style
- Follow Go conventions
- Handle errors explicitly
- Use short variable names
- Document exported functions
## HTTP Handler
```go
func (s *Server) HandleGetUser(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
user, err := s.db.GetUser(r.Context(), id)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
http.Error(w, "User not found", http.StatusNotFound)
return
}
s.log.Error("failed to get user", "error", err)
http.Error(w, "Internal error", http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(user)
}
```
## Error Handling
```go
var ErrNotFound = errors.New("not found")
func (s *Service) GetUser(ctx context.Context, id string) (*User, error) {
user, err := s.repo.Find(ctx, id)
if err != nil {
return nil, fmt.Errorf("get user: %w", err)
}
return user, nil
}
```
## Testing
```go
func TestGetUser(t *testing.T) {
t.Run("returns user when found", func(t *testing.T) {
// Arrange
svc := NewService(mockRepo)
// Act
user, err := svc.GetUser(ctx, "123")
// Assert
require.NoError(t, err)
assert.Equal(t, "123", user.ID)
})
}
```Cursor rules for building high-performance APIs with FastAPI, including async patterns and Pydantic.
Cursor rules for Node.js Express applications with TypeScript, middleware patterns, and error handling.
Cursor rules for building robust API routes in Next.js with validation, error handling, and authentication.
Copilot
backend
AI coding rules customize how GitHub Copilot generates and refactors code for your project. Follow these steps to install GitHub Copilot Go Development.
.cursor/rules, for Windsurf use .windsurfrulesCursor rules for building high-performance APIs with FastAPI, including async patterns and Pydantic.
Cursor rules for Node.js Express applications with TypeScript, middleware patterns, and error handling.
Cursor rules for building robust API routes in Next.js with validation, error handling, and authentication.