Skip to content

vardius/gorouter

Repository files navigation

gorouter

Build Status Go Report Card codecov FOSSA Status license

Go Server/API micro framework, HTTP request router, multiplexer, mux.

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.

HOW TO USE

  1. GoDoc
  2. Documentation
  3. Benchmarks
  4. Go Server/API boilerplate using best practices DDD CQRS ES

Basic example

package main

import (
    "fmt"
    "log"
    "net/http"
	
    "github.com/vardius/gorouter/v4"
    "github.com/vardius/gorouter/v4/context"
)

func index(w http.ResponseWriter, _ *http.Request) {
    if _, err := fmt.Fprint(w, "Welcome!\n"); err != nil {
        panic(err)
    }
}

func hello(w http.ResponseWriter, r *http.Request) {
    params, _ := context.Parameters(r.Context())
    if _, err := fmt.Fprintf(w, "hello, %s!\n", params.Value("name")); err != nil {
        panic(err)
    }
}

func main() {
    router := gorouter.New()
    router.GET("/", http.HandlerFunc(index))
    router.GET("/hello/{name}", http.HandlerFunc(hello))

    log.Fatal(http.ListenAndServe(":8080", router))
}
package main

import (
    "fmt"
    "log"

    "github.com/valyala/fasthttp"
    "github.com/vardius/gorouter/v4"
)

func index(_ *fasthttp.RequestCtx) {
    fmt.Print("Welcome!\n")
}

func hello(ctx *fasthttp.RequestCtx) {
    params := ctx.UserValue("params").(context.Params)
    fmt.Printf("Hello, %s!\n", params.Value("name"))
}

func main() {
    router := gorouter.NewFastHTTPRouter()
    router.GET("/", index)
    router.GET("/hello/{name}", hello)

    log.Fatal(fasthttp.ListenAndServe(":8080", router.HandleFastHTTP))
}

Advanced examples

License

This package is released under the MIT license. See the complete license in the package:

LICENSE

FOSSA Status

About

Go Server/API micro framework, HTTP request router, multiplexer, mux

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 8