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