Example #1
0
File: http.go Project: dgdn/goutil
func SimpleHandle(fn func(*routing.HTTPSession) (interface{}, error)) routing.HandleFunc {
	return func(hs *routing.HTTPSession) routing.HResult {
		rst, err := fn(hs)
		if err != nil {
			log.E("err:%v", err.Error())
			return hs.MsgResE(1, err.Error())
		}
		return _common.MsgRes(hs, rst)
	}
}
Example #2
0
File: http.go Project: dgdn/goutil
func SimpleListHandle(fn func(*routing.HTTPSession) (interface{}, int64, error)) routing.HandleFunc {
	return func(hs *routing.HTTPSession) routing.HResult {
		list, total, err := fn(hs)
		if err != nil {
			log.E("err:%v", err.Error())
			return hs.MsgResE(1, err.Error())
		}
		return _common.MsgRes(hs, map[string]interface{}{
			"total": total,
			"list":  list,
		})
	}
}
Example #3
0
func wrapRedirectHandle(fn func(*routing.HTTPSession) []reflect.Value) routing.HandleFunc {
	return func(hs *routing.HTTPSession) routing.HResult {
		outs := fn(hs)
		if len(outs) != 2 {
			panic("redirect handle api return count should be 2")
		}
		if err, ok := outs[1].Interface().(error); ok && err != nil {
			log.E("err:%v", err.Error())
			return hs.MsgResE(1, err.Error())
		}
		hs.Redirect(outs[0].Interface().(string))
		return _common.MsgRes(hs, outs[0].Interface().(string))
	}
}