当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Query方法代码示例

本文整理汇总了Golang中github.com/gin-gonic/gin.Context.Query方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Query方法的具体用法?Golang Context.Query怎么用?Golang Context.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/gin-gonic/gin.Context的用法示例。


在下文中一共展示了Context.Query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: executeAction

func executeAction(c *gin.Context) {

	var args []string
	for i := 0; i < 10; i++ {
		operation := c.Query(strconv.Itoa(i))
		if len(operation) > 0 {
			args = append(args, operation)
		} else {
			break
		}
	}
	fmt.Println(args)
	//Turn LED Blue to Indicate event.
	setRGB([]string{"0", "255", "255"})
	time.Sleep(1 * time.Second)

	statusCode := 200
	out, err := exec.Command(command, args...).Output()
	if err != nil {
		statusCode = 500
		//Flash LED red to indicate Error
		setRGB([]string{"255", "0", "0"})
		time.Sleep(1 * time.Second)
	}

	//Turn LED back to green
	setRGB([]string{"0", "255", "0"})

	c.JSON(statusCode, gin.H{
		"status": "received",
		"output": string(out[:]),
	})

}
开发者ID:prizyp,项目名称:go-wink,代码行数:34,代码来源:go-wink.go

示例2: getMonitoringAction

func (pc *MonitoringController) getMonitoringAction(c *gin.Context) {

	host := c.Query("host")
	stat := c.DefaultQuery("stat", "all")
	t := c.DefaultQuery("time", "last1800")

	hosts, err := models.NodeMapper.FetchAll()
	if err != nil {
		panic(err)
	}

	var graphs models.Graphs

	var target []string
	if host != "" {
		target = []string{host}
	} else {
		for _, h := range hosts {
			target = append(target, h.Hostname)
		}
	}

	if graphs, err = models.GraphMapper.FetchAll(target, stat, t); err != nil {
		panic(err)
	}

	c.HTML(http.StatusOK, "monitoring_show.html", map[string]interface{}{
		"host":   host,
		"stat":   stat,
		"time":   t,
		"hosts":  hosts,
		"stats":  models.GraphStats,
		"graphs": graphs,
	})
}
开发者ID:KarhuTeam,项目名称:Karhu,代码行数:35,代码来源:monitoring_controller.go

示例3: delete

func delete(c *gin.Context) {
	series := c.Query("series")
	if series == "" {
		c.JSON(http.StatusOK, gin.H{
			"status":  "error",
			"message": "series need",
		})
		return
	}

	err := db.Batch(func(tx *bolt.Tx) error {
		err := tx.DeleteBucket([]byte(series))
		if err != nil {
			return err
		}

		return nil
	})

	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"status":  "error",
			"message": err.Error(),
		})

		return
	}

	c.JSON(http.StatusOK, gin.H{
		"status": "ok",
	})
}
开发者ID:semihalev,项目名称:tsdb,代码行数:32,代码来源:main.go

示例4: deployReplicasModify

func deployReplicasModify(ginCtx *gin.Context) {
	name := ginCtx.Params.ByName("name")
	num := ginCtx.Params.ByName("num")
	force := ginCtx.Query("force")
	fs := false
	if force == "true" {
		fs = true
	}
	glog.Info("scaling %s to %d instances", name, num)
	replicas, err := strconv.Atoi(num)
	if err != nil {
		glog.Errorf("Could not change instances for %s, caused by %s", name, err)
		ginCtx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		ginCtx.Error(err)
		return
	}
	var beReq = &ScaleRequest{Name: name, Replicas: replicas, Force: fs}

	_, err = se.Backend.Scale(beReq)
	if err != nil {
		glog.Errorf("Could not change instances for %s, caused by: %s", name, err.Error())
		ginCtx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		ginCtx.Error(err)
		return
	}
	ginCtx.JSON(http.StatusOK, gin.H{})
}
开发者ID:zalando,项目名称:chimp,代码行数:27,代码来源:handler.go

示例5: Post

