本文整理汇总了Golang中github.com/atsman/interviewr-go/handlers/utils.GetDb函数的典型用法代码示例。如果您正苦于以下问题:Golang GetDb函数的具体用法?Golang GetDb怎么用?Golang GetDb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetDb函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Login
func Login(c *gin.Context) {
loginData := LoginData{}
err := c.Bind(&loginData)
if err != nil {
c.JSON(http.StatusBadRequest, err)
return
}
db := utils.GetDb(c)
err, user := userdb.GetOne(db, bson.M{
"username": loginData.Username,
})
err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(loginData.Password))
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{
"success": false,
"message": "The username or password don't match",
})
return
}
token, err := CreateJwtToken(user.ID.Hex())
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"id_token": token,
})
}
示例2: sendMeta
func sendMeta(name string, c *gin.Context) {
db := utils.GetDb(c)
err, res := getData(db, name)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, res)
}
示例3: GetList
func GetList(c *gin.Context) {
db := utils.GetDb(c)
query := BuildQuery(c)
err, subs := subdb.GetList(db, query)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, subs)
}
示例4: GetOne
func GetOne(c *gin.Context) {
db := utils.GetDb(c)
id := c.Params.ByName("id")
err, sub := subdb.GetOne(db, id)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, sub)
}
示例5: GetList
func GetList(c *gin.Context) {
db := utils.GetDb(c)
err, users := userdb.GetList(db, &bson.M{})
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, users)
}
示例6: Delete
func Delete(c *gin.Context) {
db := utils.GetDb(c)
userID := utils.GetUserId(c)
id := c.Params.ByName("id")
err, interview := interviewdb.Delete(db, userID, id)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, interview)
}
示例7: GetList
func GetList(c *gin.Context) {
db := utils.GetDb(c)
query := BuildQuery(c)
err, companies := companydb.GetList(db, query)
if err != nil {
log.Error(err.Error())
c.JSON(http.StatusNotFound, companyNotFoundError)
return
}
c.JSON(http.StatusOK, companies)
}
示例8: GetFeedback
func GetFeedback(c *gin.Context) {
db := utils.GetDb(c)
id := c.Params.ByName("id")
err, feedback := interviewdb.GetFeedback(db, id)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, feedback)
}
示例9: Delete
func Delete(c *gin.Context) {
db := utils.GetDb(c)
id := c.Params.ByName("id")
err, user := userdb.Delete(db, id)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, user)
}
示例10: GetOne
func GetOne(c *gin.Context) {
db := utils.GetDb(c)
id := c.Params.ByName("id")
err, company := companydb.GetOne(db, id)
if err != nil {
c.JSON(http.StatusNotFound, companyNotFoundError)
return
}
c.JSON(http.StatusOK, company)
}
示例11: GetComments
func GetComments(c *gin.Context) {
db := utils.GetDb(c)
id := c.Params.ByName("id")
err, comments := companydb.GetComments(db, id)
if err != nil {
c.JSON(http.StatusBadRequest, err)
return
}
c.JSON(http.StatusOK, comments)
}
示例12: End
func End(c *gin.Context) {
db := utils.GetDb(c)
id := c.Params.ByName("id")
err := interviewdb.End(db, id)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{})
}
示例13: DeleteComment
func DeleteComment(c *gin.Context) {
db := utils.GetDb(c)
companyId := c.Params.ByName("id")
commentId := c.Params.ByName("commentId")
err := companydb.DeleteComment(db, companyId, commentId)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{})
}
示例14: Delete
func Delete(c *gin.Context) {
db := utils.GetDb(c)
userId := utils.GetUserId(c)
id := c.Params.ByName("id")
err, user := vacancydb.DeleteById(db, userId, id)
if err != nil {
log.Error(err.Error())
c.JSON(http.StatusNotFound, notFoundError)
return
}
c.JSON(http.StatusOK, user)
}
示例15: Delete
func Delete(c *gin.Context) {
db := utils.GetDb(c)
userId := utils.GetUserId(c)
companyId := c.Params.ByName("id")
err, company := companydb.Delete(db, userId, companyId)
if err != nil {
c.JSON(http.StatusNotFound, companyNotFoundError)
return
}
c.JSON(http.StatusOK, company)
}