Go net/http ServeMux Best Practices .cursorrules prompt file
About .cursorrules prompt file
What you can build
Secure RESTful API Generator: A web application that allows developers to quickly generate secure RESTful APIs in Go, with built-in support for input validation, authentication, authorization, and rate limiting. It should use the standard library's
net/http
package, leverage ServeMux for routing, and include middleware for logging and error handling.Go Web Application Starter Kit: A scaffold tool that creates a ready-to-deploy Go web application template following best practices. It includes a modular structure with rate limiting, middleware support, logging, and authentication. The starter kit should use
taskfile.dev
for task automation and provide examples for declarative programming patterns.Go Microservice Framework: A microservice framework specifically for building scalable Go applications with a strong focus on security and maintainability. It should support service discovery, load balancing, and include gRPC alongside HTTP support. The framework should offer easy integration with existing monitoring and logging systems.
Input Validator for Go Web Apps: A library specifically for input validation in Go web applications that provides easy-to-use interfaces to ensure user inputs are sanitized before processing. The library should be easily integrable with the standard
net/http
package and ServeMux.Go Middleware Library: A comprehensive library of reusable middleware for common web application concerns like logging, caching, authentication, and error handling. The middleware should be simple to plug into any Go web server setup using ServeMux.
Concurrency-Optimized Web Server: A sample Go project that demonstrates the power of Go's concurrency features in building an efficient web server. The server should handle high loads efficiently, demonstrating the use of goroutines and channels in request processing.
Dynamic Configurator for Go Apps: A configuration management tool that allows Go applications to load configurations dynamically at runtime. It should support JSON, YAML formats, and environment variables, making use of dependency injection to ensure clean and maintainable code.
Rate Limiter Middleware for Go: A standalone Go package that developers can use to easily implement rate limiting in their web applications using Go's standard library features.
Idiomatic Go Code Formatter: An online tool that takes Go source code and reformats it according to idiomatic practices, providing suggestions for improvements in code style and structure based on the given guidelines.
Go Security Linter: A static analysis tool for Go applications that focuses on identifying and fixing security vulnerabilities, ensuring that code follows security best practices and guidelines provided in the prompt.
Benefits
- Leverage new ServeMux features in Go 1.22 for enhanced routing, including wildcard and regex support.
- Emphasize security, scalability, and maintainability with Go's standard library for efficient, idiomatic code.
- Implement task management with taskfile.dev, avoiding makefiles and traditional build scripts.
Synopsis
Developers building a secure, scalable Go web application will benefit from this prompt to create efficient, maintainable, idiomatic code with proper routing and method handling.
Overview of .cursorrules prompt
The .cursorrules file provides guidelines for Go developers to ensure best practices in coding, particularly for web application development. It emphasizes using Go's standard library, specifically the net/http package and ServeMux for routing, as well as leveraging Go's concurrency features. The file also advocates for robust error handling, input validation, and security measures such as rate limiting and authentication. Developers are advised to use dependency injection, avoid global variables, and prefer interfaces over concrete types. The file highlights the importance of structuring code with clear naming conventions and modularized functions for scalability and maintainability. Additionally, it suggests using taskfile.dev for task automation over makefiles.