1654358400
Bxog is a simple and fast HTTP router for Go (HTTP request multiplexer).
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):
Detailed benchmark here
API
Methods:
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
Author: Claygod
Source Code: https://github.com/claygod/Bxog
License: View license
1654358400
Bxog is a simple and fast HTTP router for Go (HTTP request multiplexer).
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):
Detailed benchmark here
API
Methods:
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
Author: Claygod
Source Code: https://github.com/claygod/Bxog
License: View license
1599854400
Go announced Go 1.15 version on 11 Aug 2020. Highlighted updates and features include Substantial improvements to the Go linker, Improved allocation for small objects at high core counts, X.509 CommonName deprecation, GOPROXY supports skipping proxies that return errors, New embedded tzdata package, Several Core Library improvements and more.
As Go promise for maintaining backward compatibility. After upgrading to the latest Go 1.15 version, almost all existing Golang applications or programs continue to compile and run as older Golang version.
#go #golang #go 1.15 #go features #go improvement #go package #go new features
1654199640
You need to have at least go 1.11 installed on you local machine.
Install go route package with go get
go get -u github.com/goroute/route
Start your first server. Create main.go file and add:
package main
import (
"net/http"
"log"
"github.com/goroute/route"
)
type helloResponse struct {
Title string `json:"title"`
}
func main() {
mux := route.NewServeMux()
mux.Use(func(c route.Context, next route.HandlerFunc) error {
log.Println("Hello, Middleware!")
return next(c)
})
mux.GET("/", func(c route.Context) error {
return c.JSON(http.StatusOK, &helloResponse{Title:"Hello, JSON!"})
})
log.Fatal(http.ListenAndServe(":9000", mux))
}
Run it
go run main.go
See examples
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
Author: Goroute
Source Code: https://github.com/goroute/route
License: MIT license
1654207080
π gorouter
Go Server/API micro framework, HTTP request router, multiplexer, mux.
β gorouter git:(master) β go test -bench=. -cpu=4 -benchmem
test
goos: darwin
goarch: amd64
pkg: github.com/vardius/gorouter/v4
BenchmarkNetHTTP-4 65005786 17.9 ns/op 0 B/op 0 allocs/op
BenchmarkFastHTTP-4 69810878 16.5 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/vardius/gorouter/v4 3.808s
π Click here to see all benchmark results.
π HOW TO USE
π ABOUT
Contributors:
Want to contribute ? Feel free to send pull requests!
Have problems, bugs, feature ideas? We are using the github issue tracker to manage them.
For documentation (including examples), visit rafallorenz.com/gorouter
For GoDoc reference, visit pkg.go.dev
Author: Vardius
Source Code: https://github.com/vardius/gorouter
License: MIT license
1651097100
Request
HTTP Client for golang, Inspired by Javascript-axios Python-request. If you have experience about axios or requests, you will love it. No 3rd dependency.
go mod:
go get github.com/monaco-io/request
package main
import (
"github.com/monaco-io/request"
)
func main() {
var body = struct {
A string
B int
}{A: "A", B: 1}
var result interface{}
c := request.Client{
URL: "https://google.com",
Method: "POST",
Query: map[string]string{"hello": "world"},
JSON: body,
}
resp := c.Send().Scan(&result)
if !resp.OK(){
// handle error
log.Println(resp.Error())
}
// str := resp.String()
// bytes := resp.Bytes()
package main
import (
"github.com/monaco-io/request"
)
func main() {
c := request.Client{
URL: "https://google.com",
Method: "POST",
Query: map[string]string{"hello": "world"},
MultipartForm: MultipartForm{
Fields: map[string]string{"a": "1"},
Files: []string{"doc.txt"},
},
}
resp := c.Send().Scan(&result)
...
package main
import (
"github.com/monaco-io/request"
)
func main() {
var response interface{}
resp := request.
New().
POST("http://httpbin.org/post").
AddHeader(map[string]string{"Google": "google"}).
AddBasicAuth("google", "google").
AddURLEncodedForm(map[string]string{"data": "google"}).
Send().
Scan(&response)
...
package main
import (
"github.com/monaco-io/request"
"context"
)
func main() {
c := request.Client{
Context: context.Background(),
URL: "https://google.com",
Method: "POST",
BasicAuth: request.BasicAuth{
Username: "google",
Password: "google",
},
}
resp := c.Send()
...
package main
import (
"github.com/monaco-io/request"
"context"
)
func main() {
var response interface{}
resp := request.
NewWithContext(context.TODO()).
POST("http://httpbin.org/post").
AddHeader(map[string]string{"Google": "google"}).
AddBasicAuth("google", "google").
AddURLEncodedForm(map[string]string{"data": "google"}).
Send().
Scan(&response)
...
package main
import (
"github.com/monaco-io/request"
)
func main() {
c := request.Client{
URL: "https://google.com",
Method: "POST",
BasicAuth: request.BasicAuth{
Username: "google",
Password: "google",
},
}
resp := c.Send()
}
package main
import (
"github.com/monaco-io/request"
)
func main() {
c := request.Client{
URL: "https://google.com",
Method: "POST",
Timeout: time.Second*10,
}
}
package main
import (
"github.com/monaco-io/request"
)
func main() {
c := request.Client{
URL: "https://google.com",
CookiesMap: map[string]string{
"cookie_name": "cookie_value",
}
}
}
package main
import (
"github.com/monaco-io/request"
)
func main() {
c := request.Client{
URL: "https://google.com",
TLSConfig: &tls.Config{InsecureSkipVerify: true},
}
}
Author: Monaco-io
Source Code: https://github.com/monaco-io/request
License: MIT License