11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

IBM の BlueMix で golang

Last updated at Posted at 2014-03-06

BlueMix は cloudfoundry 互換なので cf コマンドで操作する。

cf をインストール

gem install cf

target を設定

$ cf target https://api.ng.bluemix.net
Setting target to https://api.ng.bluemix.net... OK

ログイン

$ cf login
target: https://api.ng.bluemix.net

Email> メールアドレス
Password> ************
Authenticating... OK

go のコードを書く

簡単なやつ

package main

import (
	"net/http"
	"os"
)

func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello World"))
	})
	http.ListenAndServe(":"+port, nil)
}

.godir を作る

$ echo server > .godir

Procfile を作る

$ echo "web: server" > Procfile

ビルドパックを指定して push する

$ cf push --name mattn --buildpack https://github.com/michaljemala/cloudfoundry-buildpack-go.git
Instances> 1

1: 128M
2: 256M
3: 512M
4: 1G
Memory Limit> 256M

Creating mattn... OK

1: mattn
2: none
Subdomain> mattn

1: ng.bluemix.net
2: none
Domain> ng.bluemix.net

Creating route mattn.ng.bluemix.net... OK
Binding mattn.ng.bluemix.net to mattn... OK
Preparing to start mattn... OK
Checking status of app 'mattn'...
  1 of 1 instances running (1 running)
Push successful! App 'mattn' available at mattn.ng.bluemix.net

ソースはここに置いておきます。

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?