go語言進行開發Web開發,雖然使用go語言自身的包即可實現,但是需要快速開發的時候對初學者還是有一定的障礙。go語言有上千個開源的項目,而這其中也不乏面向web開發的架構,比如Revel/beego/iris等。 beego
beego的開發人員是中國的astaxie,是受了tornado 和 sinatra的啟發而做出的一個簡單易用功能強大的web架構。目前已有很多企業使用者。
安裝
[root@liumiaocn beego]# export GOPATH=/tmp/goprj/beego[root@liumiaocn beego]# go get github.com/astaxie/beego[root@liumiaocn beego]# go get github.com/beego/bee[root@liumiaocn beego]# export PATH=$PATH:/tmp/goprj/beego/bin
建立項目
[root@liumiaocn beego]# bee new helloprj______| ___ \| |_/ / ___ ___| ___ \ / _ \ / _ \| |_/ /| __/| __/\____/ \___| \___| v1.6.22017/01/31 16:02:02 WARN ? 0001 You current workdir is not inside $GOPATH/src.2017/01/31 16:02:02 INFO ? 0002 Creating application... create /tmp/goprj/beego/src/helloprj/ create /tmp/goprj/beego/src/helloprj/conf/ create /tmp/goprj/beego/src/helloprj/controllers/ create /tmp/goprj/beego/src/helloprj/models/ create /tmp/goprj/beego/src/helloprj/routers/ create /tmp/goprj/beego/src/helloprj/tests/ create /tmp/goprj/beego/src/helloprj/static/ create /tmp/goprj/beego/src/helloprj/static/js/ create /tmp/goprj/beego/src/helloprj/static/css/ create /tmp/goprj/beego/src/helloprj/static/img/ create /tmp/goprj/beego/src/helloprj/views/ create /tmp/goprj/beego/src/helloprj/conf/app.conf create /tmp/goprj/beego/src/helloprj/controllers/default.go create /tmp/goprj/beego/src/helloprj/views/index.tpl create /tmp/goprj/beego/src/helloprj/routers/router.go create /tmp/goprj/beego/src/helloprj/tests/default_test.go create /tmp/goprj/beego/src/helloprj/main.go2017/01/31 16:02:02 SUCCESS ? 0003 New application successfully created![root@liumiaocn beego]# ll
執行
[root@liumiaocn helloprj]# pwd/tmp/goprj/beego/src/helloprj[root@liumiaocn helloprj]# bee run______| ___ \| |_/ / ___ ___| ___ \ / _ \ / _ \| |_/ /| __/| __/\____/ \___| \___| v1.6.22017/01/31 16:04:16 INFO ? 0001 Using 'helloprj' as 'appname'2017/01/31 16:04:16 INFO ? 0002 Loading default configuration...2017/01/31 16:04:16 INFO ? 0003 Initializing watcher...2017/01/31 16:04:16 INFO ? 0004 Watching: /tmp/goprj/beego/src/helloprj/controllers2017/01/31 16:04:16 INFO ? 0005 Watching: /tmp/goprj/beego/src/helloprj2017/01/31 16:04:16 INFO ? 0006 Watching: /tmp/goprj/beego/src/helloprj/routers2017/01/31 16:04:16 INFO ? 0007 Watching: /tmp/goprj/beego/src/helloprj/testshelloprj/controllershelloprj/routershelloprj2017/01/31 16:04:18 SUCCESS ? 0008 Built Successfully!2017/01/31 16:04:18 INFO ? 0009 Restarting 'helloprj'...2017/01/31 16:04:18 SUCCESS ? 0010 './helloprj' is running...2017/01/31 16:04:18 [I] [asm_amd64.s:2086] http server Running on http://:80802017/01/31 16:04:39 [D] [server.go:2202] | 192.168.32.1| 200 | 6.373568ms| match| GET / r:/
畫面確認
其他
除了beego之外,revel也被廣泛地採用,還有很多其他的開源優秀的項目可以參看如下URL進行學習。
項目 |
URL |
Revel |
http://www.gorevel.cn/ |
iris |
https://github.com/kataras/iris |
beego |
https://beego.me/ |
開源項目 |
https://github.com/hackstoic/golang-open-source-projects |
開源項目 |
http://www.open-open.com/lib/view/open1396063913278.html |