Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 23, 2022 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/d567150c50c8c85bf513e02b3026152f to your computer and use it in GitHub Desktop.
Save parzibyte/d567150c50c8c85bf513e02b3026152f to your computer and use it in GitHub Desktop.
func obtenerDetallesGist() (error, string, string) {
clienteHttp := &http.Client{}
peticion, err := http.NewRequest("GET", GistControlador, nil)
if err != nil {
return err, "", ""
}
respuesta, err := clienteHttp.Do(peticion)
if err != nil {
return err, "", ""
}
defer respuesta.Body.Close()
cuerpoRespuesta, err := ioutil.ReadAll(respuesta.Body)
if err != nil {
return err, "", ""
}
respuestaString := string(cuerpoRespuesta)
if respuesta.StatusCode != http.StatusOK {
return fmt.Errorf("status code no fue OK, fue %v", respuesta.StatusCode), "", ""
}
respuestaArreglo := strings.Split(respuestaString, ",")
if len(respuestaArreglo) != 2 {
return fmt.Errorf("se esperaban 2 valores separados por coma (,), pero se encontraron: %d", len(respuestaArreglo)), "", ""
}
rutaImagen, fecha := respuestaArreglo[0], respuestaArreglo[1]
return nil, rutaImagen, fecha
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment