Bxog is a simple and fast HTTP router for Go (HTTP request multiplexer).

Related tags

Routers Bxog
Overview

Bxog is a simple and fast HTTP router for Go (HTTP request multiplexer).

API documentation Go Report Card Mentioned in Awesome Go

Usage

An example of using the multiplexer:

package main

import (
	"io"
	"net/http"

	bx "github.com/claygod/Bxog"
)

// Handlers
func IHandler(w http.ResponseWriter, req *http.Request, r *bx.Router) {
	io.WriteString(w, "Welcome to Bxog!")
}
func THandler(w http.ResponseWriter, req *http.Request, r *bx.Router) {
	params := r.Params(req, "/abc/:par")
	io.WriteString(w, "Params:\n")
	io.WriteString(w, " 'par' -> "+params["par"]+"\n")
}
func PHandler(w http.ResponseWriter, req *http.Request, r *bx.Router) {
	// Getting parameters from URL
	params := r.Params(req, "country")
	io.WriteString(w, "Country:\n")
	io.WriteString(w, " 'name' -> "+params["name"]+"\n")
	io.WriteString(w, " 'capital' -> "+params["city"]+"\n")
	io.WriteString(w, " 'valuta' -> "+params["money"]+"\n")
	// Creating an URL string
	io.WriteString(w, "Creating an URL from the current route (This is an example of creating an another URL):\n")
	io.WriteString(w, r.Create("country", map[string]string{"name": "Russia", "city": "Moscow", "money": "rouble"}))
}

// Main
func main() {
	m := bx.New()
	m.Add("/", IHandler)
	m.Add("/abc/:par", THandler)
	m.Add("/country/:name/capital/:city/valuta/:money", PHandler).
		Id("country"). // For a convinience you can indicate a short ID
		Method("GET")  // It is not necessary to indicate the GET method here as the GET method is used by default but this way is used to set an allowed method
	m.Test()
	m.Start(":9999")
}

Click URLs:

Settings

Necessary changes in the configuration of the multiplexer can be made in the configuration file config.go

Perfomance

Bxog is the fastest router, showing the speed of query processing. Its speed is comparable to the speed of the popular multiplexers: Bone, Httprouter, Gorilla, Zeus. The test is done on a computer with a i3-6320 3.7GHz processor and 8 GB RAM. In short (less time, the better):

  • Bxog 163 ns/op
  • HttpRouter 183 ns/op
  • Zeus 12302 ns/op
  • GorillaMux 14928 ns/op
  • GorillaPat 618 ns/op
  • Bone 47333 ns/op

Detailed benchmark here

API

Methods:

  • New - create a new multiplexer
  • Add - add a rule specifying the handler (the default method - GET, ID - as a string to this rule)
  • Start - start the server indicating the listening port
  • Params - extract parameters from URL
  • Create - generate URL of the available options
  • Shutdown - graceful stop the server
  • Stop - aggressive stop the server
  • Test - Start analogue (for testing only)

Example: m := bxog.New() m.Add("/", IHandler)

Named parameters

Arguments in the rules designated route colon. Example route: /abc/:param , where abc is a static section and :param - the dynamic section(argument).

Static files

The directory path to the file and its nickname as part of URL specified in the configuration file. This constants FILE_PREF and FILE_PATH

You might also like...
FastRouter is a fast, flexible HTTP router written in Go.

FastRouter FastRouter is a fast, flexible HTTP router written in Go. FastRouter contains some customizable options, such as TrailingSlashesPolicy, Pan

An extremely fast Go (golang) HTTP router that supports regular expression route matching. Comes with full support for building RESTful APIs.

ozzo-routing You may consider using go-rest-api to jumpstart your new RESTful applications with ozzo-routing. Description ozzo-routing is a Go package

Pure is a fast radix-tree based HTTP router
Pure is a fast radix-tree based HTTP router

package pure Pure is a fast radix-tree based HTTP router that sticks to the native implementations of Go's "net/http" package; in essence, keeping the

Simple Golang HTTP router
Simple Golang HTTP router

Bellt Simple Golang HTTP router Bellt Package implements a request router with the aim of managing controller actions based on fixed and parameterized

Simple router build on `net/http` supports custom middleWare.

XMUS-ROUTER Fast lightweight router build on net/http supports delegate and in url params. usage : Create new router using NewRouter() which need rout

Simple HTTP router for Go

ngamux Simple HTTP router for Go Installation Examples Todo Installation Run this command with correctly configured Go toolchain. go get github.com/ng

Simple http router.

