gcs

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gcs provides a Google Cloud Storage client wrapper (cloud.google.com/go/storage) configured from config package.

Role in architecture:

  • Infrastructure adapter: connects to GCS, exposes client and bucket; used by application code for object read/write.

Responsibilities:

  • Setup: create storage client from config (credentials file or ADC); verify bucket access if BucketName set.
  • GetClient, GetBucket, GetBucketName: access the client and default bucket.
  • ReadObject, ReadObjectAsReader, WriteObject, DeleteObject, ObjectExists, ListObjects: map to GCS API calls with context.
  • Close: close the client.

Constraints:

  • SDK: cloud.google.com/go/storage. Single client and bucket per process; no provider switching.
  • No business logic; only mapping to GCS operations.
  • Credentials: config.GCS.CredentialsFile or Application Default Credentials.

This package must NOT:

  • Contain use-case logic; only GCS operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the GCS client

func DeleteObject

func DeleteObject(objectName string) error

DeleteObject deletes an object from GCS bucket

func GetBucket

func GetBucket() *storage.BucketHandle

GetBucket returns the default bucket handle. Panics if bucket name is not configured.

func GetBucketName

func GetBucketName() string

GetBucketName returns the configured bucket name (may be empty if not set).

func GetClient

func GetClient() *storage.Client

GetClient returns the storage client. Panics if Setup was not called or client is nil.

func ListObjects

func ListObjects(prefix string) ([]string, error)

ListObjects lists objects in the bucket with the given prefix

func ObjectExists

func ObjectExists(objectName string) (bool, error)

ObjectExists checks if an object exists in the bucket

func ReadObject

func ReadObject(objectName string) ([]byte, error)

ReadObject reads an object from GCS bucket

func ReadObjectAsReader

func ReadObjectAsReader(objectName string) (io.ReadCloser, error)

ReadObjectAsReader returns a reader for an object from GCS bucket

func Setup

func Setup() error

Setup initializes the GCS client from config (credentials file or ADC) and optionally verifies bucket access. No-op if GCS.Enabled is false.

func WriteObject

func WriteObject(objectName string, data []byte, contentType string) error

WriteObject writes data to an object in GCS bucket

Types

This section is empty.

Jump to

Keyboard shortcuts

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