Skip to content
Myr

v0.5 release

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Javier Provecho Fernandez · committed by Javier Provecho Fernandez · parents 5cfe2c5, b1758d3 · Browse files · 8 files+62 added−42 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+62 added−42 removed

  • other:+62 added−42 removed

8 files+62 added−42 removed

modified:binding/binding.go+1 added-1 removed
168 unmodified lines
169 for i := 0; i < typ.NumField(); i++ {170 field := typ.Field(i)171172 // Allow ignored and unexported fields in the struct173 if field.Tag.Get("form") == "-" || field.PkgPath != "" {173 if len(field.PkgPath) > 0 || field.Tag.Get("form") == "-" {174 continue175 }176177 fieldValue := val.Field(i).Interface()
39 unmodified lines
modified:Godeps/Godeps.json+1 added-1 removed
modified:render/render.go+1 added-1 removed
48 unmodified lines
49 HTMLDebug = &htmlDebugRender{}50)5152func writeHeader(w http.ResponseWriter, code int, contentType string) {53 w.Header().Set("Content-Type", contentType)53 w.Header().Set("Content-Type", contentType+"; charset=utf-8")54 w.WriteHeader(code)55}5657func (_ jsonRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {
66 unmodified lines
modified:AUTHORS.md+18 added-2 removed
modified:CHANGELOG.md+4 added-1 removed
1#Changelog23###Gin 0.5 (Jan 4, 2015)3###Gin 0.6 (Mar 7, 2015)456###Gin 0.5 (Feb 7, 2015)78- [NEW] Content Negotiation9- [FIX] Solved security bug that allow a client to spoof ip10- [FIX] Fix unexported/ignored fields in binding11
53 unmodified lines
modified:context_test.go+6 added-6 removed
74 unmodified lines
75 if w.Body.String() != "{\"foo\":\"bar\"}\n" {76 t.Errorf("Response should be {\"foo\":\"bar\"}, was: %s", w.Body.String())77 }7879 if w.HeaderMap.Get("Content-Type") != "application/json" {79 if w.HeaderMap.Get("Content-Type") != "application/json; charset=utf-8" {80 t.Errorf("Content-Type should be application/json, was %s", w.HeaderMap.Get("Content-Type"))81 }82}83
18 unmodified lines
102 if w.Body.String() != "Hello alexandernyquist" {103 t.Errorf("Response should be Hello alexandernyquist, was: %s", w.Body.String())104 }105106 if w.HeaderMap.Get("Content-Type") != "text/html" {106 if w.HeaderMap.Get("Content-Type") != "text/html; charset=utf-8" {107 t.Errorf("Content-Type should be text/html, was %s", w.HeaderMap.Get("Content-Type"))108 }109}110
13 unmodified lines
124 if w.Body.String() != "test" {125 t.Errorf("Response should be test, was: %s", w.Body.String())126 }127128 if w.HeaderMap.Get("Content-Type") != "text/plain" {128 if w.HeaderMap.Get("Content-Type") != "text/plain; charset=utf-8" {129 t.Errorf("Content-Type should be text/plain, was %s", w.HeaderMap.Get("Content-Type"))130 }131}132
13 unmodified lines
146 if w.Body.String() != "<map><foo>bar</foo></map>" {147 t.Errorf("Response should be <map><foo>bar</foo></map>, was: %s", w.Body.String())148 }149150 if w.HeaderMap.Get("Content-Type") != "application/xml" {150 if w.HeaderMap.Get("Content-Type") != "application/xml; charset=utf-8" {151 t.Errorf("Content-Type should be application/xml, was %s", w.HeaderMap.Get("Content-Type"))152 }153}154
180 unmodified lines
335 if w.Body.String() != "{\"parsed\":\"bar\"}\n" {336 t.Errorf("Response should be {\"parsed\":\"bar\"}, was: %s", w.Body.String())337 }338339 if w.HeaderMap.Get("Content-Type") != "application/json" {339 if w.HeaderMap.Get("Content-Type") != "application/json; charset=utf-8" {340 t.Errorf("Content-Type should be application/json, was %s", w.HeaderMap.Get("Content-Type"))341 }342}343
24 unmodified lines
368 if w.Body.String() != "{\"parsed\":\"嘉\"}\n" {369 t.Errorf("Response should be {\"parsed\":\"嘉\"}, was: %s", w.Body.String())370 }371372 if w.HeaderMap.Get("Content-Type") != "application/json" {372 if w.HeaderMap.Get("Content-Type") != "application/json; charset=utf-8" {373 t.Errorf("Content-Type should be application/json, was %s", w.HeaderMap.Get("Content-Type"))374 }375}376
107 unmodified lines
modified:gin.go+2 added-2 removed
125 unmodified lines
126 engine.router.ServeHTTP(writer, request)127}128129func (engine *Engine) Run(addr string) error {130 debugPrint("Listening and serving HTTP on %s", addr)130 debugPrint("Listening and serving HTTP on %s\n", addr)131 if err := http.ListenAndServe(addr, engine); err != nil {132 return err133 }134 return nil135}136137func (engine *Engine) RunTLS(addr string, cert string, key string) error {138 debugPrint("Listening and serving HTTPS on %s", addr)138 debugPrint("Listening and serving HTTPS on %s\n", addr)139 if err := http.ListenAndServeTLS(addr, cert, key, engine); err != nil {140 return err141 }142 return nil
1 unmodified line
modified:README.md+29 added-28 removed
1#Gin Web Framework1#Gin Web Framework [![GoDoc](https://godoc.org/github.com/gin-gonic/gin?status.svg)](https://godoc.org/github.com/gin-gonic/gin) [![Build Status](https://travis-ci.org/gin-gonic/gin.svg)](https://travis-ci.org/gin-gonic/gin)23[![GoDoc](https://godoc.org/github.com/gin-gonic/gin?status.svg)](https://godoc.org/github.com/gin-gonic/gin)4[![Build Status](https://travis-ci.org/gin-gonic/gin.svg)](https://travis-ci.org/gin-gonic/gin)53Gin is a web framework written in Golang. It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin. 45![Gin console logger](https://gin-gonic.github.io/gin/other/console.png)6
24 unmodified lines
31```3233##Gin is new, will it be supported?3438Yes, Gin is an internal project of [my](https://github.com/manucorporat) upcoming startup. We developed it and we are going to continue using and improve it.35Yes, Gin is an internal tool of [Manu](https://github.com/manucorporat) and [Javi](https://github.com/javierprovecho) for many of our projects/start-ups. We developed it and we are going to continue using and improve it.363738##Roadmap for v1.042- [x] Performance improments, reduce allocation and garbage collection overhead43- [x] Fix bugs44- [ ] Stable API39- [ ] Ask our designer for a cool logo40- [ ] Add tons of unit tests41- [ ] Add internal benchmarks suite42- [ ] More powerful validation API43- [ ] Improve documentation44- [ ] Add Swagger support45- [x] Stable API46- [x] Improve logging system47- [x] Improve JSON/XML validation using bindings48- [x] Improve XML support49- [x] Flexible rendering system52- [ ] More powerful validation API53- [ ] Improve documentation54- [X] Add more cool middlewares, for example redis caching (this also helps developers to understand the framework).50- [x] Add more cool middlewares, for example redis caching (this also helps developers to understand the framework).51- [x] Continuous integration52- [x] Performance improments, reduce allocation and garbage collection overhead53- [x] Fix bugs54555657## Start using it
72 unmodified lines
130 message := "Hello "+name131 c.String(200, message)132 })133136 // However, this one will match /user/john and also /user/john/send134 // However, this one will match /user/john/ and also /user/john/send135 // If no other routers match /user/john, it will redirect to /user/join/136 r.GET("/user/:name/*action", func(c *gin.Context) {137 name := c.Params.ByName("name")138 action := c.Params.ByName("action")139 message := name + " is " + action
3 unmodified lines
143 // Listen and server on 0.0.0.0:8080144 r.Run(":8080")145}146```147###Form parameters148```go149func main() {150 r := gin.Default()151 152 // This will respond to urls like search?firstname=Jane&lastname=Doe153 r.GET("/search", func(c *gin.Context) {154 // You need to call ParseForm() on the request to receive url and form params first155 c.Request.ParseForm()156 157 firstname := c.Request.Form.Get("firstname")158 lastname := c.Request.Form.get("lastname")159160 message := "Hello "+ firstname + lastname161 c.String(200, message)162 })163 r.Run(":8080")164}165```166167#### Grouping routes168```go169func main() {
175 unmodified lines
345```346347Note: this will use `httpNotFound` instead of the Router's `NotFound` handler.348332####Serving static files333334Use Engine.ServeFiles(path string, root http.FileSystem):335336```go337func main() {338 r := gin.Default()339 r.Static("/assets", "./assets")340341 // Listen and server on 0.0.0.0:8080342 r.Run(":8080")343}344```345346Note: this will use `httpNotFound` instead of the Router's `NotFound` handler.347349####HTML rendering350351Using LoadHTMLTemplates()352
184 unmodified lines