handler

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type 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.

func (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.

func (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.

func (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.

func (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.

type 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.

func New

func New(h web.Handler, hasher *crypto.Hasher, store fs.Store, limit int64) Image

func (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.

func (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.

func (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.

func (Image) Index

func (h Image) Index(w http.ResponseWriter, r *http.Request)

Index serves the HTML response detailing the list of images.

func (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.

func (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.

func (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.

func (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.

func (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.

type UI

type UI struct {
	Image
}

UI is the handler for handling UI requests made for image creation, and management.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL