revel

Go语言Web框架Revel介绍

余生颓废 提交于 2019-12-05 20:44:12
Revel是一个go语言写的web框架,这个框架源于java的 Play! Framework.清晰的MVC结构,是现在go语言Web框架中优秀的框架。 Revel的功能有 1.热部署 Revel会自动编译你的go代码和templates模板文件,这个类似jsp功能。 2.简单的选择 Revel提供了一个工具包,用户日常的网络维护。也可以放弃这个工具包,直接访问底层应用。 3.轻量级线程 Revel建立在Go Http Server之上,使用Goroutine来处理请求。 Quick Start 安装revel之前,先安装go环境 安装还需要hg和git支持 设置GOPATH,然后把revel安装到GOPATH内 go get github.com/robfig/revel 编译revel go build -o bin/revel github.com/robfig/revel/cmd 运行revel bin/revel run github.com/robfig/revel/samples/chat 这里运行了一个revel的应用chat Revel应用结构 1 appname #应用名称 2 /app #app目录 3 /controllers #app下用于存放controllers的目录 4 /models #存放model的目录 5 /views #存放模板目录 6

使用Revel(go)开发网站

你说的曾经没有我的故事 提交于 2019-12-05 20:43:59
Revel很好的利用了Go语言的goroutine,把每一个request都分配到了goroutine里。不用再写一大堆的回调。如果你写过nodejs的话就会深刻的体会到callback hell是什么样子的。正是由于Revel有了goroutine,Revel的性能也有了很大的提升。官网号称请求的吞吐量是Rails的3到10倍。Revel的性能好,在开发方面也提供了非常全面的工具。常用的路由、模板、session、参数解析、等几乎都有,甚至还提供了一个测试框架。而这些东西的开发都是模块化的,也就是你可以用自己的实现来代替上述提到的工具。比如,用你觉得合适的活着自己开发的router来代替默认的路由。 这里默认的你已经配置好了go env。在GOPATH所指定的目录中的一个里,运行命令 go get github.com/revel/revel之后再运行 go get github.com/revel/cmd/revel。好的这个时候你会报错说无法import到websocket这个包。感谢伟大的全国防火墙,这部分的代码被屏蔽了。虽然直接下载不行,但是代码在github上还是有的。所以,还是可以手动下载,之后配置上的。 这里就需要知道go的另一个很好的工具:http://gopm.io/。这是一个类似于nodejs的npm一样的工具。他会根据版本号来下载对应的go包,而不是git

Can't install Revel (Unrecognized import path)

家住魔仙堡 提交于 2019-12-05 13:57:50
I'm a beginner in Go and I would like to use the Revel web framework. I installed: Git; Mercurial and even: Bazaar and CVS. I checked my environment variables. I set environment variable GOPATH to D:\Go and added D:\Go\bin to PATH.But I still get these errors when I go get The Revel Framework ( go get github.com/revel/revel ) ** package golang.org/x/net/websocket: unrecognized import path "golang.org/x/net/websocket" package gopkg.in/fsnotify.v1: unrecognized import path "gopkg.in/fsnotify.v1"** For instalation of GO into your home folder you need this environment variables: . ├── bin ├── go

Golang requirements.txt equivalent

寵の児 提交于 2019-12-04 23:57:08
Coming from a python/django world, it'd be great to have something like a requirements.txt equivalent for go/revel. How can I do this? I know I can just write a requirements.txt file and then do something like cat reqiurements.txt | xargs go get But what if my requirements ALSO have requirements? The above command would attempt to "go get" them, and then they'd fail to build, since I don't have those requirements installed. Is there something I'm missing? The command go get does exactly what you need: It finds all dependencies and downloads and installs the missing ones. Focus on " all ": go

go revel 简单性能测试

泪湿孤枕 提交于 2019-12-04 23:31:02
用revel创建的new创建了一个最简单的示例app,并用ab做简单的性能测试。设置并发数为1000。 结果如下: dev模式下运行:1200次/每秒 prod模式下运行:4800次/每秒 默认创建的app只能使用单个cpu,对多核多cpu服务器来说是个资源浪费,通过修改init.go 在其中添加如下代码: runtime.GOMAXPROCS(runtime.NumCPU()) 再次测试后,得到测试数据为:17500/每秒。 另:要做性能测试或者正式部署到生产环境之前别忘了把watch设置为false,开发状态下开启watch很爽,修改了代码不需要重启服务,revel发现代码发生了更改会自动重新编译,返回新的结果,但是带来的代价是性能剧降。我忘了关闭此功能做性能测试的结果是从18000次/每秒降到600次/每秒。 来源: oschina 链接: https://my.oschina.net/u/221218/blog/148365

Revel doesn't forward to port 443 when SSL enabled

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using Revel for a small app and added SSL. When I update the config to point to http.port = 443, requests to port 80 are rejected instead of being forwarded. Is there a way to fix this on the Revel Framework? Thank you. # The port on which to listen. http.port = 443 # Whether to use SSL or not. http.ssl = true # Path to an X509 certificate file, if using SSL. http.sslcert = /root/go/src/saml/AlphaCerts/cert.crt # Path to an X509 certificate key, if using SSL. http.sslkey = /root/go/src/saml/star_home_com.key 回答1: You could add a simple

go语言web框架

匿名 (未验证) 提交于 2019-12-03 00:27:02
GO 语言爱好者的最佳Web框架 如果你是自己写一个小应用程序,那你可能不需要Web框架。但是如果你要做产品,那么你肯定需要一个好的框架。 如果你认为你有相应的知识和经验,你会自己编写所有的这些代码么?你有时间找到一个产品级的外部包来完成工作吗?你确定这与你应用程序的其它部分一致吗? 这些都是促使我们(即便是我们中最优秀的)使用框架的原因,如果其他人已经做了必要的艰苦的工作,我们不会想让自己重复这些工作。 简介 Go 是一个快速增长的开源编程语言,用于构建简单、快速和可靠的软件。点 这里 看有哪些大公司在使用Go语言来构建他们的服务。 本文提供了所有必要的信息,以帮助开发人员了解使用Go语言开发Web应用程序的最佳选项。。 本文包含了最详细的框架比较,通过尽可能多的角度(人气,社区支持,内置功能等)来比较最知名的几个Web 框架。 Beego : 一个Go语言下开源的,高性能Web框架 * https://github.com/astaxie/beego * https://beego.me Buffalo : 一个Go语言下快速Web开发框架 * https://github.com/gobuffalo/buffalo * https://gobuffalo.io Echo : 一个高性能,极简的Web框架 * https://github.com/labstack/echo *

Go net/http request

房东的猫 提交于 2019-11-30 10:40:12
Can somebody help to convert my ruby code to Go. Kindly refer to my ruby code below. query= "test" request = Net::HTTP::Post.new(url) request.body = query response = Net::HTTP.new(host, post).start{|http http.request(request)} to Go. VonC You seem to want to POST a query, which would be similar to this answer : import ( "bytes" "fmt" "io/ioutil" "net/http" ) func main() { url := "http://xxx/yyy" fmt.Println("URL:>", url) var query = []byte(`your query`) req, err := http.NewRequest("POST", url, bytes.NewBuffer(query)) req.Header.Set("X-Custom-Header", "myvalue") req.Header.Set("Content-Type",

How to return dynamic type struct in Golang?

自古美人都是妖i 提交于 2019-11-28 19:33:14
I am using Golang Revel for some web project and I did like 12 projects in that so far. In all of them I have a lot of code redundancy because of return types. Look at this two functions: func (c Helper) Brands() []*models.Brand{ //do some select on rethinkdb and populate correct model var brands []*models.Brand rows.All(&brands) return brands } func (c Helper) BlogPosts() []*models.Post{ //do some select on rethinkdb and populate correct model var posts []*models.Post rows.All(&posts) return posts } As you can see they they both returns same type of data (type struct). My idea was just to

How to return dynamic type struct in Golang?

霸气de小男生 提交于 2019-11-27 20:32:48
问题 I am using Golang Revel for some web project and I did like 12 projects in that so far. In all of them I have a lot of code redundancy because of return types. Look at this two functions: func (c Helper) Brands() []*models.Brand{ //do some select on rethinkdb and populate correct model var brands []*models.Brand rows.All(&brands) return brands } func (c Helper) BlogPosts() []*models.Post{ //do some select on rethinkdb and populate correct model var posts []*models.Post rows.All(&posts) return