github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/mainredirect/handler.go (about)

     1  package mainredirect
     2  
     3  import (
     4  	"net/http"
     5  	"strings"
     6  
     7  	"github.com/tedsuo/rata"
     8  )
     9  
    10  type Handler struct {
    11  	Routes rata.Routes
    12  	Route  string
    13  }
    14  
    15  func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    16  	params := rata.Params{
    17  		"team_name": "main",
    18  	}
    19  
    20  	for k, vs := range r.URL.Query() {
    21  		if strings.HasPrefix(k, ":") {
    22  			params[k[1:]] = vs[0]
    23  		}
    24  	}
    25  
    26  	path, err := h.Routes.CreatePathForRoute(h.Route, params)
    27  	if err != nil {
    28  		w.WriteHeader(http.StatusInternalServerError)
    29  		return
    30  	}
    31  
    32  	http.Redirect(w, r, path, http.StatusMovedPermanently)
    33  }