Simple router based on tree structure. import ( "fmt" "log" "net/http" router "github.com/dmitruk-v/router/v1" ) func main() { ro := router.New

A powerful HTTP router and URL matcher for building Go web servers with 🦍

gorilla/mux https://www.gorillatoolkit.org/pkg/mux Package gorilla/mux implements a request router and dispatcher for matching incoming requests to th

lightweight, idiomatic and composable router for building Go HTTP services

chi is a lightweight, idiomatic and composable router for building Go HTTP services. It's especially good at helping you write large REST API services

Comments
  • add to awesome-go

    add to awesome-go

    Hi! I recommend that you add the library to the list of awesome-go. Then your project will be more popular and will have more contributors.

    You have some issues with golint and i also recommend check this out and fix it: https://goreportcard.com/report/github.com/claygod/Bxog#golint

    Thank you.

    opened by lk-geimfari 4
  • Publish more

    Publish more

    Почему только на хабре? Послушай коммент с хабра: все сущности, которые не нужны пользователю, сделай приватными. И публикуй в golang-nuts гугл группе, а также в golang сабреддите (reddit.com/r/golang)

    opened by funny-falcon 3
  • I think, I found an error in the example

    I think, I found an error in the example

    Hello.

    Thank you for this framework!

    When I start your example, I saw an error in the output. If I used a recommended url http://localhost/country/USA/capital/Washington/valuta/dollar, I did't see a Country in the last string and I saw "Moscow" in the capital place.

    I think, the code below is more right (and I replaced "valuta" to "currency"):

    package main

    import ( "io" "net/http"

    "github.com/claygod/bxog"
    

    )

    // Handlers func IHandler(w http.ResponseWriter, req *http.Request, r *bxog.Router) { io.WriteString(w, "Welcome to Bxog!") } func THandler(w http.ResponseWriter, req *http.Request, r *bxog.Router) { params := r.Params(req, "/abc/:para") io.WriteString(w, "Params:\n") io.WriteString(w, " 'par' -> "+params["par"]+"\n") } func PHandler(w http.ResponseWriter, req *http.Request, r *bxog.Router) { // Getting parameters from URL params := r.Params(req, "country") io.WriteString(w, "Country:\n") io.WriteString(w, " 'Name' -> "+params["name"]+"\n") io.WriteString(w, " 'Capital' -> "+params["city"]+"\n") io.WriteString(w, " 'Currency' -> "+params["money"]+"\n") // Creating a URL string io.WriteString(w, "Creating a URL from route:\n") io.WriteString(w, r.Create("country", params))

    }

    // Main func main() { m := bxog.New() m.Add("/", IHandler) m.Add("/abc/:par", THandler) m.Add("/country/:name/capital/:city/currency/:money", PHandler). Id("country"). // For ease indicate the short ID Method("GET") // GET method do not need to write here, it is used by default (this is an example) m.Start(":80") }

    opened by eremenkomax 1
Owner
Eduard
Eduard
Goji is a minimalistic and flexible HTTP request multiplexer for Go (golang)

Goji Goji is a HTTP request multiplexer, similar to net/http.ServeMux. It compares incoming requests to a list of registered Patterns, and dispatches

Goji 920 Dec 3, 2022
Lightning Fast HTTP Multiplexer

bone What is bone ? Bone is a lightweight and lightning fast HTTP Multiplexer for Golang. It support : URL Parameters REGEX Parameters Wildcard routes

Go-zoo 1.3k Nov 30, 2022
Go HTTP request router and web framework benchmark

Go HTTP Router Benchmark This benchmark suite aims to compare the performance of HTTP request routers for Go by implementing the routing structure of

Peter Kieltyka 27 Oct 4, 2022
A high performance HTTP request router that scales well

HttpRouter HttpRouter is a lightweight high performance HTTP request router (also called multiplexer or just mux for short) for Go. In contrast to the

Julien Schmidt 14.7k Dec 3, 2022
A high performance HTTP request router that scales well

HttpRouter HttpRouter is a lightweight high performance HTTP request router (also called multiplexer or just mux for short) for Go. In contrast to the

Julien Schmidt 13.5k Dec 9, 2021
xujiajun/gorouter is a simple and fast HTTP router for Go. It is easy to build RESTful APIs and your web framework.

gorouter xujiajun/gorouter is a simple and fast HTTP router for Go. It is easy to build RESTful APIs and your web framework. Motivation I wanted a sim

徐佳军 532 Oct 30, 2022
Fast, simple, and lightweight HTTP router for Golang

Sariaf Fast, simple and lightweight HTTP router for golang Install go get -u github.com/majidsajadi/sariaf Features Lightweight compatible with net/ht

defectivepixel 33 Aug 19, 2022
A high performance fasthttp request router that scales well

FastHttpRouter FastHttpRouter is forked from httprouter which is a lightweight high performance HTTP request router (also called multiplexer or just m

招牌疯子 871 Dec 1, 2022
:rotating_light: Is a lightweight, fast and extensible zero allocation HTTP router for Go used to create customizable frameworks.

LARS LARS is a fast radix-tree based, zero allocation, HTTP router for Go. view examples. If looking for a more pure Go solution, be sure to check out

Go Playgound 389 Nov 18, 2022
Fast and flexible HTTP router

treemux - fast and flexible HTTP router Basic example Debug logging CORS example Error handling Rate limiting using Redis Gzip compression OpenTelemet

Vladimir Mihailenco 507 Nov 29, 2022