From 7e9f4867b0ca5d1256d6248a7023f68a18315aa3 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 16 Jun 2018 18:36:03 +0200 Subject: [PATCH] add redirection --- router.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/router.go b/router.go index 2585dbb..a9d4763 100644 --- a/router.go +++ b/router.go @@ -125,7 +125,20 @@ func (s *Server) route(res http.ResponseWriter, httpReq *http.Request) { responseBarebone := implement.NewResponse() response := callable(parameters, responseBarebone) - /* (2) Build JSON response */ + /* (2) Extract http headers */ + for k, v := range response.Dump() { + if k == "_REDIRECT_" { + redir, ok := v.(string) + if !ok { + continue + } + res.Header().Add("Location", redir) + res.WriteHeader(308) // permanent redirect + return + } + } + + /* (3) Build JSON response */ formattedResponse := response.Dump() formattedResponse["error"] = response.Err.Code formattedResponse["reason"] = response.Err.Reason