Live data from Hacker News

Playing with Go: Embarrassingly Parallel Scripts

collectiveidea.com

51–53 of 53 posts

Re: Playing with Go: Embarrassingly Parallel Scripts

#51

Earlier quoted context omitted.

I know zero Go (it's a little far down on the to-learn list), and maybe he edited it, but I went back and read the GP's code and didn't see anything that looked like ignoring errors. Is it the two ", _" things?

So for this line of code: file_in, _ := ioutil.ReadFile("domains.txt") It says call ReadFile. In go a function can return multiple values. ReadFile returns an byte array and an error value. Normally you'd check to see if err is nil, if it is then no error happened. If it isn't you can check it out for information about the error and handle it. A unique feature about go is that declaring a variable and never using it…

> A unique feature about go is that declaring a variable and never using it is an error and not a warning. Actually there aren't even compiler warnings. Either it is right or wrong.

Ahhh. Nice. That sounds like a feature I could get behind, too. Thank you.

Re: Playing with Go: Embarrassingly Parallel Scripts

#52
post #2

Yes, Go does make writing stuff like that nice, but I think the actual code given is pretty heavyweight. This does the same thing: package main import ( "fmt" "net" "io/ioutil" "strings" ) func main() { file_in, _ := ioutil.ReadFile("domains.txt") domain_list := string(file_in) done := make(chan bool) count := 0 for _, domain := range strings.Split(strings.TrimSpace(domain_list), "\n") { go func(d string) { ipAddress…

I know it's about Go, but bash is awesome for stuff like this: while read line; do host $line | head -n1 | awk '{print $1 " -> " $4}' & done

You don't need to spawn N awks,

   " $4}'

Re: Playing with Go: Embarrassingly Parallel Scripts

#53
post #26

Earlier quoted context omitted.

Until last week I didn't know that xargs could invoke commands in parallel. xargs -n1 -P8 dig A hosts-matched.txt

So what's the difference between xargs and parallel? I thought the point of parallel was that it was xargs with the addition of running things in parallel. But if xargs can do that already, is there any reason to use one over the other?

xargs is already in your path.
Post reply on HN