main.go 394 B

123456789101112131415161718192021222324252627
  1. package main
  2. import (
  3. "fmt"
  4. "io"
  5. "log"
  6. "net/http"
  7. "github.com/tidwall/gjson"
  8. )
  9. func main() {
  10. resp, err := http.Get("http://dog-api.kinduff.com/api/facts?number=1")
  11. if err != nil {
  12. log.Fatal(err)
  13. }
  14. defer resp.Body.Close()
  15. data, err := io.ReadAll(resp.Body)
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19. value := gjson.GetBytes(data, "facts.0")
  20. fmt.Println("Fact about dogs:", value)
  21. }