Created
June 28, 2018 21:15
-
-
Save Cibernomadas/90c5205580f21d53327d1683c478c4ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func ProfileFn(c *gin.Context) { | |
dbc, exist := c.Get("db") | |
if !exist { | |
c.HTML(http.StatusOK, "index", gin.H{ | |
"title": "Hi! GoBlog.", | |
"error": "We've got an internal error, please try later.", | |
}) | |
return | |
} | |
db := dbc.(*gorm.DB) | |
username := c.Param("name") | |
user := models.User{} | |
db.Where(&models.User{Username: username}).First(&user) | |
if user.Username != "" { | |
c.HTML(http.StatusOK, "profile", gin.H{ | |
"title": "Hi! GoBlog.", | |
"user": user, | |
}) | |
return | |
} else { | |
c.HTML(http.StatusOK, "index", gin.H{ | |
"title": "Hi! GoBlog.", | |
"error": "User not found", | |
}) | |
return | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment