main.go
, and type following code:go run main.go
, you should see a log message is printed to the console:main.go
and do some extended exercises.go run main.go
again, you’ll see string the request path is: /
is on your screen./
. We don’t use anonymous function anymore, but a named function called myHandler
. Notice that there is no parentheses after function name when we register route because we do not call it at that point.myHandler
accepts one argument with type *macaron.Context
and returns a string. You may notice that we didn’t tell Macaron what arguments should pass to myHandler
when we register routes, and if you look at the m.Get
method, you will see Macaron sees all handlers(macaron.Handler
) as type interface{}
. So how does Macaron know?*macaron.Context
is one of the default injected services, so you can use it directly. Don’t worry about how to inject your own services, it’s just not the time to tell you yet.http.ListenAndServe
, which shows any Macaron Instance is fully compatible with Go standard library.