func()

in og/viewog/og.go [91:118]


func (h *Handler) Redirect(w http.ResponseWriter, r *http.Request) error {
	ctx := r.Context()
	parts := strings.Split(r.URL.Path, "/")
	if len(parts) != 5 {
		return fmt.Errorf("Invalid URL: %s", r.URL.Path)
	}
	status, err := strconv.Atoi(parts[2])
	if err != nil || (status != 301 && status != 302) {
		return fmt.Errorf("Invalid status: %s", parts[2])
	}
	count, err := strconv.Atoi(parts[3])
	if err != nil {
		return fmt.Errorf("Invalid count: %s", parts[3])
	}
	context, err := rellenv.FromContext(ctx)
	if err != nil {
		return err
	}
	if count == 0 {
		http.Redirect(w, r, context.AbsoluteURL("/rog/"+parts[4]).String(), status)
	} else {
		count--
		url := context.AbsoluteURL(fmt.Sprintf(
			"/rog-redirect/%d/%d/%s", status, count, parts[4]))
		http.Redirect(w, r, url.String(), status)
	}
	return nil
}