Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. type Login struct {
  2. User string `form:"user" json:"user" binding:"required"`
  3. Password string `form:"password" json:"password" binding:"required"`
  4.  
  5. // Example for binding JSON ({"user": "manu", "password": "123"})
  6. router.POST("/loginJSON", func(c *gin.Context) {
  7. var json Login
  8. if c.BindJSON(&json) == nil {
  9. if json.User == "manu" && json.Password == "123" {
  10. c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
  11. } else {
  12. c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
  13. }
  14. }
  15. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement