juju: github.com/wallyworld/juju/resource/api Index | Files | Directories

package api

import "github.com/wallyworld/juju/resource/api"


Package Files

download.go helpers.go http.go upload.go


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"

func API2CharmResource Uses

func API2CharmResource(apiInfo params.CharmResource) (charmresource.Resource, error)

API2CharmResource converts an API CharmResource struct into a charm resource.

func API2Resource Uses

func API2Resource(apiRes params.Resource) (resource.Resource, error)

API2Resource converts an API Resource struct into a resource.Resource.

func APIResult2ApplicationResources Uses

func APIResult2ApplicationResources(apiResult params.ResourcesResult) (resource.ApplicationResources, error)

APIResult2ApplicationResources converts a ResourcesResult into a resource.ApplicationResources.

func ApplicationResources2APIResult Uses

func ApplicationResources2APIResult(svcRes resource.ApplicationResources) params.ResourcesResult

func CharmResource2API Uses

func CharmResource2API(res charmresource.Resource) params.CharmResource

CharmResource2API converts a charm resource into a CharmResource struct.

func ExtractEndpointDetails Uses

func ExtractEndpointDetails(url *url.URL) (application, name string)

ExtractEndpointDetails pulls the endpoint wildcard values from the provided URL.

func NewEndpointPath Uses

func NewEndpointPath(application, name string) string

NewEndpointPath returns the API URL path for the identified resource.

func NewHTTPDownloadRequest Uses

func NewHTTPDownloadRequest(resourceName string) (*http.Request, error)

NewHTTPDownloadRequest creates a new HTTP download request for the given resource.

Intended for use on the client side.

func Resource2API Uses

func Resource2API(res resource.Resource) params.Resource

Resource2API converts a resource.Resource into a Resource struct.

func SendHTTPError Uses

func SendHTTPError(w http.ResponseWriter, err error)

SendHTTPError sends a JSON-encoded error response for errors encountered during processing.

func SendHTTPStatusAndJSON Uses

func SendHTTPStatusAndJSON(w http.ResponseWriter, statusCode int, response interface{})

SendHTTPStatusAndJSON sends an HTTP status code and a JSON-encoded response to a client.

type UploadRequest Uses

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 Uses

func NewUploadRequest(application, name, filename string, r io.ReadSeeker) (UploadRequest, error)

NewUploadRequest generates a new upload request for the given resource.

func (UploadRequest) HTTPRequest Uses

func (ur UploadRequest) HTTPRequest() (*http.Request, error)

HTTPRequest generates a new HTTP request.



Package api imports 13 packages (graph). Updated 2020-08-11. Refresh now. Tools for package owners.