Skip to content
forked from Eodomius/router

Router for Eodomius APIs and servers

License

Notifications You must be signed in to change notification settings

Smaug6739/router

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Router

A simple router written in Go for APIs and servers of Eodomius projects

Installation

go get github.com/eodomus/router

Usage

Create a router

You can create a new router with the New function :

var router = router.New()

Handle a request

You can handle a request with the Get, Post, Patch, Put, and Delete functions :

  • First parameter is the path of the request

  • Second parameter is the function to call when the request is received

    • First parameter is the responce
    • Second parameter is the request
    • Third parameter is a Result structure
  router.Get("/test/{id}", func(w http.ResponseWriter, r *http.Request, result *Result){
    w.Write([]byte("Get : Test ID : " + result.Params["id"]))
  })
  router.Post("/test", func(w http.ResponseWriter, r *http.Request, result *Result){
    w.Write([]byte("Post : Test"))
  })
  router.Patch("/test", func(w http.ResponseWriter, r *http.Request, result *Result){
    w.Write([]byte("Patch : Test"))
  })
  router.Put("/test", func(w http.ResponseWriter, r *http.Request, result *Result){
    w.Write([]byte("Put : Test"))
  })
  router.Delete("/test", func(w http.ResponseWriter, r *http.Request, result *Result){
    w.Write([]byte("Delete : Test"))
  })

Typedef

Result

Result is a structure that contains parameters.

type Result struct {
  Params map[string]string // [paramName]paramValue
}

About

Router for Eodomius APIs and servers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%