db :=&MyDatabase{}m := macaron.Classic()m.Map(db) // Service will be available to all handlers as *MyDatabasem.Get("/", func(db *MyDatabase) {// Operations with db.})m.Run()
funcMyCustomLoggerHandler(ctx *macaron.Context) { logger :=&MyCustomLogger{ctx.Req} ctx.Map(logger) // mapped as *MyCustomLogger}funcmain() {//... m.Get("/", MyCustomLoggerHandler, func(logger *MyCustomLogger) {// Operations with logger. }) m.Get("/panic", func(logger *MyCustomLogger) {// This will panic because no logger service maps to this request. })//...}