Skip to content
/ httpsrv Public

Lightweight, Modular, High Performance MVC web framework for Golang

License

Notifications You must be signed in to change notification settings

hooto/httpsrv

Repository files navigation

httpsrv

httpsrv is a lightweight, modular, high-performance MVC web framework designed for Go, suitable for developing various internet-facing APIs and web applications.

Language: English | 中文

Features

  • 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

Documentation

Installation

go get -u github.com/hooto/httpsrv

Quick Start

Create 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.go

Visit:

curl http://localhost:8080/hello/world/

Output:

hello world

Project Structure

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

Recommended Dependencies

httpsrv keeps the core concise. Here are some recommended third-party libraries:

Database

Utility Libraries

More Go ecosystem libraries: awesome-go

System Requirements

  • Go Version: 1.22 or higher
  • Recommended Systems: Linux, Unix, or macOS (Windows not tested for compatibility)

Core Components

  • 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

Extension Components

  • log - Logging extension
  • data-rdb - Relational database extension
  • data-kv - Key-Value database extension
  • flag - Command line argument extension

Reference Projects

httpsrv has referenced the following projects in architecture design and some code implementations. Special thanks!

License

Apache License 2.0

About

Lightweight, Modular, High Performance MVC web framework for Golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages