Skip to content
/ BxogV2 Public

Based on the Bxog, but a slower router

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE.md
Unknown
LICENSE.txt
Notifications You must be signed in to change notification settings

claygod/BxogV2

Repository files navigation

Bxog v.2

Based on the Bxog, more comfortable because of the context of use, but at a slower router

API documentation Go Report Card

Usage

An example of using the multiplexer:

package main

import (
	bx "github.com/claygod/BxogV2"
	"io"
	"net/http"
)

// Handlers
func IHandler(w http.ResponseWriter, req *http.Request) {
	io.WriteString(w, "Welcome to Bxog!")
}
func THandler(w http.ResponseWriter, req *http.Request) {
	io.WriteString(w, "Params:\n")
	if x := (req.Context().Value("par")).(string); x != "" {
		io.WriteString(w, " 'par' -> "+x+"\n")
	}
}
func PHandler(w http.ResponseWriter, req *http.Request) {
	// Getting parameters
	io.WriteString(w, "Country:\n")
	io.WriteString(w, " 'name' -> "+(req.Context().Value("name")).(string)+"\n")
	io.WriteString(w, " 'capital' -> "+(req.Context().Value("city")).(string)+"\n")
	io.WriteString(w, " 'valuta' -> "+(req.Context().Value("money")).(string)+"\n")

}

// 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 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")
}

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. Detailed benchmark here. In short (less time, the better):

  • Bxog 330 ns/op
  • HttpRouter 395 ns/op
  • Zeus 23772 ns/op
  • GorillaMux 30223 ns/op
  • GorillaPat 1253 ns/op
  • Bone 63656 ns/op

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
  • 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). The parameters are transmitted via context

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

About

Based on the Bxog, but a slower router

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE.md
Unknown
LICENSE.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages