handler
v1.1.1
Documentation
pkg.go.dev ↗Types
API
type API struct {
Image
// 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 image creation, and management.
API.Destroy
func (h API) Destroy(w http.ResponseWriter, r *http.Request)
Destroy removes the image in the given request context from the database and underlying block store. 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 images for the given request. If multiple pages of images 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 image in the given request. If the Accept header in the request is "application/x-qemu-disk" then the content of the image itself is sent in the response.
API.Store
func (h API) Store(w http.ResponseWriter, r *http.Request)
Store stores the image from the given request body. If any validation errors occur then these will be sent back in the JSON response. On success the image is sent in the JSON response.
Image
type Image struct {
web.Handler
// contains filtered or unexported fields
}
Image is the base handler that provides shared logic for the UI and API handlers for image creation, and management.
New
func New(h web.Handler, hasher *crypto.Hasher, store fs.Store, limit int64) Image
Image.Create
func (h Image) Create(w http.ResponseWriter, r *http.Request)
Create serves the HTML response for creating and uploading images via the web frontend.
Image.DeleteModel
func (h Image) DeleteModel(r *http.Request) error
DeleteModel removes the image in the given request context from the database and the underlying block store.
Image.Destroy
func (h Image) Destroy(w http.ResponseWriter, r *http.Request)
Destroy removes the image in the given request context from the database. This redirects back to the image index if this was done from an individual image view, otherwise it redirects back to the request's referer.
Image.Index
func (h Image) Index(w http.ResponseWriter, r *http.Request)
Index serves the HTML response detailing the list of images.
Image.IndexWithRelations
func (h Image) IndexWithRelations(r *http.Request) ([]*image.Image, database.Paginator, error)
IndexWithRelations retrieves a slice of *image.Image models for the user in the given request context. All of the relations for each image will be loaded into each model we have. If any of the images 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 images.
Image.Show
func (h Image) Show(w http.ResponseWriter, r *http.Request)
Show serves the HTML response for viewing an individual image in the given request.
Image.ShowWithRelations
func (h Image) ShowWithRelations(r *http.Request) (*image.Image, error)
ShowWithRelations retrieves the *image.Image model from the context of the given request. All of the relations for the image will be loaded into the model we have. If the image has a namespace bound to it, then the namespace's user will be loaded to the namespace.
Image.Store
func (h Image) Store(w http.ResponseWriter, r *http.Request)
Store validates the form submitted in the given request for creating an image. If validation fails then the user is redirected back to the request referer, otherwise they are redirect back to the image index.
Image.StoreModel
func (h Image) StoreModel(w http.ResponseWriter, r *http.Request) (*image.Image, image.Form, error)
StoreModel unmarshals the request's data into an image, validates it and stores it in the database. Upon success this will return the newly created image. This also returns the form for creating an image.
UI
type UI struct {
Image
}
UI is the handler for handling UI requests made for image creation, and management.