Golang Context.XML Examples

Golang Context.XML - 8 examples found. These are the top rated real world Golang examples of github.com/gin-gonic/gin.Context.XML extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
func HandleQuery(query string, c *gin.Context) {
	rawQuery, err := base64.StdEncoding.DecodeString(query)
	if err == nil {
		query = string(rawQuery)
	}

	result, err := DB(c).Query(query)
	if err != nil {
		c.JSON(400, NewError(err))
		return
	}

	format := getQueryParam(c, "format")
	filename := getQueryParam(c, "filename")

	if filename == "" {
		filename = fmt.Sprintf("pgweb-%v.%v", time.Now().Unix(), format)
	}

	if format != "" {
		c.Writer.Header().Set("Content-disposition", "attachment;filename="+filename)
	}

	switch format {
	case "csv":
		c.Data(200, "text/csv", result.CSV())
	case "json":
		c.Data(200, "applicaiton/json", result.JSON())
	case "xml":
		c.XML(200, result)
	default:
		c.JSON(200, result)
	}
}
Example #2
0
func GetAddonsXML(ctx *gin.Context) {
	user := ctx.Params.ByName("user")
	repository := ctx.Params.ByName("repository")
	addons, err := getAddons(user, repository)
	if err != nil {
		ctx.AbortWithError(404, errors.New("Unable to retrieve the remote's addon.xml file."))
	}
	ctx.XML(200, addons)
}
Example #3
0
func (k controllers) DeleteStack(c *gin.Context) {
	r, errs := requests.NewDeleteStackRequest(c.Request)
	if len(errs.Errors) > 0 {
		c.AbortWithError(http.StatusBadRequest, errs)
	}

	userId, _ := c.Get("UserId")
	query := bson.M{"UserId": userId, "StackName": r.StackName}

	// enqueue job
	coll := k.Session.DB("nimbus").C("Stacks")
	err := coll.Update(query, bson.M{"$set": bson.M{"StackStatus": "DELETE_IN_PROGRESS"}})
	if err != nil {
		c.AbortWithError(http.StatusBadRequest, err)
	}

	requestId, _ := c.Get("RequestId")
	c.XML(http.StatusOK, res.NewDeleteStackResponse(requestId.(string)))
}
Example #4
0
func GetCC(c *gin.Context) {
	repo, err := store.GetRepoOwnerName(c,
		c.Param("owner"),
		c.Param("name"),
	)
	if err != nil {
		c.AbortWithStatus(404)
		return
	}

	builds, err := store.GetBuildList(c, repo)
	if err != nil || len(builds) == 0 {
		c.AbortWithStatus(404)
		return
	}

	cc := model.NewCC(repo, builds[0], "")
	c.XML(200, cc)
}
Example #5
0
File: badge.go Project: Ablu/drone
func GetCC(c *gin.Context) {
	repo, err := store.GetRepoOwnerName(c,
		c.Param("owner"),
		c.Param("name"),
	)
	if err != nil {
		c.AbortWithStatus(404)
		return
	}

	builds, err := store.GetBuildList(c, repo)
	if err != nil || len(builds) == 0 {
		c.AbortWithStatus(404)
		return
	}

	url := fmt.Sprintf("%s/%s/%d", httputil.GetURL(c.Request), repo.FullName, builds[0].Number)
	cc := model.NewCC(repo, builds[0], url)
	c.XML(200, cc)
}
Example #6
0
func (k controllers) DescribeStacks(c *gin.Context) {
	r, errs := requests.NewDescribeStacksRequest(c.Request)
	if len(errs.Errors) > 0 {
		c.AbortWithError(http.StatusBadRequest, errs)
	}

	userId, _ := c.Get("UserId")
	query := bson.M{"UserId": userId}
	// TODO: 404 error
	if r.StackName != "" {
		query["StackName"] = r.StackName
	}

	var stacks []models.Stack
	coll := k.Session.DB("nimbus").C("Stacks")
	err := coll.Find(query).Sort("StackName").All(&stacks)
	if err != nil {
		c.AbortWithError(http.StatusBadRequest, err)
	}

	requestId, _ := c.Get("RequestId")
	c.XML(http.StatusOK, res.NewDescribeStacksResponse(requestId.(string), stacks))
}