README: gofmt the code examples

This commit is contained in:
Julien Schmidt 2014-07-04 19:44:07 +02:00
parent 5eb0e10a78
commit 592af3026c

View File

@ -43,11 +43,13 @@ import "github.com/gin-gonic/gin"
#### Create most basic PING/PONG HTTP endpoint
```go
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context){
r.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
@ -82,7 +84,7 @@ func main() {
r.GET("/user/:name", func(c *gin.Context) {
name := c.Params.ByName("name")
message := "Hello "+name
message := "Hello " + name
c.String(200, message)
})
@ -187,9 +189,9 @@ func main() {
// in the HTTP stream and return a 400 error. If you want custom error
// handling you should use: c.ParseBody(interface{}) error
if c.EnsureBody(&json) {
if json.User=="manu" && json.Password=="123" {
if json.User == "manu" && json.Password == "123" {
c.JSON(200, gin.H{"status": "you are logged in"})
}else{
} else {
c.JSON(401, gin.H{"status": "unauthorized"})
}
}
@ -258,6 +260,7 @@ You can also use your own html template render
```go
import "html/template"
func main() {
r := gin.Default()
html := template.Must(template.ParseFiles("file1", "file2"))
@ -293,7 +296,7 @@ func main() {
r := gin.New()
r.Use(Logger())
r.GET("/test", func(c *gin.Context){
r.GET("/test", func(c *gin.Context) {
example := r.Get("example").(string)
// it would print: "12345"