Categorygithub.com/lidstromberg/storage
modulepackage
0.4.0
Repository: https://github.com/lidstromberg/storage.git
Documentation: pkg.go.dev

# README

Storage - read/write utility for Google Cloud Platform Storage buckets.

A Go utility to facilitate reading/writing files from/to Google Cloud Platform Storage.

What?

This utility uses Google Application Credentials or GCP service accounts to connect to a Google Cloud Platform project and read/write files from/to Storage buckets.

Why?

This was written to provide GCP storage bucket functionality within auth. It wraps the Google provided Storage Go client.

How?

The best place to start is with the tests. If running locally, then ensure that Google Application Credentials have been created. If running from a GCP virtual machine, then ensure that the relevant service account (compute, appengine etc.) has the following IAM scopes: 'Storage Object Viewer' and 'Storage Object Creator', or 'Storage Object Admin'. See GCP service accounts for further details.

Examples

See the tests for usage examples.

Dependencies and services

This utilises the following fine pieces of work:

Installation

Install with

$ go get -u github.com/lidstromberg/storage

Environment Variables

You will also need to export (linux/macOS) or create (Windows) some environment variables.

Change LB_DEBUGON to true/false if you want verbose logging on/off. The other variables don't need to be changed.

################################
# STORAGE
################################
export STOR_DEBUGON='true'
export STOR_CLIPOOL='5'

################################
# GCP CREDENTIALS
################################
export GOOGLE_APPLICATION_CREDENTIALS="/PATH/TO/GCPCREDENTIALS.JSON"

(See Google Application Credentials)

Main Files

FilePurpose
storage.goLogic manager
storage_test.goTests

Ancillary Files

FilePurpose
config.goBoot package parameters, environment var collection
const.goPackage constants
errors.goPackage error definitions
envPackage environment variables for local/dev installation
storagetester.jsontest content file
gogetsStatements for go-getting required packages

# Functions

DrainFn drains a channel until it is closed.
NewJSONMgr returns a new storage manager based on a GCP credential supplied as a byte array.
NewMgr returns a new storage manager.

# Constants

ObjAttrContentEncoding is the file encoding.
ObjAttrContentType is the content type.
ObjAttrCreated created timestamp.
ObjAttrName is the object name.
ObjAttrOwner is the GCP owner account.
ObjAttrSize is the size of the object.

# Variables

EnvClientPool is the size of the client pool.
EnvDebugOn controls verbose logging.
ErrMissingDateRange message.

# Structs

StorMgr handles interactions with GCS.