github.com/mattn/anko@v0.1.10/_example/scripts/socket.ank (about)

     1  #!anko
     2  
     3  var os, net, url, ioutil = import("os"), import("net"), import("net/url"), import("io/ioutil");
     4  
     5  func connect(uri) {
     6    proxy = os.Getenv("http_proxy")
     7    if proxy != "" {
     8      u, e = url.Parse(proxy)
     9      if e != nil {
    10        return nil, e
    11      }
    12      return net.Dial("tcp", u.Host)
    13    }
    14    return net.Dial("tcp", uri)
    15  }
    16  
    17  c, e = connect("www.google.com:80")
    18  if e != nil {
    19    throw e
    20  }
    21  c.Write(toByteSlice("GET http://www.google.com/ HTTP/1.0\r\n\r\n"))
    22  b, e = ioutil.ReadAll(c)
    23  if e != nil {
    24    throw e
    25  }
    26  printf("%s", b)