Example #1
0
// Performs validation and combines errors from validation
// with errors from deserialization, then maps both the
// resulting struct and the errors to the context.
func validateAndMap(obj reflect.Value, ctx *macaron.Context, errors *Errors, ifacePtr ...interface{}) {
	ctx.Invoke(Validate(obj.Interface()))
	errors.Combine(getErrors(ctx))
	ctx.Map(*errors)
	ctx.Map(obj.Elem().Interface())
	if len(ifacePtr) > 0 {
		ctx.MapTo(obj.Elem().Interface(), ifacePtr[0])
	}
}
func myLogger(ctx *macaron.Context) {
	// 该服务的映射只会对当前请求的后续处理器有效
	ctx.MapTo(logger, (*Logger)(nil))
}