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
|
#### 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")
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -196,9 +198,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"})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,6 +269,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"))
|
||||||
@ -306,8 +309,8 @@ 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 := c.MustGet("example").(string)
|
example := r.Get("example").(string)
|
||||||
|
|
||||||
// it would print: "12345"
|
// it would print: "12345"
|
||||||
log.Println(example)
|
log.Println(example)
|
||||||
|
Loading…
Reference in New Issue
Block a user