Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.