Golang Context.Query Examples

Golang Context.Query - 30 examples found. These are the top rated real world Golang examples of github.com/gin-gonic/gin.Context.Query extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
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[:]),
	})

}
Example #2
0
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,
	})
}
Example #3
0
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",
	})
}
Example #4
0
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{})
}
Example #5
0
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: ")

}
Example #6
0
func (ctr *AuthController) Show(c *gin.Context) {
	email := c.Query("email")
	c.JSON(200, gin.H{
		"status": "posted",
		"email":  email,
	})
}