mirror of https://github.com/gin-gonic/gin.git
Merge branch 'master' of https://github.com/julienschmidt/gin into julienschmidt-master
Conflicts: README.md
This commit is contained in:
commit
e2ecb03c16
13
README.md
13
README.md
|
@ -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")
|
||||
})
|
||||
|
||||
|
@ -196,9 +198,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"})
|
||||
}
|
||||
}
|
||||
|
@ -267,6 +269,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"))
|
||||
|
@ -306,8 +309,8 @@ func main() {
|
|||
r := gin.New()
|
||||
r.Use(Logger())
|
||||
|
||||
r.GET("/test", func(c *gin.Context){
|
||||
example := c.MustGet("example").(string)
|
||||
r.GET("/test", func(c *gin.Context) {
|
||||
example := r.Get("example").(string)
|
||||
|
||||
// it would print: "12345"
|
||||
log.Println(example)
|
||||
|
|
Loading…
Reference in New Issue