Nex is a lightweight, high-performance web framework for Go. Designed with simplicity and scalability in mind, Nex provides a robust set of features for building web applications and APIs.
- Features
- Installation
- Quick Start
- Middleware
- Routing
- Grouping Routes
- Error Handling
- Best Practices
- Contributing
- License
- Fast Routing: Efficient routing using a trie-based structure.
- Middleware Support: Easily extend functionality with middleware.
- Grouping Routes: Organize your routes with groups.
- Context: A comprehensive context for handlers, making it easier to manage request and response data.
- Error Handling: Built-in error handling mechanism.
- Session Management: Secure and efficient session management capabilities.
- Compression: Automatic response compression.
- Rate Limiting: Protect your application from abuse with rate limiting.
- CORS: Built-in support for Cross-Origin Resource Sharing.
- Cache Control: Efficiently manage cache headers and server-side caching.
- Content-Type Checking: Ensure that your endpoints receive the expected content types.
To install Nex, use go get
:
go get github.com/nex-gen-tech/nex
Here's a simple example to get you started:
package main
import (
"github.com/nex-gen-tech/nex"
"github.com/nex-gen-tech/nex/context"
)
func main() {
r := nex.NewRouter()
r.GET("/", func(c *context.Context) {
c.String(200, "Welcome to Nex!")
})
r.Run(":8080")
}
Nex supports middleware at both the global and group levels. Here's how you can use the built-in logging and recovery middleware:
r := nex.NewRouter()
r.Use(middleware.Logging(), middleware.Recovery())
// ... your routes here ...
Define routes easily with Nex:
r.GET("/users", listUsers)
r.POST("/users", createUser)
Organize your routes with groups:
api := r.NewGroup("/api")
api.GET("/users", listUsers)
api.POST("/users", createUser)
Nex provides a built-in mechanism for error handling:
r.SetErrorHandler(func(c *context.Context, err error) {
// Handle the error here
c.String(500, "Internal Server Error")
})
- Always check for errors and handle them gracefully.
- Use middleware to extend functionality and keep your code DRY.
- Organize your routes with groups, especially for larger applications.
- Monitor your application's performance and adjust rate limits, compression settings, etc., as needed.
We welcome contributions! Please see CONTRIBUTING.md for details on how to contribute.
Nex is licensed under the MIT License. See LICENSE for more information.