Giter VIP home page Giter VIP logo

bxogv2's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.