在IBM的BlueMix上使用golang
由于BlueMix与cloudfoundry兼容,因此可以使用cf命令进行操作。
安装cf
gem install cf
设定目标
$ 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
指定构建包并推送
$ 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
我将把源文件放在这里。 (Wǒ bǎ .)