Skip to content

Instantly share code, notes, and snippets.

@Cibernomadas
Created June 28, 2018 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cibernomadas/90c5205580f21d53327d1683c478c4ac to your computer and use it in GitHub Desktop.
Save Cibernomadas/90c5205580f21d53327d1683c478c4ac to your computer and use it in GitHub Desktop.
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