otiai10 / marmoset

The very minimum web toolkit, less than framework

Home Page:https://github.com/otiai10/marmoset-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

marmoset

Go codecov Go Report Card Maintainability GoDoc

less than "web framework", just make your code a bit DRY.

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
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<name>[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)
}

About

The very minimum web toolkit, less than framework

https://github.com/otiai10/marmoset-example

License:MIT License


Languages

Language:Go 100.0%