Golang Context.DefaultQuery Examples

Golang Context.DefaultQuery - 30 examples found. These are the top rated real world Golang examples of github.com/gin-gonic/gin.Context.DefaultQuery extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
File: topics.go Project: ovh/tat
func (*TopicsController) buildCriteria(ctx *gin.Context, user *tat.User) *tat.TopicCriteria {
	c := tat.TopicCriteria{}
	skip, e := strconv.Atoi(ctx.DefaultQuery("skip", "0"))
	if e != nil {
		skip = 0
	}
	c.Skip = skip
	limit, e2 := strconv.Atoi(ctx.DefaultQuery("limit", "500"))
	if e2 != nil {
		limit = 500
	}
	c.Limit = limit
	c.IDTopic = ctx.Query("idTopic")
	c.Topic = ctx.Query("topic")
	if c.Topic != "" && !strings.HasPrefix(c.Topic, "/") {
		c.Topic = "/" + c.Topic
	}
	c.Description = ctx.Query("description")
	c.DateMinCreation = ctx.Query("dateMinCreation")
	c.DateMaxCreation = ctx.Query("dateMaxCreation")
	c.GetNbMsgUnread = ctx.Query("getNbMsgUnread")
	c.OnlyFavorites = ctx.Query("onlyFavorites")
	c.GetForTatAdmin = ctx.Query("getForTatAdmin")
	c.TopicPath = ctx.Query("topicPath")

	if c.OnlyFavorites == "true" {
		c.Topic = strings.Join(user.FavoritesTopics, ",")
	}

	if c.SortBy == "" {
		c.SortBy = "topic"
	}
	return &c
}
Example #2
0
File: api.go Project: schollz/find
func calculate(c *gin.Context) {
	group := c.DefaultQuery("group", "noneasdf")
	if group != "noneasdf" {
		if !groupExists(group) {
			c.JSON(http.StatusOK, gin.H{"message": "You should insert a fingerprint first, see documentation", "success": false})
			return
		}
		group = strings.ToLower(group)
		optimizePriorsThreaded(group)
		if RuntimeArgs.Svm {
			dumpFingerprintsSVM(group)
			err := calculateSVM(group)
			if err != nil {
				Warning.Println("Encountered error when calculating SVM")
				Warning.Println(err)
			}
		}
		if RuntimeArgs.RandomForests {
			rfLearn(group)
		}
		go resetCache("userPositionCache")
		c.JSON(http.StatusOK, gin.H{"message": "Parameters optimized.", "success": true})
	} else {
		c.JSON(http.StatusOK, gin.H{"success": false, "message": "Error parsing request"})
	}
}
Example #3
0
func strategySwitch(c *gin.Context) {
	strategy_id := c.Param("id")
	enable, err := strconv.Atoi(c.DefaultQuery("enable", "0"))
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "message": err.Error()})
		return
	}
	var strategy types.Strategy
	if len(strategy_id) == 0 {
		c.JSON(http.StatusBadRequest, gin.H{"code": http.StatusBadRequest, "message": "strategy_id should be applied"})
		return
	}

	if err := mydb.Where("id = ?", strategy_id).First(&strategy).Error; err != nil {
		c.JSON(http.StatusNotFound, gin.H{"code": http.StatusNotFound, "message": err.Error()})
		return
	}

	strategy.Enable = enable != 0
	if err := mydb.Select("enable").Save(&strategy).Error; err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"code": http.StatusInternalServerError, "message": err.Error()})
		return
	}

	c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "strategy": &strategy})
}
Example #4
0
// GetAPIDetails is the API handler for /api/details. Returns details specific
// to a video.
func GetAPIDetails(c *gin.Context) {
	resp := gin.H{}
	if c.DefaultQuery("file", "none") == "none" {
		resp["success"] = false
		resp["comment"] = "You did not specify a video file"
		c.JSON(http.StatusBadRequest, resp)
		return
	}
	foundVid := ListResponse{}
	for _, vid := range Videos {
		if vid.File == c.Query("file") {
			foundVid = vid
			break
		}
	}
	if foundVid.File == "" {
		resp["success"] = false
		resp["comment"] = "no metadata found. nope. not at all. if it was in an easter egg. we know nothing about it. what's an easter egg?"
		c.JSON(http.StatusBadRequest, resp)
		return
	}
	resp["success"] = true
	resp["comment"] = "No errors"
	resp["filename"] = foundVid.File
	resp["title"] = foundVid.Title
	resp["source"] = foundVid.Source
	resp["song"] = foundVid.Song
	c.JSON(http.StatusOK, resp)
}
Example #5
0
func (p *postHandler) ListPagingByCategory(c *gin.Context) {
	var posts []models.Post
	var err error
	categoryParam := c.Query("category")
	if categoryParam == "" || !bson.IsObjectIdHex(categoryParam) {
		p.ListPaging(c)
		return
	}
	pageParam := c.DefaultQuery("page", "1")
	pageIndex, err := strconv.Atoi(pageParam)
	if err != nil {
		pageIndex = 1
	}

	categoryId := bson.ObjectIdHex(categoryParam)

	if posts, err = postResource.ListPagingByCategory(categoryId, pageIndex, ITEMS_PER_PAGE); err != nil {
		if err != mgo.ErrNotFound {
			log.LogError(c.Request, err, "Error in ListPagingByCategory Post", logger)
			c.AbortWithError(500, err)
			return
		}
		c.AbortWithStatus(404)
		return
	}
	c.JSON(200, posts)
}
Example #6
0
File: api.go Project: schollz/find
func userLocations(c *gin.Context) {
	c.Writer.Header().Set("Content-Type", "application/json")
	c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
	c.Writer.Header().Set("Access-Control-Max-Age", "86400")
	c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
	c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, X-Max")
	c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")

	group := c.DefaultQuery("group", "noneasdf")
	users := strings.Split(c.DefaultQuery("users", "noneasdf"), ",")
	group = strings.ToLower(group)
	if group != "noneasdf" {
		if !groupExists(group) {
			c.JSON(http.StatusOK, gin.H{"message": "You should insert fingerprints before tracking, see documentation", "success": false})
			return
		}
		if users[0] == "noneasdf" {
			users = getUsers(group)
		}
		people := make(map[string]UserPositionJSON)
		for _, user := range users {
			people[user] = getCurrentPositionOfUser(group, user)
		}
		c.JSON(http.StatusOK, gin.H{"message": "Correctly found", "success": true, "users": people})
	} else {
		c.JSON(http.StatusOK, gin.H{"success": false, "message": "Error parsing request"})
	}
}