Skip to content
/ gorro Public

Stupid simple go http requests router for my demo projects

License

Notifications You must be signed in to change notification settings

mcustiel/gorro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages