Documentation
¶
Index ¶
- func CreateAnswer(c *gin.Context)
- func CreateQuestion(c *gin.Context)
- func DeleteAnswer(c *gin.Context)
- func DeleteQuestion(c *gin.Context)
- func EmailLogin(c *gin.Context)
- func InitRouter()
- func ModifyAnswer(c *gin.Context)
- func ModifyQuestion(c *gin.Context)
- func PhoneNumberLogin(c *gin.Context)
- func UserNameLogin(c *gin.Context)
- func UserRegister(c *gin.Context)
- func ViewOwnAnswers(c *gin.Context)
- func ViewOwnQuestions(c *gin.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateAnswer ¶
func CreateQuestion ¶
func DeleteAnswer ¶
func DeleteQuestion ¶
func EmailLogin ¶
func InitRouter ¶
func InitRouter()
func ModifyAnswer ¶
func ModifyQuestion ¶
func PhoneNumberLogin ¶
func UserNameLogin ¶
func UserRegister ¶
func ViewOwnAnswers ¶
func ViewOwnQuestions ¶
func CreateComment(c *gin.Context) {
//接收前端发来的数据
var comment model.Comment
err := c.ShouldBindJSON(&comment)
if err != nil {
checkresponse.ResFail(c, "参数绑定失败")
return
}
//通过c.Get方法获取的值的类型是interface{},因此需要根据实际情况进行类型断言或转换,以便正确使用该值。
usernameRaw, exists := c.Get("username")
if !exists {
checkresponse.ResFail(c, "无法获取用户名")
return
}
username, ok := usernameRaw.(string)
if !ok {
checkresponse.ResFail(c, "用户名类型断言失败")
return
}
//存入数据库
depositcomment := model.Comment{
Commenter: username,
AnswerID: comment.AnswerID,
Content: comment.Content,
}
global.GlobalDb.Model(&model.Question{}).Create(&depositcomment)
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.