https://github.com/otiai10/marmoset
The very minimum web toolkit, less than framework
https://github.com/otiai10/marmoset
go http-router http-server
Last synced: about 1 year ago
JSON representation
The very minimum web toolkit, less than framework
- Host: GitHub
- URL: https://github.com/otiai10/marmoset
- Owner: otiai10
- License: mit
- Created: 2016-01-20T06:40:46.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2024-10-04T23:13:15.000Z (over 1 year ago)
- Last Synced: 2024-11-01T10:42:20.671Z (over 1 year ago)
- Topics: go, http-router, http-server
- Language: Go
- Homepage: https://github.com/otiai10/marmoset-example
- Size: 59.6 KB
- Stars: 11
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
marmoset
========
[](https://github.com/otiai10/marmoset/actions/workflows/go.yml)
[](https://codecov.io/gh/otiai10/marmoset)
[](https://goreportcard.com/report/github.com/otiai10/marmoset)
[](https://codeclimate.com/github/otiai10/marmoset/maintainability)
[](https://godoc.org/github.com/otiai10/marmoset)
less than "web framework", just make your code a bit DRY.
```go
func main() {
router := marmoset.NewRouter()
router.GET("/hello", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello!"))
})
http.ListenAndServe(":8080", router)
}
```
# Features
- Path parameters
- Static directory
- Request filters
- Request-Context accessor, if you want
```go
func main() {
router := marmoset.NewRouter()
router.GET("/foo", your.FooHttpHandlerFunc)
router.POST("/bar", your.BarHttpHandlerFunc)
// Path parameters available with regex like declaration
router.GET("/users/(?P[a-zA-Z0-9]+)/hello", func(w http.ResponseWriter, r *http.Request) {
marmoset.Render(w).HTML("hello", map[string]string{
// Path parameters can be accessed by req.FromValue()
"message": fmt.Printf("Hello, %s!", r.FormValue("name")),
})
})
// Set static file path
router.Static("/public", "/your/assets/path")
// Last added filter will be called first.
server := marmoset.NewFilter(router).
Add(&your.Filter{}).
Add(&your.AnotherFilter{}).
Add(&marmoset.ContextFilter{}). // if you want
Server()
http.ListenAndServe(":8080", server)
}
```