From dd794625ddb937557295fa006f9222753ebc6dd1 Mon Sep 17 00:00:00 2001 From: Leonard Gram Date: Tue, 17 Sep 2019 19:28:35 +0200 Subject: [PATCH] API: adds redirect helper to simplify http redirects (#19180) --- pkg/api/common.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/api/common.go b/pkg/api/common.go index 7973c72c8fa80..74bf42de7a810 100644 --- a/pkg/api/common.go +++ b/pkg/api/common.go @@ -135,3 +135,15 @@ func Respond(status int, body interface{}) *NormalResponse { header: make(http.Header), } } + +type RedirectResponse struct { + location string +} + +func (r *RedirectResponse) WriteTo(ctx *m.ReqContext) { + ctx.Redirect(r.location) +} + +func Redirect(location string) *RedirectResponse { + return &RedirectResponse{location: location} +}