gcs

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GCS

type GCS struct {
	Client       *storage.Client
	Bucket       string
	BasePath     string
	MainPage     string
	NotFoundPage string
	Fallback     http.Handler
}

GCS proxies request to google cloud storage

Example

Configure the proxy as a single-page-application host: "/" serves index.html, any missing object falls back to 404.html (so client-side routing works), and requests outside the bucket fall through to another handler.

package main

import (
	"context"
	"net/http"

	"cloud.google.com/go/storage"

	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/gcs"
)

func main() {
	client, err := storage.NewClient(context.Background())
	if err != nil {
		return
	}

	m := &gcs.GCS{
		Client:       client,
		Bucket:       "my-bucket",
		BasePath:     "web",
		MainPage:     "index.html",
		NotFoundPage: "404.html",
		Fallback: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			http.Error(w, "not found", http.StatusNotFound)
		}),
	}

	s := parapet.New()
	s.Use(m)
}

func New

func New(client *storage.Client, bucket string, basePath string) *GCS

New creates new gcs backend

Example

Serve a bucket's objects through the proxy: requests are mapped onto objects under "assets/" in the bucket and streamed back to the client.

package main

import (
	"context"

	"cloud.google.com/go/storage"

	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/gcs"
)

func main() {
	client, err := storage.NewClient(context.Background())
	if err != nil {
		return
	}

	s := parapet.New()
	s.Use(gcs.New(client, "my-bucket", "assets"))
}

func (GCS) ServeHandler

func (m GCS) ServeHandler(h http.Handler) http.Handler

ServeHandler implements middleware interface

Jump to

Keyboard shortcuts

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