func (red *Redirecionador) ServeHTTP(w http.ResponseWriter, r *http.Request) { caminho := strings.Split(r.URL.Path, "/") id := caminho[len(caminho)-1] if url := url.Buscar(id); url != nil { http.Redirect(w, r, url.Destino, http.StatusMovedPermanently) red.stats <- id } else { http.NotFound(w, r) } }
func Visualizador(w http.ResponseWriter, r *http.Request) { caminho := strings.Split(r.URL.Path, "/") id := caminho[len(caminho)-1] if url := url.Buscar(id); url != nil { json, err := json.Marshal(url.Stats()) if err != nil { w.WriteHeader(http.StatusInternalServerError) return } responderComJson(w, string(json)) } else { http.NotFound(w, r) } }