FAQs

How do I integrate with existing servers?

Every Macaron instance implements http.Handler, so it can easily be used to serve subtrees on existing Go servers. For example this is a working Macaron app for Google App Engine:
1
package hello
2
3
import (
4
"net/http"
5
6
"gopkg.in/macaron.v1"
7
)
8
9
func init() {
10
m := macaron.Classic()
11
m.Get("/", func() string {
12
return "Hello world!"
13
})
14
http.Handle("/", m)
15
}
Copied!

How do I change the port/host?

Macaron's Run function looks for the PORT and HOST environment variables and uses those. Otherwise Macaron will default to localhost:4000. To have more flexibility over port and host, use the http.ListenAndServe function instead.
1
m := macaron.Classic()
2
// ...
3
log.Fatal(http.ListenAndServe(":8080", m))
Copied!
Or following ways:
  • m.Run("0.0.0.0"), listen on 0.0.0.0:4000
  • m.Run(8080), listen on 0.0.0.0:8080
  • m.Run("0.0.0.0", 8080), listen on 0.0.0.0:8080

How do I graceful shutdown?

1
package main
2
3
import (
4
...
5
"net/http"
6
7
"gopkg.in/macaron.v1"
8
"gopkg.in/tylerb/graceful.v1"
9
)
10
11
func main() {
12
m := macaron.Classic()
13
14
...
15
16
mux := http.NewServeMux()
17
mux.Handle("/", m)
18
graceful.Run(":4000", 60*time.Second, mux)
19
}
Copied!

How do I pass data in request-level other than service inject?

There is a field called Data with type map[string]interface{} in *macaron.Context where you can store and retrieve any type of data. It comes with *macaron.Context so every request is independent.
See example here.

What's the idea behind this other than Martini?

  • Integrate frequently used middlewares and helper methods with less reflection.
  • Replace default router with faster multi-tree router.
  • Make it much easier to power Gogs project.
  • Make a deep source study against Martini.

Why Logo is a dragon?

Shouldn't it be some sort of dessert?
The transliteration of Macaron in Chinese is Maca Long, Long means dragon, so actually the Logo is a dragon whose name is Maca. Hah!

Live code reload?

Bra is the prefect fit for live reloading Macaron and other apps.
Last modified 2yr ago