Documentation ¶
Overview ¶
Package gcsemu implements a Google Cloud Storage emulator for development.
Index ¶
- func BucketMeta(baseUrl HttpBaseUrl, bucket string) *storage.Bucket
- func BucketUrl(baseUrl HttpBaseUrl, bucket string) string
- func DrainRequestHandler(h http.HandlerFunc) http.HandlerFunc
- func GzipRequestHandler(h http.HandlerFunc) http.HandlerFunc
- func InitMetaWithUrls(baseUrl HttpBaseUrl, meta *storage.Object, bucket string, filename string, ...)
- func InitScrubbedMeta(meta *storage.Object, filename string)
- func NewClient(ctx context.Context) (*storage.Client, error)
- func NewFileStore(gcsDir string) *filestore
- func NewMemStore() *memstore
- func NewTestClientWithHost(ctx context.Context, hostUrl string) (*storage.Client, error)
- func ObjectUrl(baseUrl HttpBaseUrl, bucket string, filepath string) string
- func ScrubMeta(meta *storage.Object)
- type GcsEmu
- type GcsParams
- type HttpBaseUrl
- type Options
- type Server
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BucketMeta ¶
func BucketMeta(baseUrl HttpBaseUrl, bucket string) *storage.Bucket
BucketMeta returns a default bucket metadata for the given name and base url.
func BucketUrl ¶
func BucketUrl(baseUrl HttpBaseUrl, bucket string) string
BucketUrl returns the URL for a bucket.
func DrainRequestHandler ¶
func DrainRequestHandler(h http.HandlerFunc) http.HandlerFunc
DrainRequestHandler wraps the given handler to drain the incoming request body on exit.
func GzipRequestHandler ¶
func GzipRequestHandler(h http.HandlerFunc) http.HandlerFunc
GzipRequestHandler wraps the given handler to automatically decompress gzipped content.
func InitMetaWithUrls ¶
func InitMetaWithUrls(baseUrl HttpBaseUrl, meta *storage.Object, bucket string, filename string, size uint64)
InitMetaWithUrls "bakes" metadata with intrinsic values, including computed links.
func InitScrubbedMeta ¶
func InitScrubbedMeta(meta *storage.Object, filename string)
InitScrubbedMeta "bakes" metadata with intrinsic values and removes fields that are intrinsic / computed.
func NewClient ¶
NewClient returns either a real *storage.Cient, or else a *storage.Client that routes to a local emulator if a `GCS_EMULATOR_HOST` environment variable is configured.
func NewFileStore ¶
func NewFileStore(gcsDir string) *filestore
NewFileStore returns a new Store that writes to the given directory.
func NewMemStore ¶
func NewMemStore() *memstore
NewMemStore returns a Store that operates purely in memory.
func NewTestClientWithHost ¶
NewTestClientWithHost returns a new Google storage client that connects to the given host:port address.
Types ¶
type GcsEmu ¶
type GcsEmu struct {
// contains filtered or unexported fields
}
GcsEmu is a Google Cloud Storage emulator for development.
func (*GcsEmu) BatchHandler ¶
func (g *GcsEmu) BatchHandler(w http.ResponseWriter, r *http.Request)
BatchHandler handles emulated GCS http requests for "storage.googleapis.com/batch/storage/v1".
func (*GcsEmu) Handler ¶
func (g *GcsEmu) Handler(w http.ResponseWriter, r *http.Request)
Handler handles emulated GCS http requests for "storage.googleapis.com".
func (*GcsEmu) InitBucket ¶
InitBucket creates the given bucket directly.
type HttpBaseUrl ¶
type HttpBaseUrl string
HttpBaseUrl represents the emulator base URL, including trailing slash; e.g. https://www.googleapis.com/
type Options ¶
type Options struct { // A storage layer to use; if nil, defaults to in-mem storage. Store Store // If true, log verbosely. Verbose bool // Optional log function. `err` will be `nil` for informational/debug messages. Log func(err error, fmt string, args ...interface{}) }
Options configure the emulator.
type Server ¶
Server is an in-memory Cloud Storage emulator; it is unauthenticated, and only a rough approximation.
func NewServer ¶
NewServer creates a new Server with the given options. The Server will be listening for HTTP connections, without TLS, on the provided address. The resolved address is named by the Addr field. An address with a port of 0 will bind to an open port on the system.
For running a full in-process setup (e.g. unit tests), initialize os.Setenv("GCS_EMULATOR_HOST", srv.Addr) so that subsequent calls to NewClient() will return an in-process targeted storage client.
type Store ¶
type Store interface { // CreateBucket creates a bucket; no error if the bucket already exists. CreateBucket(bucket string) error // Get returns a bucket's metadata. GetBucketMeta(baseUrl HttpBaseUrl, bucket string) (*storage.Bucket, error) // Get returns a file's contents and metadata. Get(url HttpBaseUrl, bucket string, filename string) (*storage.Object, []byte, error) // GetMeta returns a file's metadata. GetMeta(url HttpBaseUrl, bucket string, filename string) (*storage.Object, error) // Add creates the specified file. Add(bucket string, filename string, contents []byte, meta *storage.Object) error // UpdateMeta updates the given file's metadata. UpdateMeta(bucket string, filename string, meta *storage.Object, metagen int64) error // Copy copies the file Copy(srcBucket string, srcFile string, dstBucket string, dstFile string) (bool, error) // Delete deletes the file. Delete(bucket string, filename string) error // ReadMeta reads the GCS metadata for a file, when you already have file info. ReadMeta(url HttpBaseUrl, bucket string, filename string, fInfo os.FileInfo) (*storage.Object, error) // Walks the given bucket. Walk(ctx context.Context, bucket string, cb func(ctx context.Context, filename string, fInfo os.FileInfo) error) error }
Store is an interface to either on-disk or in-mem storage