osada-chan

Rails メインでサーバーサイドエンジニアしつつ現場監督やってます

A Tour of Go 3

2ページ目は言語選択だったので飛ばす。

3ページ目

package main

import (
  "fmt"
  "net"
  "os"
  "time"
)

func main() {
  fmt.Println("Welcome to the playground!")

  fmt.Println("The time is", time.Now())

  fmt.Println("And if you try to open a file: ")
  fmt.Println(os.Open("filename"))

  fmt.Println("Or access the network: ")
  fmt.Println(net.Dial("tcp", "localhost:80"))
}

いろんなものをPrintlnしてみた。 net.Dialとかそのまま実行できなくて、結局リファレンス読む、と。

よく分からなかったのはこれ。


  fmt.Println(os.Open("filename"))
  fmt.Println(net.Dial("tcp", "localhost:80"))

実行結果

&{0xc084044000} <nil>
&{{0xc084047000}} <nil>

どうやら、ポインタとエラーが返っているみたい。 Goでは複数の値を返すことができるみたいです。

<nil>

ってことは成功ですな。

ふむふむ。まだ大丈夫。