-
-
Save parzibyte/e4fb09ede89bedfae6e2e9a36794684a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enrutador.HandleFunc("/foto_producto", func(w http.ResponseWriter, r *http.Request) { | |
idsProductos, existenIdsProductos := r.URL.Query()["id"] | |
if !existenIdsProductos || len(idsProductos) < 0 { | |
responderHttpConError(errors.New("no hay id en la URL"), w, r) | |
return | |
} | |
idProducto := idsProductos[0] | |
pc := ProductosController{ | |
AjustesUsuario: AjustesDeUsuarioLogueado{ | |
httpResponseWriter: w, | |
httpRequest: r, | |
}, | |
} | |
idProductoEntero, err := strconv.Atoi(idProducto) | |
if err != nil { | |
responderHttpConError(err, w, r) | |
return | |
} | |
producto := pc.porRowid(idProductoEntero) | |
if producto.Foto != "" { | |
rutaImagen := filepath.Join(DirectorioArchivos, producto.Foto) | |
w.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(rutaImagen))) | |
http.ServeFile(w, r, rutaImagen) | |
return | |
} else { | |
w.WriteHeader(http.StatusNotFound) | |
} | |
}).Name("VerProductos").Methods(http.MethodGet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment