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)
}
Output:
func New ¶
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"))
}
Output:
Click to show internal directories.
Click to hide internal directories.