Documentation ¶
Index ¶
- Constants
- func API2CharmResource(apiInfo params.CharmResource) (charmresource.Resource, error)
- func API2Resource(apiRes params.Resource) (resource.Resource, error)
- func APIResult2ApplicationResources(apiResult params.ResourcesResult) (resource.ApplicationResources, error)
- func ApplicationResources2APIResult(svcRes resource.ApplicationResources) params.ResourcesResult
- func CharmResource2API(res charmresource.Resource) params.CharmResource
- func ExtractEndpointDetails(url *url.URL) (application, name string)
- func NewEndpointPath(application, name string) string
- func NewHTTPDownloadRequest(resourceName string) (*http.Request, error)
- func Resource2API(res resource.Resource) params.Resource
- func SendHTTPError(w http.ResponseWriter, err error)
- func SendHTTPStatusAndJSON(w http.ResponseWriter, statusCode int, response interface{})
- type UploadRequest
Constants ¶
const ( // ContentTypeRaw is the HTTP content-type value used for raw, unformattedcontent. ContentTypeRaw = "application/octet-stream" // ContentTypeJSON is the HTTP content-type value used for JSON content. ContentTypeJSON = "application/json" )
const ( // HeaderContentType is the header name for the type of a file upload. HeaderContentType = "Content-Type" // HeaderContentSha384 is the header name for the sha hash of a file upload. HeaderContentSha384 = "Content-Sha384" // HeaderContentLength is the header name for the length of a file upload. HeaderContentLength = "Content-Length" // HeaderContentDisposition is the header name for value that holds the filename. // The params are formatted according to RFC 2045 and RFC 2616 (see // mime.ParseMediaType and mime.FormatMediaType). HeaderContentDisposition = "Content-Disposition" )
const ( // MediaTypeFormData is the media type for file uploads (see // mime.FormatMediaType). MediaTypeFormData = "form-data" // QueryParamPendingID is the query parameter we use to send up the pending id. QueryParamPendingID = "pendingid" )
const FilenameParamForContentDispositionHeader = "filename"
FilenameParamForContentDispositionHeader is the name of the parameter that contains the name of the file being uploaded, see mime.FormatMediaType and RFC 1867 (http://tools.ietf.org/html/rfc1867):
The original local file name may be supplied as well, either as a 'filename' parameter either of the 'content-disposition: form-data' header or in the case of multiple files in a 'content-disposition: file' header of the subpart.
const ( // HTTPEndpointPath is the URL path, with substitutions, for // a resource request. HTTPEndpointPath = "/applications/%s/resources/%s" )
Variables ¶
This section is empty.
Functions ¶
func API2CharmResource ¶
func API2CharmResource(apiInfo params.CharmResource) (charmresource.Resource, error)
API2CharmResource converts an API CharmResource struct into a charm resource.
func API2Resource ¶
API2Resource converts an API Resource struct into a resource.Resource.
func APIResult2ApplicationResources ¶
func APIResult2ApplicationResources(apiResult params.ResourcesResult) (resource.ApplicationResources, error)
APIResult2ApplicationResources converts a ResourcesResult into a resource.ApplicationResources.
func ApplicationResources2APIResult ¶
func ApplicationResources2APIResult(svcRes resource.ApplicationResources) params.ResourcesResult
func CharmResource2API ¶
func CharmResource2API(res charmresource.Resource) params.CharmResource
CharmResource2API converts a charm resource into a CharmResource struct.
func ExtractEndpointDetails ¶
ExtractEndpointDetails pulls the endpoint wildcard values from the provided URL.
func NewEndpointPath ¶
NewEndpointPath returns the API URL path for the identified resource.
func NewHTTPDownloadRequest ¶
NewHTTPDownloadRequest creates a new HTTP download request for the given resource.
Intended for use on the client side.
func Resource2API ¶
Resource2API converts a resource.Resource into a Resource struct.
func SendHTTPError ¶
func SendHTTPError(w http.ResponseWriter, err error)
SendHTTPError sends a JSON-encoded error response for errors encountered during processing.
func SendHTTPStatusAndJSON ¶
func SendHTTPStatusAndJSON(w http.ResponseWriter, statusCode int, response interface{})
SendHTTPStatusAndJSON sends an HTTP status code and a JSON-encoded response to a client.
Types ¶
type UploadRequest ¶
type UploadRequest struct { // Application is the application ID. Application string // Name is the resource name. Name string // Filename is the name of the file as it exists on disk. Filename string // Size is the size of the uploaded data, in bytes. Size int64 // Fingerprint is the fingerprint of the uploaded data. Fingerprint charmresource.Fingerprint // PendingID is the pending ID to associate with this upload, if any. PendingID string // Content is the content to upload. Content io.ReadSeeker }
UploadRequest defines a single upload request.
func NewUploadRequest ¶
func NewUploadRequest(application, name, filename string, r io.ReadSeeker) (UploadRequest, error)
NewUploadRequest generates a new upload request for the given resource.
func (UploadRequest) HTTPRequest ¶
func (ur UploadRequest) HTTPRequest() (*http.Request, error)
HTTPRequest generates a new HTTP request.