go語言快速入門:Web開發框架(10)
阿新 • • 發佈:2018-12-22
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
建立專案
[[email protected] beego]# bee new helloprj
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.6.2
2017/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.go
2017/01/31 16:02:02 SUCCESS ? 0003 New application successfully created!
[[email protected] beego]# ll
執行
[[email protected] helloprj]# pwd
/tmp/goprj/beego/src/helloprj
[[email protected] helloprj]# bee run
______
| ___ \
| |_/ / ___ ___
| ___ \ / _ \ / _ \
| |_/ /| __/| __/
\____/ \___| \___| v1.6.2
2017/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/controllers
2017/01/31 16:04:16 INFO ? 0005 Watching: /tmp/goprj/beego/src/helloprj
2017/01/31 16:04:16 INFO ? 0006 Watching: /tmp/goprj/beego/src/helloprj/routers
2017/01/31 16:04:16 INFO ? 0007 Watching: /tmp/goprj/beego/src/helloprj/tests
helloprj/controllers
helloprj/routers
helloprj
2017/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://:8080
2017/01/31 16:04:39 [D] [server.go:2202] | 192.168.32.1| 200 | 6.373568ms| match| GET / r:/
畫面確認
其他
除了beego之外,revel也被廣泛地採用,還有很多其他的開源優秀的專案可以參看如下URL進行學習。