Skip to content

Repository files navigation

httpsrv

httpsrv is a lightweight, net/http-native web framework for Go. It offers a Fiber v3-style routing surface (App/Router/Ctx/Handler) implemented from scratch over the standard library.

Language: English | 中文

Features

  • net/http-native — the typical handler is func(Ctx) error; a stdlib http.Handler (e.g. http.HandlerFunc) is also accepted, so handlers interoperate directly with the Go ecosystem
  • Radix-tree routing — per-method trees, {param} and {*catchAll} path values, case-sensitive, static segments beat params beat catch-alls (order-independent)
  • Middleware & GroupsUse with fiber v3-style middleware (func(Ctx) error + c.Next()), global or prefix-scoped; Group(prefix) for prefix sharing
  • Static filesmiddleware/static exposes New(root, ...Config) returning an httpsrv.Handler: app.Get("/*", static.New("./public")) or app.Get("/*", static.New(".", static.Config{FS: embedFS})); directory or embedded filesystem
  • Template renderinghtml/template parsed once, Ctx.Render(name, bind, layouts...)
  • i18n (opt-in) — flat locale message store, AcceptLanguage middleware (BCP-47 via x/text)
  • Compression (opt-in)middleware/compress exposes New(config...) (gzip/brotli by Accept-Encoding, brotli preferred)
  • Graceful server — safe default timeouts, Shutdown(ctx)

Documentation

Full guide (English): doc/Quick Start · Routing · Groups · Middleware · Server · Static · Ctx & Handler · Render · i18n · Examples · Index

中文文档:doc/zh-CN/

Installation

go get -u github.com/hooto/httpsrv/v2

Quick Start

package main

import (
    "github.com/hooto/httpsrv/v2"
)

func main() {
    app := httpsrv.New()

    app.Get("/", func(c httpsrv.Ctx) error {
        return c.SendString("hello httpsrv")
    })

    app.Run(":8080")
}

Run and try it:

$ go run .
$ curl http://localhost:8080/
hello httpsrv

See examples/ for runnable programs (hello, i18n, groups/static/render).

Recommended Dependencies

httpsrv keeps the core concise. Some recommended third-party libraries:

Database

Utility Libraries

More Go ecosystem libraries: awesome-go

System Requirements

  • Go Version: 1.26 or higher
  • Recommended Systems: Linux, Unix, or macOS

Reference Projects

httpsrv's API surface (App/Router/Ctx/Handler) is inspired by Fiber v3 — a from-scratch implementation over net/http with no dependency on fiber.

License

Apache License 2.0

About

A blazing-fast, net/http-native Go web framework with radix-tree routing and an ergonomic Ctx/Handler API.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages