networking and shit

This commit is contained in:
2026-09-18 11:42:15 -04:00
parent 1bae4e44b0
commit d7c01f2f0e
7 changed files with 128 additions and 1 deletions
+3
View File
@@ -0,0 +1,3 @@
module zacksolutions.dev/client
go 1.27.1
+46
View File
@@ -0,0 +1,46 @@
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)
}
}