cgarvis / martini-etag Goto Github PK
View Code? Open in Web Editor NEWETag support for Martini
ETag support for Martini
I think this small piece of code would be great candidate for the martini contrib collection. Don't you think?
In the following example, /a will return an ETag header and /b won't.
package main
import . "github.com/cgarvis/martini-etag"
import "github.com/codegangsta/martini"
func main() {
m := martini.Classic()
m.Use(ETag())
m.Get("/a", func() string {
a := make([]byte, 2000)
return string(a)
})
m.Get("/b", func() (int, string) {
b := make([]byte, 2000)
return 200, string(b)
})
m.Run()
}
I'm using "github.com/martini-contrib/render" to render r.JSON(200, userStruct)
and no Etag header is being added. I've checked some of the none-json routes and I have the same issue.
I'm basically doing:
func main() {
m := martini.Classic()
m.Use(ETag())
var appEnv *AppEnv = LoadEnv()
m.Map(appEnv)
m.Use(render.Renderer())
appName.RegisterRoutes(m)
m.Run()
}
func RegisterRoutes(m *martini.ClassicMartini) {
m.Get("/status", func(r render.Render) {
r.Text(200, "SUCCESS")
})
}
I think the README should be updated with an example that sends >= 1024 bytes. An example that sends an ETag would be less confusing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.