Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion hello/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,27 @@ package main

import (
"fmt"
"io"
"net/http"
)

const url = "http://services.explorecalifornia.org/json/tours.php"

func main() {
fmt.Println("Hello from Go!")
fmt.Println("Read a text file from the web, Network requests")
resp, err := http.Get(url)
if err != nil {
panic(err)
}
fmt.Printf("Response type %T\n", resp)
/* The response object has a public field simply called body
and the body will represent everything I need,
specifically the JSON packet.*/
defer resp.Body.Close()
bytes, err := io.ReadAll(resp.Body) //now ioutil it's just io i use it according to the course
if err != nil {
panic(err)
}
content := string(bytes)
fmt.Print(content)
}