refactored label generator script and README

This commit is contained in:
Alexander Pivkin 2025-10-08 11:53:15 +03:00
parent bff28673d3
commit cc6c71ce15
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,3 @@
module main
go 1.24.6

View File

@ -0,0 +1,46 @@
package main
import (
"fmt"
"io"
"log"
"net/http"
)
func errCheck(err error) {
if err != nil {
log.Fatalln("Error happened %v\n",err)
}
}
func responseSize(url string, out chan Page) {
fmt.Println("Getting ",url)
response,err := http.Get(url)
errCheck(err)
defer response.Body.Close()
body,err := io.ReadAll(response.Body)
errCheck(err)
out <- Page{URL: url, Size: len(body)}
}
type Page struct {
URL string
Size int
}
func main() {
size := make(chan Page)
urls :=[]string{"https://google.com","https://golang.org","https://golang.org/doc"}
for _,url := range urls {
go responseSize(url,size)
}
fmt.Println("--------")
for i:=0; i < len(urls);i++ {
page := <- size
fmt.Printf("%s: %d\n",page.URL,page.Size)
}
fmt.Println("End main()")
}