Skip to content

Latest commit

 

History

History
85 lines (58 loc) · 1.97 KB

README.md

File metadata and controls

85 lines (58 loc) · 1.97 KB

R2

GitHub Actions codecov Go Report Card PkgGoDev

A minimalist HTTP request routing helper for Go.

The name "R2" stands for "Request Routing". That's all, R2 is just a capable little helper for HTTP request routing, not another fancy web framework that wraps net/http.

Features

  • Extremely easy to use
  • Router
    • Blazing fast
    • Based on the Radix Tree
    • Zero dynamic memory allocations
    • Sub-router support
  • Middleware
  • Zero third-party dependencies

Installation

Open your terminal and execute

$ go get github.com/aofei/r2

done.

The only requirement is the Go, at least v1.13.

Hello, 世界

Create a file named hello.go

package main

import (
	"fmt"
	"net/http"

	"github.com/aofei/r2"
)

func main() {
	r := &r2.Router{}
	r.Handle("", "/hello/:name", http.HandlerFunc(handleHello))
	http.ListenAndServe("localhost:8080", r)
}

func handleHello(rw http.ResponseWriter, req *http.Request) {
	fmt.Fprintf(rw, "Hello, %s\n", r2.PathParams(req).Get("name"))
}

and run it

$ go run hello.go

then visit http://localhost:8080/hello/世界.

Community

If you want to discuss R2, or ask questions about it, simply post questions or ideas here.

Contributing

If you want to help build R2, simply follow this to send pull requests here.

License

This project is licensed under the MIT License.

License can be found here.