Files
2026-09-18 11:42:15 -04:00

47 lines
775 B
Go

package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
const url = "https://jsonplaceholder.typicode.com"
type todo struct {
ID int `json:id`
Title string `json:title`
Status bool `json: status`
}
func handler(w http.ResponseWriter, r *http.Request) {
const base = "https://jsonplaceholder."
}
func main() {
resp, err := http.Get(url + "/todos/1/")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
var item todo
err = json.Unmarshal(body, &item)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
fmt.Printf("%#v", item)
}
}