Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michaelwp/go-gcs-wrapper
go-gcs-wrapper is a library that makes it easy for Go applications to interact with Google Cloud Storage. This wrapper handles the complex details of the Google Cloud Storage API, allowing developers to use storage features with less code and effort
https://github.com/michaelwp/go-gcs-wrapper
cloud gcs gcswrapper go google gopackage storage wrapper
Last synced: 6 days ago
JSON representation
go-gcs-wrapper is a library that makes it easy for Go applications to interact with Google Cloud Storage. This wrapper handles the complex details of the Google Cloud Storage API, allowing developers to use storage features with less code and effort
- Host: GitHub
- URL: https://github.com/michaelwp/go-gcs-wrapper
- Owner: michaelwp
- License: mit
- Created: 2024-06-23T03:08:36.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-06-23T10:00:02.000Z (8 months ago)
- Last Synced: 2024-07-11T13:59:30.374Z (7 months ago)
- Topics: cloud, gcs, gcswrapper, go, google, gopackage, storage, wrapper
- Language: Go
- Homepage: https://goblog.dev/articles/28
- Size: 214 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-gcs-wrapper
go-gcs-wrapper is a library that makes it easy for Go applications to interact with Google Cloud Storage.
It provides simple functions for tasks like uploading files and generating signed URLs for secure access.
This wrapper handles the complex details of the Google Cloud Storage API, allowing developers to use storage features
with less code and effort.### installation
```shell
go get -d github.com/michaelwp/go-gcs-wrapper
```### basic of use
- Upload file
```go
package mainimport (
"context"
"github.com/joho/godotenv"
gogcswrapper "github.com/michaelwp/go-gcs-wrapper"
"log"
"os"
)func init() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file", err)
}
}func main() {
projectId := os.Getenv("GOOGLE_APPLICATION_PROJECT_ID")
bucket := os.Getenv("GOOGLE_APPLICATION_BUCKET")
object := "go_gcs.png"
uploadObjPath := "upload_tes"
localObjPath := "."ctx := context.Background()
gcs := gogcswrapper.NewGCS(ctx, projectId)params := &gogcswrapper.UploadParams{
BucketAndObject: &gogcswrapper.BucketAndObject{
Bucket: bucket,
Object: object,
},
LocalObjPath: localObjPath,
UploadObjPath: uploadObjPath,
}err := gcs.Upload(ctx, params)
if err != nil {
log.Fatal("error uploading file", err)
}
}
```- Generate signed Url
```go
package mainimport (
"context"
"fmt"
"github.com/joho/godotenv"
gogcswrapper "github.com/michaelwp/go-gcs-wrapper"
"log"
"os"
"time"
)func init() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file", err)
}
}func main() {
projectId := os.Getenv("GOOGLE_APPLICATION_PROJECT_ID")
bucket := os.Getenv("GOOGLE_APPLICATION_BUCKET")
object := "go_gcs.png"
uploadObjPath := "upload_tes"ctx := context.Background()
gcs := gogcswrapper.NewGCS(ctx, projectId)params := &gogcswrapper.GenerateSignedURLParams{
BucketAndObject: &gogcswrapper.BucketAndObject{
Bucket: bucket,
Object: object,
},
UploadObjPath: uploadObjPath,
ExpirationTime: time.Now().Add(time.Minute * 10),
}signedUrl, err := gcs.GenerateSignedURL(params)
if err != nil {
log.Fatal("error generating sign url", err)
}fmt.Printf("Signed URL: %s\n", signedUrl)
}
```