package main import ( "flag" "io" "log" "net/http" "time" ) type Link struct { Href string Text string } func main() { // Logging configuration. log.SetFlags(log.LstdFlags | log.Lshortfile) // CLI flag configuration. rawURL := flag.String("url", "", "Web address of target HTML") timeoutSecs := flag.Int("timeout", 2, "Number of seconds after which to time out") if *rawURL == "" { log.Fatal("Missing -url") } // Configure the request. timeout := time.Duration(*timeoutSecs) * time.Second client := http.Client{ Timeout: timeout, } req, err := http.NewRequest(http.MethodGet, *rawURL, nil) if err != nil { log.Fatal(err) } // Perform the request. resp, err := client.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close() links, err := findLinks(resp.Body) if err != nil { log.Fatal(err) } _ = links } // findLinks consumes the given reader, scraping it of anchor // tags. Each anchor tag is "unmarshalled" into a [Link]. The // resulting slice of Links is returned, along with an error. func findLinks(_ io.Reader) ([]Link, error) { return nil, nil }