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 {
	Object

	// 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 object creation, and management.

func (API) Destroy

func (h API) Destroy(w http.ResponseWriter, r *http.Request)

Destroy removes the object 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 objects for the given request. If multiple pages of objects 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 object in the given request. If the Accept header in the request matches the MIME type of the object then the content of the object itself is sent in the response. If the base request URL path is "/builds" then a list of the builds that the object was placed on will be returned. If there are multiple pages of builds then the paginator is encoded into the Link response header.

func (API) Store

func (h API) Store(w http.ResponseWriter, r *http.Request)

Store stores the object from the given request body. If any validation errors occur then these will be sent back in the JSON response. On success the object is sent in the JSON response.

type Object

type Object struct {
	web.Handler
	// contains filtered or unexported fields
}

Object is the base handler that provides shared logic for the UI and API handlers for object creation, and management.

func New

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

func (Object) DeleteModel

func (h Object) DeleteModel(r *http.Request) error

DeleteModel removes the object in the given request context from the database and the underlying block store.

func (Object) IndexWithRelations

func (h Object) IndexWithRelations(r *http.Request) ([]*object.Object, database.Paginator, error)

IndexWithRelations retrieves a slice of *object.Object models for the user in the given request context. All of the relations for each object will be loaded into each model we have. If any of the objects 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 objects.

func (Object) ShowWithRelations

func (h Object) ShowWithRelations(r *http.Request) (*object.Object, error)

ShowWithRelations retrieves the *object.Object model from the context of the given request. All of the relations for the object will be loaded into the model we have. If the object has a namespace bound to it, then the namespace's user will be loaded to the namespace.

func (Object) StoreModel

func (h Object) StoreModel(w http.ResponseWriter, r *http.Request) (*object.Object, object.Form, error)

StoreModel unmarshals the request's data into an object, validates it and stores it in the database. Upon success this will return the newly created object. This also returns the form for creating an object.

type UI

type UI struct {
	Object
}

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

func (UI) Create

func (h UI) Create(w http.ResponseWriter, r *http.Request)

Create serves the HTML response for creating and uploading objects via the web frontend.

func (UI) Destroy

func (h UI) Destroy(w http.ResponseWriter, r *http.Request)

Destroy removes the object in the given request context from the database. This redirects back to the object index if this was done from an individual object view, otherwise it redirects back to the request's referer.

func (UI) Index

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

Index serves the HTML response detailing the list of objects.

func (UI) Show

func (h UI) Show(w http.ResponseWriter, r *http.Request)

Show serves the HTML response for viewing an individual object in the given request. If the penultimate part of the request URL path is "download" then the object content is sent in the response body.

func (UI) Store

func (h UI) Store(w http.ResponseWriter, r *http.Request)

Store validates the form submitted in the given request for creating an object. If validation fails then the user is redirected back to the request referer, otherwise they are redirect back to the object index.

Jump to

Keyboard shortcuts

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