FAQs
Or the variable arguments of the Run
method:
f.Run("localhost") // => localhost:2830
f.Run(8888) // => 0.0.0.0:8888
f.Run("localhost", 8888) // => localhost:8888
Alternatively, http.ListenAndServe
open in new window or can also be used to change the listen address:
How do I do graceful shutdown?
The package can be used to do graceful shutdown with the Flame instance:
package main
import (
"net/http"
"github.com/flamego/flamego"
"github.com/ory/graceful"
func main() {
f := flamego.New()
...
server := graceful.WithDefaults(
&http.Server{
Addr: "0.0.0.0:2830",
Handler: f,
},
)
// Handler error
}
}
Below is an example of integrating with the net/http
router for a single route "/user/info"
:
- Code
- Test
$ curl -i http://localhost:2830/user/info
The user is Joe
Example: Integrating with Macaron
Below is an example of integrating with the Macaron router for a single route "/user/info"
:
- Code
- Test
$ curl -i http://localhost:2830/user/info
The user is Joe
What is the difference between inject.Invoker
and inject.FastInvoker
?
The inject.Invoker
open in new window is the default way that the Flame instance uses to invoke a function through reflection.
Martini brought the brilliant idea of build a web framework with dependency injection in a magical experience. However, it has terrible performance and high memory usage. Some people are blaming the use of reflection for its slowness and memory footprint, but that is not fair by the way, most of people are using reflections every single day with marshalling and unmarshalling JSON in Go.
Macaron achieved the reasonable performance and much lower memory usage. Unfortunately, it was not a properly designed product, or let’s be honest, there was no design. The origin of Macaron was to support the rapid development of the project, thus almost all things were inherited from some other web frameworks at the time.
Absence of holistic architecture view and design principles have caused many bad decisions, including but not limited to:
- The
*macaron.Context
open in new window is very heavy, thus wasn’t a thing. - The choice of using the opening-only style (e.g.
:name
) for named parametersopen in new window has limited capability and extensibility of the routing syntax. - Being too opinionated in many aspects, a simple example is the existence of /
Config
open in new window that kinda kidnaps all users to import the package but not using it at 99% of the time. - The way to is a disaster.