fileupload

package
v0.0.0-...-92440b6 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: MIT Imports: 13 Imported by: 0

README

fileupload

This example illustrates how to handle file uploading.

Generate the code

$ go generate

Test the server

Run the server:

$ go run cmd/main.go
2021/03/07 16:00:34 transport=HTTP addr=:8080

Upload a file:

$ curl -F file=@/dir/to/sample_file.txt http://localhost:8080/upload

Check the uploaded file sample_file.txt in the current directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeEndpointOfUpload

func MakeEndpointOfUpload(s Service) endpoint.Endpoint

MakeEndpointOfUpload creates the endpoint for s.Upload.

func NewHTTPRouter

func NewHTTPRouter(svc Service, codecs httpcodec.Codecs, opts ...httpoption.Option) chi.Router

func OASv2APIDoc

func OASv2APIDoc(schema oas2.Schema) string

func ValidateUploadRequest

func ValidateUploadRequest(newSchema func(*UploadRequest) validating.Schema) httpoption.Validator

ValidateUploadRequest creates a validator for UploadRequest.

Types

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

func NewHTTPClient

func NewHTTPClient(codecs httpcodec.Codecs, httpClient *http.Client, baseURL string) (*HTTPClient, error)

func (*HTTPClient) Upload

func (c *HTTPClient) Upload(ctx context.Context, file *httpcodec.FormFile) (err error)

type Service

type Service interface {
	// Upload uploads a file.
	//kun:op POST /upload
	//kun:success statusCode=204
	Upload(ctx context.Context, file *httpcodec.FormFile) (err error)
}

Service is used for uploading files.

type UploadRequest

type UploadRequest struct {
	File *httpcodec.FormFile `json:"file"`
}

type UploadResponse

type UploadResponse struct {
	Err error `json:"-"`
}

func (*UploadResponse) Body

func (r *UploadResponse) Body() interface{}

func (*UploadResponse) Failed

func (r *UploadResponse) Failed() error

Failed implements endpoint.Failer.

type Uploader

type Uploader struct{}

func (*Uploader) Upload

func (u *Uploader) Upload(ctx context.Context, file *httpcodec.FormFile) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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