func (this *CCEvent) Post(c *gin.Context) {
	this.Load()
	c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
	c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type,Token")
	program_id := c.Query("program_id")
	user_id := c.Query("created_by")

	if user_id != "" {
		_, err := userHandler.FetchUserById(user_id)
		if err != nil {
			fmt.Println("User id not exist: ")
			panic(err)
			return
		}
	}
	if program_id != "" {
		_, err := programHandler.FetchProgram(program_id)
		if err != nil {
			fmt.Println("Program id not exist: ")
			panic(err)
			return
		}
	}
	err := eventHandler.AddEvent(c)
	if err != nil {
		fmt.Println("Data insertion failed ", err.Error())
		return
	}
	fmt.Println("Data Inserted Successfully: ")

}
开发者ID:naikparag,项目名称:lego,代码行数:31,代码来源:event.go

示例6: Show

func (ctr *AuthController) Show(c *gin.Context) {
	email := c.Query("email")
	c.JSON(200, gin.H{
		"status": "posted",
		"email":  email,
	})
}
开发者ID:MasashiSalvador57f,项目名称:bookify,代码行数:7,代码来源:auth.go

示例7: GetCommit

func GetCommit(c *gin.Context) {
	repo := session.Repo(c)

	parsed, err := token.ParseRequest(c.Request, func(t *token.Token) (string, error) {
		return repo.Hash, nil
	})
	if err != nil {
		c.AbortWithError(http.StatusBadRequest, err)
		return
	}
	if parsed.Text != repo.FullName {
		c.AbortWithStatus(http.StatusUnauthorized)
		return
	}

	commit := c.Param("sha")
	branch := c.Query("branch")
	if len(branch) == 0 {
		branch = repo.Branch
	}

	build, err := store.GetBuildCommit(c, repo, commit, branch)
	if err != nil {
		c.AbortWithError(http.StatusNotFound, err)
		return
	}

	c.JSON(http.StatusOK, build)
}
开发者ID:allenbhuiyan,项目名称:drone,代码行数:29,代码来源:gitlab.go

示例8: GetAPIDetails

// 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)
}
开发者ID:thehowl,项目名称:openingsgo,代码行数:31,代码来源:routers-api.go

示例9: handleRequestBalance

func handleRequestBalance(context *gin.Context) {
	user_id := context.Query("user")

	if user_id == "" {
		context.String(422, "User is empty!")
		return
	}

	id, err := strconv.ParseUint(user_id, 10, 64)

	if err != nil {
		context.String(422, "User is not valid!")
		return
	}

	var u User

	db := context.MustGet("DBM").(*sql.DB)
	tx, err := db.Begin()
	checkErr(err)
	defer tx.Rollback()

	user := u.Get(id, tx)

	if user.Id == 0 {
		context.String(422, "User is not valid!")
		return
	}

	tx.Commit()

	context.JSON(200, gin.H{
		"balance": user.Amount,
	})
}
开发者ID:gfdev,项目名称:sandbox,代码行数:35,代码来源:main.go

示例10: convertByURLHandler

// convertByURLHandler is the main v1 API handler for converting a HTML to a PDF
// via a GET request. It can either return a JSON string indicating that the
// output of the conversion has been uploaded or it can return the output of
// the conversion to the client (raw bytes).
func convertByURLHandler(c *gin.Context) {
	s := c.MustGet("statsd").(*statsd.Client)
	r, ravenOk := c.Get("sentry")

	url := c.Query("url")
	if url == "" {
		c.AbortWithError(http.StatusBadRequest, ErrURLInvalid).SetType(gin.ErrorTypePublic)
		s.Increment("invalid_url")
		return
	}

	ext := c.Query("ext")

	source, err := converter.NewConversionSource(url, nil, ext)
	if err != nil {
		s.Increment("conversion_error")
		if ravenOk {
			r.(*raven.Client).CaptureError(err, map[string]string{"url": url})
		}
		c.Error(err)
		return
	}

	conversionHandler(c, *source)
}
开发者ID:cemoulto,项目名称:athenapdf,代码行数:29,代码来源:handlers.go

示例11: convertByFileHandler

