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进行学习。
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/9475.html