Comment

Comment by jgrahamc

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) {
        ipAddresses, _ := net.LookupIP(d)

        ip := ""
        if len(ipAddresses) > 0 {
          ip = ipAddresses[0].String()
        }

        fmt.Println("Mapping: ", d, "->", ip)
        done <- true
      }(domain)

      count++
    }

    for i := 0; i < count; i++ {
  	<- done
    }
  }
parent jgrahamc 14 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton