storage

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package storage provides a simple interface for storing and retrieving data

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned when the requested resource is not found
	ErrNotFound = errors.New("not found")
	// ErrInvalidArgument is returned when the request has invalid arguments
	ErrInvalidArgument = errors.New("invalid argument")
	// ErrPostNotPublished is returned when trying to update a published URL for
	// a post that is not published
	ErrPostNotPublished = fmt.Errorf("post not published")
)

Functions

This section is empty.

Types

type Asset

type Asset struct {
	ID          string   `json:"id" firestore:"id"`
	ContentType string   `json:"content_type" firestore:"content_type"`
	IsPublic    bool     `json:"is_public" firestore:"is_public"`
	FileName    string   `json:"file_name" firestore:"file_name"`
	Path        string   `json:"path" firestore:"path"`
	Tags        []string `json:"tags" firestore:"tags"`

	AssetURL *AssetURL `json:"asset_url" firestore:"asset_url"`

	CreatedBy string    `json:"created_by" firestore:"created_by"`
	CreatedAt time.Time `json:"created_at" firestore:"created_at"`
	UpdatedBy string    `json:"updated_by" firestore:"updated_by"`
	UpdatedAt time.Time `json:"updated_at" firestore:"updated_at"`
}

Asset represents an asset

type AssetURL

type AssetURL struct {
	URL    string    `json:"url" firestore:"url"`
	Expiry time.Time `json:"expiry" firestore:"expiry"`
}

AssetURL is a signed URL for an asset

type DataStore

type DataStore interface {
	// CreatePost creates a new post.
	CreatePost(ctx context.Context, title, createdby string, tags []string) (*Post, error)
	// GetPost retrieves a post by its ID.
	GetPost(ctx context.Context, id string) (*Post, error)
	// ListPosts retrieves a list of posts.
	ListPosts(ctx context.Context, f ListPostFilter) ([]*Post, error)
	// UpdatePost updates a post.
	UpdatePost(ctx context.Context, id, updatedby, title string) (*Post, error)
	// DeletePost deletes a post by its ID.
	DeletePost(ctx context.Context, id string) error
	// PublishPost publishes a post.
	PublishPost(ctx context.Context, postID string, version int64, publishedBy string, isPublic bool, url *AssetURL) (*Post, error)
	// UnpublishPost unpublishes a post.
	UnpublishPost(ctx context.Context, postID string) error
	// UpdatePublishedURL updates the published URL of a post.
	UpdatePublishedURL(ctx context.Context, postID string, url *AssetURL) (*Post, error)

	// NewAsset creates a new asset.
	NewAsset(ctx context.Context, asset *Asset) (*Asset, error)
	// GetAsset retrieves an asset by its ID.
	GetAsset(ctx context.Context, id string) (*Asset, error)
	// ListAssets retrieves a list of assets.
	ListAssets(ctx context.Context, f ListAssetFilter) ([]*Asset, error)
	// UpdateAsset updates an asset.
	UpdateAsset(ctx context.Context, asset *Asset) (*Asset, error)
	// DeleteAsset deletes an asset by its ID.
	DeleteAsset(ctx context.Context, id string) error
}

DataStore provides a simple interface for storing and retrieving data

type File

type File struct {
	URL      string
	Version  int64
	Versions []int64
}

File represents a file

type FileStore

type FileStore interface {
	// CreateUploadURL creates a signed URL for uploading a file.
	CreateUploadURL(path, contentType string) (url string, expiry time.Time, err error)
	// CreateSignedURL creates a signed URL for a file.
	CreateSignedURL(method, path, contentType string, expiry time.Time, queries url.Values) (url string, err error)
	// UploadFile uploads a file to the storage.
	UploadFile(ctx context.Context, path, contentType string, data []byte) error
	// GetFile retrieves a downloadable URL for a file.
	GetFile(ctx context.Context, path string, version int64, expiry time.Time) (*File, error)
	// DeleteFile deletes a file from the storage.
	DeleteFile(ctx context.Context, path string) error
	// DeleteFolder deletes a folder from the storage.
	DeleteFolder(ctx context.Context, path string) error
}

FileStore provides a simple interface for storing and retrieving files

type ListAssetFilter

type ListAssetFilter struct {
	FileName    string
	CreatedBy   string
	UpdatedBy   string
	Tags        []string
	IsPublic    *bool
	IsPublished *bool
}

ListAssetFilter represents a set of filters for listing assets.

type ListPostFilter

type ListPostFilter struct {
	CreatedBy     string
	UpdatedBy     string
	Tags          []string
	PublishStatus *PublishStatus
}

ListPostFilter represents a set of filters for listing posts.

type Post

type Post struct {
	ID        string    `json:"id" firestore:"id"`
	Title     string    `json:"title" firestore:"title"`
	Tags      []string  `json:"tags" firestore:"tags"`
	CreatedBy string    `json:"created_by" firestore:"created_by"`
	UpdatedBy string    `json:"updated_by" firestore:"updated_by"`
	CreatedAt time.Time `json:"created_at" firestore:"created_at"`
	UpdatedAt time.Time `json:"updated_at" firestore:"updated_at"`

	Publish     *Publish `json:"publish" firestore:"publish"`
	IsPublished bool     `json:"is_published" firestore:"is_published"`
	IsPublic    bool     `json:"is_public" firestore:"is_public"`
}

Post represents a post

type Publish

type Publish struct {
	PublishedVersion int64 `json:"published_version" firestore:"published_version"`
	IsPublic         bool  `json:"is_public" firestore:"is_public"`

	PublishedBy string    `json:"published_by" firestore:"published_by"`
	PublishedAt time.Time `json:"published_at" firestore:"published_at"`

	URL *AssetURL `json:"url" firestore:"url"`
}

Publish represents a published post

type PublishStatus

type PublishStatus struct {
	IsPublished *bool
	IsPublic    *bool
}

PublishStatus is a set of publish status filters.

Directories

Path Synopsis
Package cloudstorage implements the FileStore interface using Google Cloud Storage.
Package cloudstorage implements the FileStore interface using Google Cloud Storage.
Package firestore implements the storage interface using Google Cloud Firestore.
Package firestore implements the storage interface using Google Cloud Firestore.

Jump to

Keyboard shortcuts

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