func convertByFileHandler(c *gin.Context) {
	s := c.MustGet("statsd").(*statsd.Client)
	r, ravenOk := c.Get("sentry")

	file, header, err := c.Request.FormFile("file")
	if err != nil {
		c.AbortWithError(http.StatusBadRequest, ErrFileInvalid).SetType(gin.ErrorTypePublic)
		s.Increment("invalid_file")
		return
	}

	ext := c.Query("ext")

	source, err := converter.NewConversionSource("", file, ext)
	if err != nil {
		s.Increment("conversion_error")
		if ravenOk {
			r.(*raven.Client).CaptureError(err, map[string]string{"url": header.Filename})
		}
		c.Error(err)
		return
	}

	conversionHandler(c, *source)
}
开发者ID:cemoulto,项目名称:athenapdf,代码行数:25,代码来源:handlers.go

示例12: ListPagingByCategory

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)
}
开发者ID:jeff235255,项目名称:forum,代码行数:27,代码来源:post.go

示例13: GetArticles

func (ctrl *Controller) GetArticles(c *gin.Context) {
	id := repository.MaxArticleID
	if c.Query("olderthan") != "" {
		olderthan, err := strconv.Atoi(c.Query("olderthan"))
		if err != nil {
			ctrl.Logger.Log("msg", "Can't convert olderthan id to int", "err", err.Error())
			c.AbortWithStatus(http.StatusInternalServerError)
		}
		id = olderthan
	}

	articles, err := ctrl.Repository.FindArticlesOlderThan(id, ArticlesPerPage)
	if err != nil {
		if err == repository.ErrArticleNotFound {
			ctrl.Logger.Log("msg", "Can't find olderthan article", "id", id)
			status := http.StatusNotFound
			c.JSON(status, gin.H{
				"message":     http.StatusText(status),
				"status_code": status,
			})
		}

		ctrl.Logger.Log("msg", "Failed to get olderthan articles", "id", id, "err", err)
		c.AbortWithStatus(http.StatusInternalServerError)
	}

	c.JSON(http.StatusOK, marshaller.Articles(articles))
}
开发者ID:MetalMatze,项目名称:Krautreporter-API,代码行数:28,代码来源:articles_controller.go

示例14: Home

func Home(c *gin.Context) {
	ac := getAppConfig(c)

	hostPortList := make([]string, 0, 100)
	for k, _ := range ac.Instances {
		hostPortList = append(hostPortList, k)
	}

	instanceID := c.Query("instance")
	if _, ok := ac.Instances[instanceID]; ok == false {
		instanceID = hostPortList[0]
	}
	targetSource := ac.Instances[instanceID].Source

	infoErr := ""
	hasInfoErr := false
	statsInfo, err := getStatsInfo(targetSource)
	if err != nil {
		infoErr = err.Error()
		hasInfoErr = true
	}
	structedStatsInfo := statsMap2Struct(statsInfo)
	structedStatsInfo.InstanceID = instanceID
	structedStatsInfo.Source = targetSource

	c.HTML(http.StatusOK, "index.html", gin.H{
		"HasInfoErr": hasInfoErr,
		"InfoErr":    infoErr,
		"Instances":  ac.Instances,
		"StatsInfo":  structedStatsInfo,
	})
}
开发者ID:picasso250,项目名称:memcached-ui,代码行数:32,代码来源:controller.go

示例15: ParseRGB

func ParseRGB(c *gin.Context) (colorful.Color, error) {
	rgb := map[string]float64{
		"r": 0,
		"g": 0,
		"b": 0,
	}
	var err error
	for k, v := range rgb {
		if v, err = strconv.ParseFloat(c.Query(k), 64); err != nil {
			err = errors.New("failed to parse color")
			return colorful.Color{}, err
		}
		if v < 0 || v > 255 {
			err = errors.New("invalid color value. must be <= 0 or >= 255")
			return colorful.Color{}, err
		}
		rgb[k] = v
	}
	color := colorful.Color{
		rgb["r"] / 255.0,
		rgb["g"] / 255.0,
		rgb["b"] / 255.0,
	}
	return color, nil
}
开发者ID:Nesurion,项目名称:milight-daemon,代码行数:25,代码来源:parser.go


注:本文中的github.com/gin-gonic/gin.Context.Query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。