shad-go/urlfetch/main.go

27 lines
371 B
Go

//go:build !solution
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
)
func main() {
urls := os.Args[1:]
for _, url := range urls {
resp, err := http.Get(url)
if err != nil {
log.Panic("fetch:", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Panic("fetch:", err)
}
fmt.Printf("%s", body)
}
}