Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
22
Help us understand the problem. What is going on with this article?
@hit

Centos6.5 に Go.lang と mysql ドライバをインストールしてみた

More than 5 years have passed since last update.

OS別の最新版ダウンロード URL

GO言語のダウンロードは以下から行います

https://golang.org/dl/

Centos6.5でのGOインストール手順

ディストリビューションの確認

cat /etc/redhat-release                                                                                       
----
CentOS release 6.5 (Final)

インストール

cd /usr/local/src
wget https://storage.googleapis.com/golang/go1.4.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.4.linux-amd64.tar.gz

パスの設定

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

.bashrc にパスを追記

次回ログイン時も有効になるように設定しておく

cat << '_EOT_' >> ~/.bashrc
GOPATH=/usr/local/go/
PATH=$PATH:/usr/local/go/bin
_EOT_

MySQLドライバのインストール

go get github.com/go-sql-driver/mysql

サンプルプログラムの実行

cat << '_EOT_' > /tmp/hello.go

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}
_EOT_


go run /tmp/hello.go
---
hello, world

上記サンプルをコンパイルして実行

go build /tmp/hello.go
./hello 
---
hello, world

httpを書いてみる


cat << '_EOT_' > /tmp/http.go

package main

import (
    "fmt"
    "html"
    "net/http"
)

func HelloServer(w http.ResponseWriter, req *http.Request) {
    title := html.EscapeString(req.URL.Path[1:])
    strpost := req.FormValue("strpost")
    strget := req.FormValue("strget")
    output := `
<html>
  <head>
   <title>` + title + `</title>
  </head>
  <body>
  <h1>post/getのテスト</h1>
     <h2>post</h2>
        post=`+ html.EscapeString(strpost) + `</br>
     <h2>get</h2>
        get=`+ html.EscapeString(strget) + `</br>
  </body>
</html>
`
fmt.Fprintf(w, "%s", output)
}

func main() {
    http.HandleFunc("/hello", HelloServer)
    http.ListenAndServe(":8080", nil)
}
_EOT_

go run /tmp/http.go
22
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
hit
なんとなくデータベースエンジニア。なんとなくメモしてます

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
22
Help us understand the problem. What is going on with this article?