本文整理汇总了Golang中github.com/ardanlabs/kit/web.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:coralproject,项目名称:xenia,代码行数:34,代码来源:form_submission.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:34,代码来源:mask.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:27,代码来源:aggregations.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:57,代码来源:form_submission.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:13,代码来源:form_gallery.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:13,代码来源:mask.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:13,代码来源:relationship.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:13,代码来源:form.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:form_gallery.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:13,代码来源:view.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:form_submission.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:script.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:pattern.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:relationship.go
示例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
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:relationship.go
示例16: List
// List returns all the existing views in the system.
// 200 Success, 404 Not Found, 500 Internal
func (viewHandle) List(c *web.Context) error {
views, err := view.GetAll(c.SessionID, c.Ctx["DB"].(*db.DB))
if err != nil {
if err == view.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(views, http.StatusOK)
return nil
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:view.go
示例17: List
// List returns all the existing patterns in the system.
// 200 Success, 404 Not Found, 500 Internal
func (patternHandle) List(c *web.Context) error {
ps, err := pattern.GetAll(c.SessionID, c.Ctx["DB"].(*db.DB))
if err != nil {
if err == pattern.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(ps, http.StatusOK)
return nil
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:pattern.go
示例18: Retrieve
// Retrieve returns the specified View from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (viewHandle) Retrieve(c *web.Context) error {
v, err := view.GetByName(c.SessionID, c.Ctx["DB"].(*db.DB), c.Params["name"])
if err != nil {
if err == view.ErrNotFound {
err = web.ErrNotFound
}
return err
}
c.Respond(v, http.StatusOK)
return nil
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:view.go
示例19: UpdateStatus
// UpdateStatus updates the status of a form in the store.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (formHandle) UpdateStatus(c *web.Context) error {
id := c.Params["id"]
status := c.Params["status"]
f, err := form.UpdateStatus(c.SessionID, c.Ctx["DB"].(*db.DB), id, status)
if err != nil {
return err
}
c.Respond(f, http.StatusOK)
return nil
}
开发者ID:coralproject,项目名称:xenia,代码行数:14,代码来源:form.go
示例20: Upsert
// Upsert inserts or updates the posted Relationship document into the database.
// 204 SuccessNoContent, 400 Bad Request, 404 Not Found, 500 Internal
func (relationshipHandle) Upsert(c *web.Context) error {
var rel relationship.Relationship
if err := json.NewDecoder(c.Request.Body).Decode(&rel); err != nil {
return err
}
if err := relationship.Upsert(c.SessionID, c.Ctx["DB"].(*db.DB), &rel); err != nil {
return err
}
c.Respond(nil, http.StatusNoContent)
return nil
}
开发者ID:coralproject,项目名称:xenia,代码行数:15,代码来源:relationship.go
注:本文中的github.com/ardanlabs/kit/web.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论