updown

package
v0.0.0-...-63cd2eb Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const APIName = "upload_download"

APIName is the name of the API as defined in the design.

View Source
const APIVersion = "0.0.1"

APIVersion is the version of the API as defined in the design.

View Source
const ServiceName = "updown"

ServiceName is the name of the service as defined in the design. This is the same value that is set in the endpoint request contexts under the ServiceKey key.

Variables

View Source
var MethodNames = [2]string{"upload", "download"}

MethodNames lists the service method names as defined in the design. These are the same values that are set in the endpoint request contexts under the MethodKey key.

Functions

func MakeInternalError

func MakeInternalError(err error) *goa.ServiceError

MakeInternalError builds a goa.ServiceError from an error.

func MakeInvalidFilePath

func MakeInvalidFilePath(err error) *goa.ServiceError

MakeInvalidFilePath builds a goa.ServiceError from an error.

func MakeInvalidMediaType

func MakeInvalidMediaType(err error) *goa.ServiceError

MakeInvalidMediaType builds a goa.ServiceError from an error.

func MakeInvalidMultipartRequest

func MakeInvalidMultipartRequest(err error) *goa.ServiceError

MakeInvalidMultipartRequest builds a goa.ServiceError from an error.

func NewDownloadEndpoint

func NewDownloadEndpoint(s Service) goa.Endpoint

NewDownloadEndpoint returns an endpoint function that calls the method "download" of service "updown".

func NewUploadEndpoint

func NewUploadEndpoint(s Service) goa.Endpoint

NewUploadEndpoint returns an endpoint function that calls the method "upload" of service "updown".

Types

type Client

type Client struct {
	UploadEndpoint   goa.Endpoint
	DownloadEndpoint goa.Endpoint
}

Client is the "updown" service client.

func NewClient

func NewClient(upload, download goa.Endpoint) *Client

NewClient initializes a "updown" service client given the endpoints.

func (*Client) Download

func (c *Client) Download(ctx context.Context, p string) (res *DownloadResult, resp io.ReadCloser, err error)

Download calls the "download" endpoint of the "updown" service. Download may return the following errors:

  • "invalid_file_path" (type *goa.ServiceError): Could not locate file for download
  • "internal_error" (type *goa.ServiceError): Fault while processing download.
  • error: internal error

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, p *UploadPayload, req io.ReadCloser) (err error)

Upload calls the "upload" endpoint of the "updown" service. Upload may return the following errors:

  • "invalid_media_type" (type *goa.ServiceError): Error returned when the Content-Type header does not define a multipart request.
  • "invalid_multipart_request" (type *goa.ServiceError): Error returned when the request body is not a valid multipart content.
  • "internal_error" (type *goa.ServiceError): Fault while processing upload.
  • error: internal error

type DownloadResponseData

type DownloadResponseData struct {
	// Result is the method result.
	Result *DownloadResult
	// Body streams the HTTP response body.
	Body io.ReadCloser
}

DownloadResponseData holds both the result and the HTTP response body reader of the "download" method.

type DownloadResult

type DownloadResult struct {
	// Length is the downloaded content length in bytes.
	Length int64
}

DownloadResult is the result type of the updown service download method.

type Endpoints

type Endpoints struct {
	Upload   goa.Endpoint
	Download goa.Endpoint
}

Endpoints wraps the "updown" service endpoints.

func NewEndpoints

func NewEndpoints(s Service) *Endpoints

NewEndpoints wraps the methods of the "updown" service with endpoints.

func (*Endpoints) Use

func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint)

Use applies the given middleware to all the "updown" service endpoints.

type Service

type Service interface {
	// Upload implements upload.
	Upload(context.Context, *UploadPayload, io.ReadCloser) (err error)

	// If body implements [io.WriterTo], that implementation will be used instead.
	// Consider [goa.design/goa/v3/pkg.SkipResponseWriter] to adapt existing
	// implementations.
	Download(context.Context, string) (res *DownloadResult, body io.ReadCloser, err error)
}

Service updown demonstrates how to implement upload and download of files in Goa without having to load the entire content in memory first. The upload method uses SkipRequestBodyEncodeDecode to delegate reading the HTTP request body to the service logic. This alleviates the need for loading the full body content in memory first to decode it into a data structure. Note that using SkipRequestBodyDecode is incompatible with gRPC and can only be used on methods that only define a HTTP transport mapping. This example implementation leverages package "mime/multipart" to read the request body. Similarly the download method uses SkipResponseBodyEncodeDecode to stream the file to the client without requiring to load the complete content in memory first. As with SkipRequestBodyDecode using SkipResponseBodyEncodeDecode is incompatible with gRPC.

type UploadPayload

type UploadPayload struct {
	// Content-Type header, must define value for multipart boundary.
	ContentType string
	// Dir is the relative path to the file directory where the uploaded content is
	// saved.
	Dir string
}

UploadPayload is the payload type of the updown service upload method.

type UploadRequestData

type UploadRequestData struct {
	// Payload is the method payload.
	Payload *UploadPayload
	// Body streams the HTTP request body.
	Body io.ReadCloser
}

UploadRequestData holds both the payload and the HTTP request body reader of the "upload" method.

Jump to

Keyboard shortcuts

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