Hello World
定番のHello Worldを作成してみる。
まず、プロジェクトを作成する。
Project Space Making1 | $ mkdir -p $GOPATH /src/example/hello
|
いよいよ、ソースの作成だ。
Hello World1 2 3 4 5 6 7 | package main
import "fmt"
func main() {
fmt.Println( "Hello, World!" )
}
|
かなりシンプル。
次に実行。
Project Space Making1 2 3 4 5 6 7 8 9 | $ pwd
$HOME /go
$go install example /hello
$ ls
bin src
$ ls bin
hello
$bin /hello
Hello, World!
|
出来た!
Install
We can use apt to install go.
Download1 | $ sudo apt-get install golang-go
|
Test Program
Making Workspace
It’s easy with managing to make work space .
You can use only mkdir command to make workspace.
And then setting workspace.
Workspace Setting1 2 3 | $vim ~/.bashrc
export GOPATH=$HOME /go
$ source ~/.bashrc
|
Hello World
Try to make hello world program.
At first let’s make project.
Project Space Making1 | $ mkdir -p $GOPATH /src/example/hello
|
Finally programming.
Hello World1 2 3 4 5 6 7 | package main
import "fmt"
func main() {
fmt.Println( "Hello, World!" )
}
|
So simple.
And then run.
Project Space Making1 2 3 4 5 6 7 8 9 | $ pwd
$HOME /go
$go install example /hello
$ ls
bin src
$ ls bin
hello
$bin /hello
Hello, World!
|
Good!