gogcs

package module
v0.0.0-...-91cd17e Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 10 Imported by: 0

README

go-gcs

Google Cloud Storage Wrapper in GoLang

Installation

go get github.com/hawow/go-gcs

Preparation

You will need to setup your environment variables see .env.example

GCS_BUCKET=
GCS_PROJECT_ID=
GCS_JSON_PATH=

Usage

package main

import (
 "context"
 "log"
 "github.com/hawow/go-gcs/"
)

ctx := context.Background()
client := NewGCSClient(ctx)
f, err := os.Open("sample.txt")
if err != nil {
    log.Fatal(err)
    return
}
file := File{
    Name:     "test.txt",
    Path:     "new/test/file",
    Body:     f,
    IsPublic: true,
}
result, err := client.UploadSingleFile(ctx, file)

Documentation

Index

Constants

View Source
const (
	LikelihoodsUnKnown      = "UNKNOWN"
	LikelihoodsVeryUnLikely = "VERY_UNLIKELY"
	LikelihoodsUnLikely     = "UNLIKELY"
	LikelihoodsPossible     = "POSSIBLE"
	LikelihoodsLikely       = "LIKELY"
	LikelihoodsVeryLikely   = "VERY_LIKELY"
)

Variables

This section is empty.

Functions

func GenerateUrlFromPath

func GenerateUrlFromPath(baseUrl string, filePath string) string

func GetFullPath

func GetFullPath(path string, name string) string

func MD5BytesToString

func MD5BytesToString(bytes []byte) string

func ObjectToUrl

func ObjectToUrl(baseUrl string, objAttrs *storage.ObjectAttrs) string

Types

type DownloadedFile

type DownloadedFile struct {
	Object string
	Name   string
	Path   string
	Data   *[]byte
}

type File

type File struct {
	Path     string
	Name     string
	Body     io.Reader
	IsPublic bool
}

type FileAttr

type FileAttr struct {
	MD5  []byte
	Size int64
}

type GCSConfig

type GCSConfig struct {
	Bucket    string `envconfig:"GCS_BUCKET" required:"true"`
	ProjectID string `envconfig:"GCS_PROJECT_ID" required:"true"`
	BaseUrl   string `envconfig:"GCS_BASE_URL" required:"true"`
}

func LoadGSCConfig

func LoadGSCConfig() GCSConfig

type GoGCSClient

type GoGCSClient interface {
	UploadFiles(files []File) ([]UploadedFile, error)
	DownloadFiles(downloads []DownloadedFile) error
	RemoveFiles(downloads []DownloadedFile) error
	GenerateImageResizable(ctx context.Context, image string) (*string, error)
	ValidAdultContent(body io.Reader, unAcceptLikelihoods []string) (bool, error)
	FileAttrs(files []File) ([]FileAttr, error)
}

type GoGSCClient

type GoGSCClient struct {
	StorageClient        *storage.Client
	ImageAnnotatorClient *vision.ImageAnnotatorClient
	ProjectID            string
	Bucket               string
	BaseUrl              string
	Context              context.Context
}

func NewGCSClient

func NewGCSClient(ctx context.Context) (*GoGSCClient, error)

func (GoGSCClient) DownloadFiles

func (s GoGSCClient) DownloadFiles(downloads []DownloadedFile) error

func (GoGSCClient) FileAttrs

func (s GoGSCClient) FileAttrs(files []File) ([]FileAttr, error)

func (GoGSCClient) GenerateImageResizable

func (s GoGSCClient) GenerateImageResizable(ctx context.Context, image string) (*string, error)

func (GoGSCClient) RemoveFiles

func (s GoGSCClient) RemoveFiles(downloads []DownloadedFile) error

func (GoGSCClient) UploadFiles

func (s GoGSCClient) UploadFiles(files []File) ([]UploadedFile, error)

func (GoGSCClient) ValidAdultContent

func (s GoGSCClient) ValidAdultContent(body io.Reader, unAcceptLikelihoods []string) (bool, error)

type UploadedFile

type UploadedFile struct {
	Name        string
	MD5         string
	IsPublic    bool
	Url         string
	Size        int64
	ObjectAttrs *storage.ObjectAttrs
}

Jump to

Keyboard shortcuts

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