handler
v1.1.1
Documentation
pkg.go.dev ↗Types
API
type API struct {
Cron
// Prefix is the part of the URL under which the API is being served, for
// example "/api".
Prefix string
}
API is the handler for handling API requests made for cron job creation, and management.
API.Destroy
func (h API) Destroy(w http.ResponseWriter, r *http.Request)
Destroy removes the cron job in the given request context from the database. This serves no content in the response body.
API.Index
func (h API) Index(w http.ResponseWriter, r *http.Request)
Index serves the JSON encoded list of cron jobs for the given request. If multiple pages of cron jobs are returned then the database.Paginator is encoded in the Link response header.
API.Show
func (h API) Show(w http.ResponseWriter, r *http.Request)
Show serves up the JSON response for the cron job in the given request. If the base path of the URL is "/builds" then the builds submitted via the cron will be served up in the JSON response.
API.Store
func (h API) Store(w http.ResponseWriter, r *http.Request)
Store stores and submits the cron job from the given request body. If any validation errors occur then these will be sent back in the JSON response. On success the cron job is sent in the JSON response.
API.Update
func (h API) Update(w http.ResponseWriter, r *http.Request)
Update applies the changes in the given request body to the existing cron job in the database. If any validation errors occur then these will be sent back in the JSON response. On success the updated cron job is sent in the JSON response.
Cron
type Cron struct {
web.Handler
// contains filtered or unexported fields
}
Cron is the base handler that provides shared logic for the UI and API handlers for cron job creation, and management.
New
func New(h web.Handler) Cron
Cron.DeleteModel
func (h Cron) DeleteModel(r *http.Request) error
DeleteModel removes the cron in the given request context from the database.
Cron.IndexWithRelations
func (h Cron) IndexWithRelations(s *cron.Store, vals url.Values) ([]*cron.Cron, database.Paginator, error)
IndexWithRelations retrieves a slice of *cron.Cron models for the user in the given request context. All of the relations for each cron will be loaded into each model we have. If any of the crons have a bound namespace, then the namespace's user will be loaded too. A database.Paginator will also be returned if there are multiple pages of cron jobs.
Cron.ShowWithRelations
func (h Cron) ShowWithRelations(r *http.Request) (*cron.Cron, error)
ShowWithRelations retrieves the *cron.Cron model from the context of the given request. All of the relations for the cron will be loaded into the model we have. If the cron has a namespace bound to it, then the namespace's user will be loaded to the namespace.
Cron.StoreModel
func (h Cron) StoreModel(r *http.Request) (*cron.Cron, cron.Form, error)
StoreModel unmarshals the request's data into a cron job, validates it and stores it in the database. Upon success this will return the newly created cron. This also returns the form for creating a cron job.
Cron.UpdateModel
func (h Cron) UpdateModel(r *http.Request) (*cron.Cron, *cron.Form, error)
UpdateModel unmarshals the request's data into a cron job, validates it and updates the existing cron job in the database with the content in the form. Upon success the updated cron job is returned. This also returns the form for modifying a cron job.
UI
type UI struct {
Cron
}
UI is the handler for handling UI requests made for cron job creation, and management.
UI.Create
func (h UI) Create(w http.ResponseWriter, r *http.Request)
Create serves the HTML response for creating cron jobs via the web frontend.
UI.Destroy
func (h UI) Destroy(w http.ResponseWriter, r *http.Request)
Destroy removes the cron job in the given request context from the database. This redirects back to the cron index if this was done from an individual cron view, otherwise it redirects back to the request's referer.
UI.Edit
func (h UI) Edit(w http.ResponseWriter, r *http.Request)
Edit serves the HTML response for editing the cron job in the given request context.
UI.Index
func (h UI) Index(w http.ResponseWriter, r *http.Request)
Index serves the HTML response detailing the list of cron jobs.
UI.Show
func (h UI) Show(w http.ResponseWriter, r *http.Request)
Show serves the HTML response for viewing an individual cron job in the given request.
UI.Store
func (h UI) Store(w http.ResponseWriter, r *http.Request)
Store validates the form submitted in the given request for creating a cron job. If validation fails then the user is redirected back to the request referer, otherwise they are redirect back to the cron job index.
UI.Update
func (h UI) Update(w http.ResponseWriter, r *http.Request)
Update validates the form submitted in the given request for updating a cron job. If validation fails then the user is redirect back to the request's referer, otherwise they are redirected back to the updated cron job.