From fa0df5ba0a96d23f0e3d1253fc4487783698aa9b Mon Sep 17 00:00:00 2001 From: Ana Rodriguez Fernandez Date: Sun, 31 Dec 2023 13:35:56 +0100 Subject: [PATCH] reto #10 - go --- .../Reto #10 - LA API [Media]/go/anita-87.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Retos/Reto #10 - LA API [Media]/go/anita-87.go diff --git a/Retos/Reto #10 - LA API [Media]/go/anita-87.go b/Retos/Reto #10 - LA API [Media]/go/anita-87.go new file mode 100644 index 0000000000..c968109f94 --- /dev/null +++ b/Retos/Reto #10 - LA API [Media]/go/anita-87.go @@ -0,0 +1,24 @@ +package main + +import ( + "io" + "log" + "net/http" +) + +func main() { + c := http.Client{} + + resp, err := c.Get("https://uselessfacts.jsph.pl/api/v2/facts/random") + if err != nil { + log.Fatalf("Error: %v", err) + } + defer resp.Body.Close() + + data, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatalf("Error: %v", err) + } + + log.Printf("Response: %v", string(data)) +}