Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/monkeydioude/moon
Tiny Go server runner with easy routing and simple handlers
https://github.com/monkeydioude/moon
go server
Last synced: 2 days ago
JSON representation
Tiny Go server runner with easy routing and simple handlers
- Host: GitHub
- URL: https://github.com/monkeydioude/moon
- Owner: monkeydioude
- Created: 2018-06-09T19:48:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-07T21:52:23.000Z (3 months ago)
- Last Synced: 2024-08-08T16:23:27.980Z (3 months ago)
- Topics: go, server
- Language: Go
- Homepage:
- Size: 3.23 MB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
## Moon is a wrapper for http.Handler, making it way way easier to declare and handles route
[![Build Status](https://travis-ci.org/monkeydioude/moon.svg?branch=master)](https://travis-ci.org/monkeydioude/moon)Simple example:
```golang
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)
}
```### What it does
- 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`### Handlers
```golang
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 response
- `int`, as the http status code
- `error`, as an error, for logging purpose### [Detailed example(s) available here](./examples)
See [Moon's GoDoc](https://godoc.org/github.com/monkeydioude/moon) for Documentation.
This project still lacks:
- Tests (ongoing)
- Benchs
- ~~Matching without using RegExp ?~~
- Response Caching ?