GoでHello World

(20)
https://qiita.com/nsd24/items/7ca62a054ec09c799e1b
https://qiita.com/notchi/items/5f76b2f77cff39eca4d8
http://pineplanter.moo.jp/non-it-salaryman/2017/06/26/webserver-on-golang/

apt install golang
go version


mkdir -p /usr/local/go
vim ~/.profile

export GOPATH=/usr/local/go
export PATH=$PATH:$GOPATH/bin

. ~/.profile

mkdir -p /usr/local/go/{bin,pkg,src}
mkdir -p /usr/local/go/src/hello
cd /usr/local/go/src/hello


vim hello.go

package main

import "fmt"

func main() {
fmt.Printf("Hello World!\n")
}

go run hello.go
go install /usr/local/go/src/hello
hello

--
mkdir -p /usr/local/go/src/web
cd /usr/local/go/src/web

vim web.go

package main

import (
"log"
"net/http"
)

func main() {
http.Handle("/", http.FileServer(http.Dir(".") ) )
log.Fatal(http.ListenAndServe(":8080", nil) )
}

vim index.html

<!DOCTYPE html>
<html>
<body>
<h1>Hello World!</h1>
</body>
</html>

go run web.go
go install /usr/local/go/src/web
web

 

(10)

apt install golang
go version


mkdir -p /usr/local/go
vim ~/.profile

export GOPATH=/usr/local/go
export PATH=$PATH:$GOPATH/bin

. ~/.profile

mkdir -p /usr/local/go/{bin,pkg,src}
mkdir -p /usr/local/go/src/hello
cd /usr/local/go/src/hello


vim hello.go

package main

import "fmt"

func main() {
fmt.Printf("Hello World!\n")
}

go run hello.go
go install /usr/local/go/src/hello
hello

--
mkdir -p /usr/local/go/src/web
cd /usr/local/go/src/web

vim web.go

package main

import (
"log"
"net/http"
)

func main() {
http.Handle("/", http.FileServer(http.Dir(".") ) )
log.Fatal(http.ListenAndServe(":8080", nil) )
}

vim index.html

<!DOCTYPE html>
<html>
<body>
<h1>Hello World!</h1>
</body>
</html>

go run web.go
go install /usr/local/go/src/web
web

 

(8)
https://qiita.com/nooboolean/items/11805928527aeb576c21

dnf install epel-release
dnf info golang

dnf install golang
go version


mkdir -p /usr/local/go
vim ~/.bash_profile

export GOPATH=/usr/local/go
export PATH=$PATH:$GOPATH/bin

. ~/.bash_profile

mkdir -p /usr/local/go/{bin,pkg,src}
mkdir -p /usr/local/go/src/hello
cd /usr/local/go/src/hello


vim hello.go

package main

import "fmt"

func main() {
fmt.Printf("Hello World!\n")
}

go run hello.go
go install /usr/local/go/src/hello
hello

--
mkdir -p /usr/local/go/src/web
cd /usr/local/go/src/web

vim web.go

package main

import (
"log"
"net/http"
)

func main() {
http.Handle("/", http.FileServer(http.Dir(".") ) )
log.Fatal(http.ListenAndServe(":8080", nil) )
}

vim index.html

<!DOCTYPE html>
<html>
<body>
<h1>Hello World!</h1>
</body>
</html>

go run web.go
go install /usr/local/go/src/web
web

 

(2019)

https://techfun.cc/go/golang.html


MSIからインストールにより
GOPATHは%USERPROFILE%\goが設定され
Pathに%GOPATH%\binが追加される

go version

mkdir C:\Users\Administrator\go


mkdir C:\Users\Administrator\go\bin
mkdir C:\Users\Administrator\go\pkg
mkdir C:\Users\Administrator\go\src

mkdir C:\Users\Administrator\go\src\hello
cd C:\Users\Administrator\go\src\hello


notepad hello.go

package main

import "fmt"

func main() {
fmt.Printf("Hello World!\n")
}

go run hello.go
go install C:\Users\Administrator\go\src\hello
hello

--
mkdir C:\Users\Administrator\go\src\web
cd C:\Users\Administrator\go\src\web

notepad web.go

package main

import (
"log"
"net/http"
)

func main() {
http.Handle("/", http.FileServer(http.Dir(".") ) )
log.Fatal(http.ListenAndServe(":8080", nil) )
}

notepad index.html

<!DOCTYPE html>
<html>
<body>
<h1>Hello World!</h1>
</body>
</html>

go run web.go
go install C:\Users\Administrator\go\src\web
web