Golang Context.Param Examples

Golang Context.Param - 30 examples found. These are the top rated real world Golang examples of github.com/gin-gonic/gin.Context.Param extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
func handleClaimantsClaimsDelete(c *gin.Context) {
	claimantID := c.Param("id")
	if strings.TrimSpace(claimantID) == "" {
		c.JSON(http.StatusBadRequest, "Bad Request")
		return
	}
	var claim stake.Claim
	decoder := json.NewDecoder(c.Request.Body)
	err := decoder.Decode(&claim)
	if err != nil {
		c.JSON(http.StatusBadRequest, "Bad Request")
		return
	}
	if strings.TrimSpace(claim.Claim) == "" || strings.TrimSpace(claim.Subject) == "" {
		c.JSON(http.StatusBadRequest, "Bad Request")
		return
	}

	if strings.TrimSpace(claimantID) == "" || strings.TrimSpace(claim.Claim) == "" || strings.TrimSpace(claim.Subject) == "" {
		c.JSON(http.StatusBadRequest, "Bad Request")
		return
	}
	result := deleteClaimantsClaimAboutSubject(claimantID, claim.Subject, claim.Claim)
	if result == success {
		c.JSON(http.StatusOK, result)
	} else {
		c.JSON(http.StatusNotFound, result)
	}
}
Example #2
0
func EditReviewFormR(c *gin.Context) {
	// dependency injection
	var (
		reviewStore = c.MustGet(ReviewStoreKey).(ReviewStore)
		user        = GetUser(c)
	)

	// only authenticated users can perform this action
	if !user.Authenticated() {
		c.AbortWithStatus(http.StatusUnauthorized)
		return
	}

	// fetch review
	id, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		c.AbortWithError(http.StatusBadRequest, err)
		return
	}

	review, err := reviewStore.GetReview(id)
	if err != nil {
		c.AbortWithError(http.StatusInternalServerError, err)
		return
	}

	c.HTML(http.StatusOK, "review-form.html", gin.H{
		"Action": "Edit",
		"User":   user,
		"Form":   review,
		"Errors": map[string]string{},
	})
}
Example #3
0
func (pc *NodeController) postDeleteNodeAction(c *gin.Context) {

	id := c.Param("id")

	node, err := models.NodeMapper.FetchOneById(id)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error_500.html", map[string]interface{}{
			"error": err,
		})
		return
	}

	if node == nil {
		c.HTML(http.StatusNotFound, "error_404.html", map[string]interface{}{
			"text": "Node not found",
		})
		return
	}

	if err := models.NodeMapper.Delete(node); err != nil {
		c.HTML(http.StatusInternalServerError, "error_500.html", map[string]interface{}{
			"error": err,
		})
		return
	}

	c.Redirect(http.StatusFound, "/nodes")
}
Example #4
0
func (self *EnvController) New(c *gin.Context) {
	username := self.CurrentUser(c)

	if username == "" {
		c.Redirect(http.StatusFound, "/")

		return
	}

	appName := c.Param("appName")
	key := c.PostForm("key")
	value := c.PostForm("value")

	err := env.Create(self.etcd, username, appName, key, value)

	if err != nil {
		fmt.Fprintf(os.Stderr, "%+v\n", err)

		c.HTML(http.StatusInternalServerError, "app.tmpl", gin.H{
			"alert":   true,
			"error":   true,
			"message": "Failed to add environment variable.",
		})

		return
	}

	c.Redirect(http.StatusSeeOther, "/apps/"+appName)
}
Example #5
0
func EditWhiskyFormR(c *gin.Context) {
	// dependency injection
	var (
		whiskyStore = c.MustGet(WhiskyStoreKey).(WhiskyStore)
		user        = GetUser(c)
	)

	// only authenticated users can perform this action
	if !user.Authenticated() {
		c.AbortWithStatus(http.StatusUnauthorized)
		return
	}

	// fetch whisky to edit
	id, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		c.AbortWithStatus(http.StatusBadRequest)
		return
	}

	whisky, err := whiskyStore.GetWhisky(id)
	if err != nil {
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.HTML(http.StatusOK, "whisky-form.html", gin.H{
		"Action": "Edit",
		"User":   user,
		"Form":   whisky,
		"Errors": map[string]string{},
	})
}
Example #6
0
func editNode(c *gin.Context) {
	nodename := c.Param("no")
	_, delete := c.GetQuery("delete")

	node, err := kubeclient.Get().Nodes().Get(nodename)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	b, err := json.Marshal(node)
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	var out bytes.Buffer
	err = json.Indent(&out, b, "", "  ")
	if err != nil {
		c.HTML(http.StatusInternalServerError, "error", gin.H{"error": err.Error()})
		return
	}

	c.HTML(http.StatusOK, "nodeEdit", gin.H{
		"title":   nodename,
		"objname": nodename,
		"json":    out.String(),
		"delete":  strconv.FormatBool(delete),
	})
}