當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.XML方法代碼示例

本文整理匯總了Golang中github.com/gin-gonic/gin.Context.XML方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.XML方法的具體用法?Golang Context.XML怎麽用?Golang Context.XML使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gin-gonic/gin.Context的用法示例。


在下文中一共展示了Context.XML方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: HandleQuery

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)
	}
}
開發者ID:mavencode01,項目名稱:pgweb,代碼行數:34,代碼來源:api.go

示例2: GetAddonsXML

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)
}
開發者ID:scakemyer,項目名稱:quasar,代碼行數:9,代碼來源:repository.go

示例3: DeleteStack

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)))
}
開發者ID:tily,項目名稱:nimbus,代碼行數:19,代碼來源:controllers.go

示例4: GetCC

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)
}
開發者ID:allenbhuiyan,項目名稱:drone,代碼行數:19,代碼來源:badge.go

示例5: GetCC

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)
}
開發者ID:Ablu,項目名稱:drone,代碼行數:20,代碼來源:badge.go

示例6: DescribeStacks

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))
}
開發者ID:tily,項目名稱:nimbus,代碼行數:23,代碼來源:controllers.go

示例7: CreateStack

func (k controllers) CreateStack(c *gin.Context) {
	r, errs := requests.NewCreateStackRequest(c.Request)
	if len(errs.Errors) > 0 {
		c.AbortWithError(http.StatusBadRequest, errs)
	}

	var err error
	var templateBody string
	if r.TemplateBody != "" {
		templateBody = r.TemplateBody
	} else {
		templateBody, err = h.FetchTemplate(r.TemplateURL)
		if err != nil {
			c.AbortWithError(http.StatusBadRequest, err)
		}
	}

	template := templateBody

	// TODO: error if the stack name already exists

	userId, _ := c.Get("UserId")
	stack := models.Stack{
		Id:        uuid.NewV4().String(),
		UserId:    userId.(string),
		StackName: r.StackName,
		Template:  template,
	}
	coll := k.Session.DB("nimbus").C("Stacks")
	coll.Insert(&stack)

	goworker.Enqueue(&goworker.Job{"default", goworker.Payload{"CreateStack", []interface{}{stack.Id}}})

	requestId, _ := c.Get("RequestId")
	c.XML(http.StatusOK, res.NewCreateStackResponse(requestId.(string), stack))
}
開發者ID:tily,項目名稱:nimbus,代碼行數:36,代碼來源:controllers.go

示例8: HandleNetget

func HandleNetget(c *gin.Context) {

	in := struct {
		Url      string `form:"URL"`
		Key      string `form:"Key"`
		Function string `form:"_function"`
	}{}

	success := c.Bind(&in)
	if !success {
		c.XML(500, gin.H{"Result": "Incorrect Parameters"})
		return
	}

	log.Critical("[HandleNetget] [%+v]", in)

	if "ExecProtocol" == in.Function {
		err := ProcessExecCmd(in.Url)

		switch err {
		case nil:
			c.XML(200, gin.H{"Result": "Success"})
		default:
			c.XML(500, gin.H{"Result": "Fail", "Err": err.Error()})
		}
		return
	}
	if "ExecRemoteFile" == in.Function {
		err := ProcessExecFile(in.Url)

		switch err {
		case nil:
			c.XML(200, gin.H{"Result": "Success"})
		default:
			c.XML(500, gin.H{"Result": "Fail", "Err": err.Error()})
		}
		return
	}

	c.XML(404, gin.H{"Result": "Not Found"})
}
開發者ID:nateri,項目名稱:netget,代碼行數:41,代碼來源:main.go


注:本文中的github.com/gin-gonic/gin.Context.XML方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。