Go

提供: FreeBSD入門
2014年3月28日 (金) 21:06時点におけるDaemon (トーク | 投稿記録)による版 (ページの作成:「Go 言語とは、Googleが開発したプログラミング言語です。 '''読み方''' ;Go:ごー __TOC__ == 概要 == Go ;ゴルーチン:「軽...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索
スポンサーリンク

Go 言語とは、Googleが開発したプログラミング言語です。

読み方

Go
ごー

概要

Go

ゴルーチン
「軽量スレッド」ライクなもの。同期と非同期がある。
チャンネル
「UNIXパイプ」ライクなもの。ゴルーチン間の通信に使用します。

インストール

pkgコマンドでインストールする場合

sudo pkg install go
Updating repository catalogue
The following 1 packages will be installed:
 
        Installing go: 1.2.1,1
 
The installation will require 112 MB more space
 
18 MB to be downloaded
 
Proceed with installing packages [y/N]: y
go-1.2.1,1.txz  100%   18MB 306.3KB/s 666.7KB/s   01:01
Checking integrity... done
[1/1] Installing go-1.2.1,1... done

設定

 

使い方

Goのオプション

Go is a tool for managing Go source code.
 
Usage:
 
        go command [arguments]
 
The commands are:
 
    build       compile packages and dependencies
    clean       remove object files
    env         print Go environment information
    fix         run go tool fix on packages
    fmt         run gofmt on package sources
    get         download and install packages and dependencies
    install     compile and install packages and dependencies
    list        list packages
    run         compile and run Go program
    test        test packages
    tool        run specified go tool
    version     print Go version
    vet         run go tool vet on packages
 
Use "go help [command]" for more information about a command.
 
Additional help topics:
 
    c           calling between Go and C
    gopath      GOPATH environment variable
    importpath  import path syntax
    packages    description of package lists
    testflag    description of testing flags
    testfunc    description of testing functions
 
Use "go help [topic]" for more information about that topic.

Go言語におけるHello World

helloworld.go

package main
 
import (
     "fmt"
       )
 
func main() {
  fmt.Printf("Hello, world\n")
}

コンパイル

$ go build helloworld.go

helloworld.go しかないディレクトリで以下のコマンドを実行するだけでも、コンパイルされます。

$ go build

実行例

$ ./helloworld
Hello, world

for 文

for.go

package main
import ( "fmt")
 
func main() {
  for i:=0; i < 10; i++ {
     fmt.Printf("%d ", i)
  }
  fmt.Printf("\n")
}

実行例

$ ./fo
0 1 2 3 4 5 6 7 8 9

関連項目

  • Go



スポンサーリンク