Kaynağa Gözat

API: adds redirect helper to simplify http redirects (#19180)

Leonard Gram 6 yıl önce
ebeveyn
işleme
dd794625dd
1 değiştirilmiş dosya ile 12 ekleme ve 0 silme
  1. 12 0
      pkg/api/common.go

+ 12 - 0
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}
+}