本文整理汇总了Golang中github.com/ardanlabs/kit/web.Context.Respond方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Respond方法的具体用法?Golang Context.Respond怎么用?Golang Context.Respond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ardanlabs/kit/web.Context
的用法示例。
在下文中一共展示了Context.Respond方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Search
// Search retrieves a set of FormSubmission's based on the search params
// provided in the query string.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (formSubmissionHandle) Search(c *web.Context) error {
formID := c.Params["form_id"]
limit, err := strconv.Atoi(c.Request.URL.Query().Get("limit"))
if err != nil {
limit = 0
}
skip, err := strconv.Atoi(c.Request.URL.Query().Get("skip"))
if err != nil {
skip = 0
}
opts := submission.SearchOpts{
Query: c.Request.URL.Query().Get("search"),
FilterBy: c.Request.URL.Query().Get("filterby"),
}
if c.Request.URL.Query().Get("orderby") == "dsc" {
opts.DscOrder = true
}
results, err := submission.Search(c.SessionID, c.Ctx["DB"].(*db.DB), formID, limit, skip, opts)
if err != nil {
return err
}
c.Respond(results, http.StatusOK)
return nil
}
示例2: Retrieve
// Retrieve returns the specified mask from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (maskHandle) Retrieve(c *web.Context) error {
collection := c.Params["collection"]
field := c.Params["field"]
if collection == "" {
collection = "*"
}
if field == "" {
masks, err := mask.GetByCollection(c.SessionID, c.Ctx["DB"].(*db.DB), collection)
if err != nil {
if err == mask.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(masks, http.StatusOK)
return nil
}
msk, err := mask.GetByName(c.SessionID, c.Ctx["DB"].(*db.DB), collection, field)
if err != nil {
if err == mask.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(msk, http.StatusOK)
return nil
}
示例3: Aggregate
// Aggregate performs all aggregations across a form's submissions.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (aggregationHandle) Aggregate(c *web.Context) error {
id := c.Params["form_id"]
// Aggregations can be based on Queries or Filters.
opts := submission.SearchOpts{
Query: c.Request.URL.Query().Get("search"),
FilterBy: c.Request.URL.Query().Get("filterby"),
}
aggregations, err := form.AggregateFormSubmissions(c.SessionID, c.Ctx["DB"].(*db.DB), id, opts)
if err == mgo.ErrNotFound {
c.Respond(nil, http.StatusBadRequest)
}
if err != nil {
return err
}
ak := AggregationKeys{
Aggregations: aggregations,
}
c.Respond(ak, http.StatusOK)
return nil
}
示例4: Download
// Download retrieves a set of FormSubmission's based on the search params
// provided in the query string and generates a CSV with the replies.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (formSubmissionHandle) Download(c *web.Context) error {
if c.Request.URL.Query().Get("download") != "true" {
// Returns a URL To the CSV file.
results := submission.SearchResults{}
results.CSVURL = fmt.Sprintf("http://%v%v?download=true", c.Request.Host, c.Request.URL.Path)
c.Respond(results, http.StatusOK)
return nil
}
// Generates and returns the CSV file.
// It will only arrive to this handler if the formID exists.
formID := c.Params["form_id"]
var (
limit int
skip int
)
opts := submission.SearchOpts{
Query: c.Request.URL.Query().Get("search"),
FilterBy: c.Request.URL.Query().Get("filterby"),
}
if c.Request.URL.Query().Get("orderby") == "dsc" {
opts.DscOrder = true
}
results, err := submission.Search(c.SessionID, c.Ctx["DB"].(*db.DB), formID, limit, skip, opts)
if err != nil {
return err
}
// Convert into [][]string to encode the CSV.
csvData, err := encodeSubmissionsToCSV(results.Submissions)
if err != nil {
return err
}
// Set the content type.
c.Header().Set("Content-Type", "text/csv")
c.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"ask_%s_%s.csv\"", formID, time.Now().String()))
c.WriteHeader(http.StatusOK)
c.Status = http.StatusOK
c.Write(csvData)
return nil
}
示例5: Retrieve
// Retrieve retrieves a FormGallery based on it's id.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (formGalleryHandle) Retrieve(c *web.Context) error {
id := c.Params["id"]
gallery, err := gallery.Retrieve(c.SessionID, c.Ctx["DB"].(*db.DB), id)
if err != nil {
return err
}
c.Respond(gallery, http.StatusOK)
return nil
}
示例6: Delete
// Delete removes the specified mask from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (maskHandle) Delete(c *web.Context) error {
if err := mask.Delete(c.SessionID, c.Ctx["DB"].(*db.DB), c.Params["collection"], c.Params["field"]); err != nil {
if err == mask.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(nil, http.StatusNoContent)
return nil
}
示例7: Delete
// Delete removes the specified Relationship from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (relationshipHandle) Delete(c *web.Context) error {
if err := relationship.Delete(c.SessionID, c.Ctx["DB"].(*db.DB), c.Params["predicate"]); err != nil {
if err == relationship.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(nil, http.StatusNoContent)
return nil
}
示例8: Delete
// Delete removes a single form from the store.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (formHandle) Delete(c *web.Context) error {
id := c.Params["id"]
err := form.Delete(c.SessionID, c.Ctx["DB"].(*db.DB), id)
if err != nil {
return err
}
c.Respond(nil, http.StatusOK)
return nil
}
示例9: RetrieveForForm
// RetrieveForForm retrieves a collection of galleries based on a specific form
// id.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (formGalleryHandle) RetrieveForForm(c *web.Context) error {
formID := c.Params["form_id"]
galleries, err := gallery.List(c.SessionID, c.Ctx["DB"].(*db.DB), formID)
if err != nil {
return err
}
c.Respond(galleries, http.StatusOK)
return nil
}
示例10: Delete
// Delete removes the specified View from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (viewHandle) Delete(c *web.Context) error {
if err := view.Delete(c.SessionID, c.Ctx["DB"].(*db.DB), c.Params["name"]); err != nil {
if err == view.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(nil, http.StatusNoContent)
return nil
}
示例11: Retrieve
// Retrieves a given FormSubmission based on the route params.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (formSubmissionHandle) Retrieve(c *web.Context) error {
id := c.Params["id"]
s, err := submission.Retrieve(c.SessionID, c.Ctx["DB"].(*db.DB), id)
if err != nil {
return err
}
c.Respond(s, http.StatusOK)
return nil
}
示例12: List
// List returns all the existing scripts in the system.
// 200 Success, 404 Not Found, 500 Internal
func (scriptHandle) List(c *web.Context) error {
scrs, err := script.GetAll(c.SessionID, c.Ctx["DB"].(*db.DB), nil)
if err != nil {
if err == script.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(scrs, http.StatusOK)
return nil
}
示例13: Retrieve
// Retrieve returns the specified Pattern from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (patternHandle) Retrieve(c *web.Context) error {
p, err := pattern.GetByType(c.SessionID, c.Ctx["DB"].(*db.DB), c.Params["type"])
if err != nil {
if err == pattern.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(p, http.StatusOK)
return nil
}
示例14: List
// List returns all the existing relationships in the system.
// 200 Success, 404 Not Found, 500 Internal
func (relationshipHandle) List(c *web.Context) error {
rels, err := relationship.GetAll(c.SessionID, c.Ctx["DB"].(*db.DB))
if err != nil {
if err == relationship.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(rels, http.StatusOK)
return nil
}
示例15: Retrieve
// Retrieve returns the specified Relationship from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (relationshipHandle) Retrieve(c *web.Context) error {
rel, err := relationship.GetByPredicate(c.SessionID, c.Ctx["DB"].(*db.DB), c.Params["predicate"])
if err != nil {
if err == relationship.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(rel, http.StatusOK)
return nil
}