Documentation
¶
Index ¶
- type DirectUploadToken
- type DirectWritableUploadFileStoreProvider
- type JSONLineUploadFileVerifier
- type LocalUploadFileStoreProvider
- type NopWaitUploadFileVerifier
- type UploadFileStore
- func (s *UploadFileStore) GetResult(token UploadToken) (UploadResult, error)
- func (s *UploadFileStore) GetUploadToken(id string, verifier UploadFileVerifier) UploadToken
- func (s *UploadFileStore) SetResultOnCompletedUpload(token UploadToken, uploadError error) error
- func (s *UploadFileStore) SetResultOnStartingUpload(token UploadToken) error
- type UploadFileStoreProvider
- type UploadFileVerifier
- type UploadResult
- type UploadStatus
- type UploadToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DirectUploadToken ¶
type DirectUploadToken struct {
// ID identiies the file location uploade to this server directly.
ID string `json:"id"`
}
DirectUploadToken is a UploadToken for uploading the target file to API directly.
func (*DirectUploadToken) GetHash ¶
func (d *DirectUploadToken) GetHash() string
GetHash implements UploadToken.
func (*DirectUploadToken) GetID ¶
func (d *DirectUploadToken) GetID() string
GetID implements UploadToken.
func (*DirectUploadToken) GetType ¶
func (d *DirectUploadToken) GetType() string
GetType implements UploadToken.
type DirectWritableUploadFileStoreProvider ¶
type DirectWritableUploadFileStoreProvider interface {
// Write writes file with given io.Writer interaface to the file with the given ID.
Write(token UploadToken, reader io.Reader) error
}
type JSONLineUploadFileVerifier ¶
type JSONLineUploadFileVerifier struct {
MaxLineSizeInBytes int
}
func (*JSONLineUploadFileVerifier) Verify ¶
func (j *JSONLineUploadFileVerifier) Verify(storeProvider UploadFileStoreProvider, token UploadToken) error
Verify implements UploadFileVerifier.
type LocalUploadFileStoreProvider ¶
type LocalUploadFileStoreProvider struct {
// contains filtered or unexported fields
}
LocalUploadFileStoreProvider is an implementation of UploadFileStore that stores files in the local file system.
func NewLocalUploadFileStoreProvider ¶
func NewLocalUploadFileStoreProvider(directoryPath string) *LocalUploadFileStoreProvider
NewLocalUploadFileStoreProvider creates a new LocalUploadFileStore.
func (*LocalUploadFileStoreProvider) GetUploadToken ¶
func (l *LocalUploadFileStoreProvider) GetUploadToken(id string) UploadToken
GetUploadToken implements UploadFileStoreProvider.
func (*LocalUploadFileStoreProvider) Read ¶
func (l *LocalUploadFileStoreProvider) Read(token UploadToken) (io.ReadCloser, error)
func (*LocalUploadFileStoreProvider) Write ¶
func (l *LocalUploadFileStoreProvider) Write(token UploadToken, reader io.Reader) error
type NopWaitUploadFileVerifier ¶
type NopWaitUploadFileVerifier struct {
// WaitTimeInMs is the time to wait before returning the veification result.
WaitTimeInMs int
// Error is the error returned from Verify function after waiting the WaitTimeInMs.
Error error
}
NopWaitUploadFileVerifier just waits the specified time without doing anything on the file.
func (*NopWaitUploadFileVerifier) Verify ¶
func (n *NopWaitUploadFileVerifier) Verify(storeProvider UploadFileStoreProvider, token UploadToken) error
Verify implements UploadFileVerifier.
type UploadFileStore ¶
type UploadFileStore struct {
StoreProvider UploadFileStoreProvider
// contains filtered or unexported fields
}
UploadFileStore manages file uploads.
var DefaultUploadFileStore *UploadFileStore = nil
func NewUploadFileStore ¶
func NewUploadFileStore(storeProvider UploadFileStoreProvider) *UploadFileStore
NewUploadFileStore creates a new UploadFileStore.
func (*UploadFileStore) GetResult ¶
func (s *UploadFileStore) GetResult(token UploadToken) (UploadResult, error)
GetResult returns the result of the upload with given token.
func (*UploadFileStore) GetUploadToken ¶
func (s *UploadFileStore) GetUploadToken(id string, verifier UploadFileVerifier) UploadToken
GetUploadToken returns the token to upload it from frontend. The ID must be combination of a known string and random string to make it harder to guess it from outside.
func (*UploadFileStore) SetResultOnCompletedUpload ¶
func (s *UploadFileStore) SetResultOnCompletedUpload(token UploadToken, uploadError error) error
SetResultOnCompletedUpload notify the file upload is completed and start verifier.
func (*UploadFileStore) SetResultOnStartingUpload ¶
func (s *UploadFileStore) SetResultOnStartingUpload(token UploadToken) error
SetResultOnStartingUpload sets the upload status to Uploading. It returns an error if the token is not found.
type UploadFileStoreProvider ¶
type UploadFileStoreProvider interface {
// Generate a UploadToken for frontend
GetUploadToken(id string) UploadToken
// Read returns the io.ReadCloser interface to read the file with the given ID.
// The caller MUST close the returned ReadCloser.
Read(token UploadToken) (io.ReadCloser, error)
}
type UploadFileVerifier ¶
type UploadFileVerifier interface {
// Verify checks the file. This returns an error if invalid.
Verify(storeProvider UploadFileStoreProvider, token UploadToken) error
}
UploadFileVerifier verifies uploaded files (e.g., file type checks).
type UploadResult ¶
type UploadResult struct {
// Token is an UploadToken associated with the file.
Token UploadToken
// StoreProvider provides the way of getting the uploaded file with the given token.
StoreProvider UploadFileStoreProvider
// Status is the current state of the upload.
Status UploadStatus
// UploadError contains any error that occurred during the upload process itself
UploadError error
// VerificationError contains any error returned by the UploadFileVerifier.
VerificationError error
// VerificationCount is the attempt count of the verification logic. This value is preventing the race condition in verification steps.
VerificationCount int
}
UploadResult holds the result of an upload operation.
func (*UploadResult) GetReader ¶
func (r *UploadResult) GetReader() (io.ReadCloser, error)
GetReader returns an io.ReadCloser for reading the uploaded file. The caller MUST close the returned ReadCloser.
type UploadStatus ¶
type UploadStatus int
UploadStatus represents the status of an upload (Waiting or Completed).
const ( // UploadStatusWaiting indicates this file is not yet uploaded or in progress of upload. UploadStatusWaiting UploadStatus = 0 // UploadStatusUploading indicates this file is being uploaded. UploadStatusUploading UploadStatus = 1 // UploadStatusVerifying indicates the file was uploaded but this is under verifying. UploadStatusVerifying UploadStatus = 2 // UploadStatusComplete indicates the file has uploaded successfully. UploadStatusCompleted UploadStatus = 3 )
type UploadToken ¶
type UploadToken interface {
// GetType returns the type of token specifying the methods to upload the file.
GetType() string
// GetID returns the unique identifier of upload files.
GetID() string
// GetHash returns a unique string calculated from all the field of the implementation.
// This must be calculated from ALL the field because this is for checking if 2 instances are identical.
GetHash() string
}
UploadToken is the type given to the frontend to receive the file. This currently exects files are uploaded to API directly, but in future this may support the upload using signed URLs as well. All token implements this type must be serializable as JSON.