Simple example:
func main() {
server := moon.Moon()
// Me API es su API
server.AddHeader("Access-Control-Allow-Origin", "*")
server.MakeRouter(
// Will call routeHandler1() func every time a GET on "/handler1" URI is caught
moon.Get("/handler1", routeHandler1),
// This will match any "/handler1/*" GET request and create a "param1" parameter
// in moon.Request.Matches containing the matched value by the {param1} pattern
moon.Get("/handler1/{param1}", routeHandler1bis),
)
moon.ServerRun(":8080", server)
}
- Define routes using Patterns and a HTTP method
- Not use Regexp for Route Pattern matching
- Give matched parts of the Route Pattern as well as any query strings inside the
moon.Request
func aHandler(r *moon.Request) ([]byte, int, error)
Take:
- a
*moon.Request
containing a simplified HTTP Request (Parts of the uri matched, query string & headers)
Return:
[]byte
containing the text responseint
, as the http status codeerror
, as an error, for logging purpose
See Moon's GoDoc for Documentation.
This project still lacks:
- Tests (ongoing)
- Benchs
Matching without using RegExp ?- Response Caching ?