httpsrv is a lightweight, modular, high-performance MVC web framework designed for Go, suitable for developing various internet-facing APIs and web applications.
- Modular Architecture - Business code organized through modules, ideal for enterprise-level complex application development
- Lightweight & Concise - Core code is concise (~3000 lines) with stable and reliable interfaces, easy for long-term maintenance
- High Performance - Low memory footprint, high concurrency stability, QPS can reach 20000+ on 2-core instances from mainstream cloud providers
- MVC Pattern - Supports standard MVC architecture with clear code structure
- Template Engine - Built-in template engine supporting flexible view rendering
- Internationalization - Built-in i18n support for multiple languages
- Middleware - Supports request filters and interceptors
- Session Management - Built-in session management functionality
go get -u github.com/hooto/httpsrvCreate a simple Hello World application:
package main
import (
"github.com/hooto/httpsrv"
)
// Define a controller
type Hello struct {
*httpsrv.Controller
}
// Define an Action
func (c Hello) WorldAction() {
c.RenderString("hello world")
}
// Create module
func NewModule() httpsrv.Module {
module := httpsrv.NewModule("demo")
module.ControllerRegister(new(Hello))
return module
}
func main() {
// Register module to global service
httpsrv.GlobalService.ModuleRegister("/", NewModule())
// Set port
httpsrv.GlobalService.Config.HttpPort = 8080
// Start service
httpsrv.GlobalService.Start()
}Run:
go run main.goVisit:
curl http://localhost:8080/hello/world/Output:
hello world
Recommended directory structure:
├─ bin/ # Compiled executables
├─ etc/ # Configuration files
├─ config/ # Configuration parsing code
├─ cmd/
│ └─ server/
│ └─ main.go # Service entry point
├─ data/ # Database access layer
├─ websrv/ # Module directory
│ ├─ api-v1/ # API module
│ └─ frontend/ # Frontend module
│ └─ views/ # Template files
├─ webui/ # Static files
└─ var/ # Runtime data
Complete example project: httpsrv-demo
httpsrv keeps the core concise. Here are some recommended third-party libraries:
- mysqlgo - MySQL client
- pgsqlgo - PostgreSQL client
- redisgo - Redis client
- kvgo - Embedded Key-Value database
- hlog4g - Logging library
- hini4g - INI configuration file parsing
- hflag4g - Command line argument handling
- hlang4g - i18n internationalization
- hcaptcha4g - CAPTCHA generation
More Go ecosystem libraries: awesome-go
- Go Version: 1.22 or higher
- Recommended Systems: Linux, Unix, or macOS (Windows not tested for compatibility)
- Service - Service container and configuration management
- Config - Configuration file handling
- Module - Module management and routing
- Controller - Controller and request handling
- Template - Template rendering and views
- Router - Routing configuration and matching
- log - Logging extension
- data-rdb - Relational database extension
- data-kv - Key-Value database extension
- flag - Command line argument extension
httpsrv has referenced the following projects in architecture design and some code implementations. Special thanks!