本文整理汇总了Golang中github.com/atsman/interviewr-go/handlers/utils.GetDb函数的典型用法代码示例。如果您正苦于以下问题:Golang GetDb函数的具体用法?Golang GetDb怎么用?Golang GetDb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetDb函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
})
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:33,代码来源:users.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:9,代码来源:meta.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:10,代码来源:subscriptions.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:10,代码来源:subscriptions.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:11,代码来源:users.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:11,代码来源:interviews.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:11,代码来源:companies.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:12,代码来源:interviews.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:12,代码来源:users.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:12,代码来源:companies.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:12,代码来源:companies.go
示例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{})
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:12,代码来源:interviews.go
示例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{})
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:13,代码来源:companies.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:13,代码来源:vacancies.go
示例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)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:13,代码来源:companies.go
示例16: Create
func Create(c *gin.Context) {
file, fileHeader, err := c.Request.FormFile("file")
if err != nil {
c.Error(err)
return
}
_, h := parseVal("h", c)
_, w := parseVal("w", c)
_, x := parseVal("x", c)
_, y := parseVal("y", c)
img, _, err := image.Decode(file)
if err != nil {
c.Error(err)
return
}
log.Debug("Crop w:%v h:%v x:%v y:%v", w, h, x, y)
rect := convertToRectangle(int(w), int(h), int(x), int(y))
log.Debug("Rect", rect)
croppedImg := imaging.Crop(img, rect)
db := utils.GetDb(c)
gridFile, err := db.GridFS("fs").Create(fileHeader.Filename)
if err != nil {
c.Error(err)
return
}
buffer := new(bytes.Buffer)
jpeg.Encode(buffer, croppedImg, nil)
gridFile.SetName(fileHeader.Filename)
gridFile.SetContentType(fileHeader.Header.Get("Content-Type"))
_, err = io.Copy(gridFile, buffer)
if err != nil {
c.Error(err)
return
}
file.Close()
gridFile.Close()
c.JSON(http.StatusOK, gin.H{"_id": gridFile.Id()})
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:49,代码来源:images.go
示例17: GetList
func GetList(c *gin.Context) {
db := utils.GetDb(c)
err, query := BuildQuery(c)
if err != nil {
c.Error(err)
return
}
log.Debug("interviews - GetList, query: ", query)
err, interviews := interviewdb.GetList(db, query)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, interviews)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:15,代码来源:interviews.go
示例18: GetUserCompanies
func GetUserCompanies(c *gin.Context) {
db := utils.GetDb(c)
id := c.Params.ByName("id")
err, companies := companydb.GetList(db, &bson.M{
"owner": bson.ObjectIdHex(id),
})
if err != nil {
c.JSON(http.StatusNotFound, userNotFoundError)
return
}
c.JSON(http.StatusOK, companies)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:15,代码来源:users.go
示例19: Delete
func Delete(c *gin.Context) {
db := utils.GetDb(c)
userId := utils.GetUserId(c)
id := c.Params.ByName("id")
err, sub := subdb.Delete(db, userId, id)
if err != nil {
log.Debug(err)
c.Error(err)
return
}
interviewdb.GetInterviewC(db).RemoveId(sub.Interview)
c.JSON(http.StatusOK, sub)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:15,代码来源:subscriptions.go
示例20: GetVacancySubscriptions
func GetVacancySubscriptions(c *gin.Context) {
db := utils.GetDb(c)
id := c.Params.ByName("id")
query := map[string]interface{}{}
query["vacancy"] = id
//query["vacancy"]
err, subs := subdb.GetList(db, query)
if err != nil {
c.Error(err)
return
}
c.JSON(http.StatusOK, subs)
}
开发者ID:Atsman,项目名称:interviewr-go,代码行数:16,代码来源:vacancies.go
注:本文中的github.com/atsman/interviewr-go/handlers/utils.GetDb函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论