refactored label generator script and README
This commit is contained in:
parent
5c56f1ff0b
commit
8f45d64598
BIN
headFirst/flag/flag
Executable file
BIN
headFirst/flag/flag
Executable file
Binary file not shown.
3
headFirst/flag/go.mod
Normal file
3
headFirst/flag/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module main
|
||||
|
||||
go 1.25.3
|
||||
15
headFirst/flag/main.go
Normal file
15
headFirst/flag/main.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var nFlag = flag.Int("n",1234,"this is test int flag")
|
||||
var sFlag = flag.String("s","lolkek","this is test string flag")
|
||||
flag.Parse()
|
||||
|
||||
fmt.Println(*nFlag)
|
||||
fmt.Println(*sFlag)
|
||||
}
|
||||
|
|
@ -63,5 +63,7 @@ func main() {
|
|||
|
||||
var e Test
|
||||
_ = json.Unmarshal(b,&e)
|
||||
fmt.Println(e)
|
||||
fmt.Printf("Output is %v",e)
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,45 +2,50 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"sync"
|
||||
// "time"
|
||||
)
|
||||
|
||||
func errCheck(err error) {
|
||||
if err != nil {
|
||||
log.Fatalln("Error happened %v\n",err)
|
||||
|
||||
// func a(name int, channel chan int, wg *sync.WaitGroup) {
|
||||
// defer wg.Done()
|
||||
// for i := 0; i < 3; i++ {
|
||||
// fmt.Printf("Number %d is sending\n",name)
|
||||
// channel <- name
|
||||
// }
|
||||
// fmt.Printf("Num %d is ended\n",name)
|
||||
// }
|
||||
func test(name int,channel chan []int, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
inter := []int{}
|
||||
for i := 0; i < 3; i++ {
|
||||
inter = append(inter, name)
|
||||
}
|
||||
channel <- inter
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
_list := []int{1,2,3,4,5}
|
||||
a_chan := make(chan []int)
|
||||
|
||||
for _,k := range _list {
|
||||
wg.Add(1)
|
||||
go test(k,a_chan, &wg)
|
||||
}
|
||||
fmt.Println("--------")
|
||||
for i:=0; i < len(urls);i++ {
|
||||
page := <- size
|
||||
fmt.Printf("%s: %d\n",page.URL,page.Size)
|
||||
|
||||
go func() {
|
||||
wg.Wait()
|
||||
close(a_chan)
|
||||
}()
|
||||
|
||||
// for i := range a_chan {
|
||||
// fmt.Println(i)
|
||||
// }
|
||||
for i := range a_chan {
|
||||
fmt.Println(i)
|
||||
}
|
||||
fmt.Println("End main()")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user