Skip to content
mcustielPublic

About

Stupid simple go http requests router for my demo projects

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

Repository files navigation

gorro

Stupid simple go http requests router for my demo projects. Allows to configure routes using regular expressions.

Usage example

import (
  "github.com/mcustiel/gorro"
  "net/http"
  "fmt"
)

func getHandler(w http.ResponseWriter, r *gorro.Request) error {
  fmt.Fprintf(w, "GET Hello %s", r.NamedParams["name"])
  return nil
}

func postHandler(w http.ResponseWriter, r *gorro.Request) error {
  fmt.Fprint(w, "POST Hello World")
  return nil
}



func main() {
  rtr := gorro.NewRouter()

  err := rtr.Register(`/hello/(?P<name>[a-z]+)`, gorro.HandlersMap{
    http.MethodPost: postHandler,
    http.MethodGet:  getHandler})

  if err != nil {
    panic(err)
  }

  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    rtr.Route(w, r)
  })

  http.ListenAndServe(":8080", nil)
}

About

Stupid simple go http requests router for my demo projects

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages