Documentation
¶
Overview ¶
Package weasel provides a simple frontend (App Engine app) that serves content from a Google Cloud Storage (GCS) bucket. See README.md for the design details.
Index ¶
- Constants
- Variables
- func ServeObject(w http.ResponseWriter, o *Object, withBody bool) error
- func ValidMethod(m string) bool
- type FetchError
- type Object
- type Storage
- func (s *Storage) CacheKey(bucket, name string) string
- func (s *Storage) HandleChangeHook(w http.ResponseWriter, r *http.Request)
- func (s *Storage) PurgeCache(ctx context.Context, bucket, name string) error
- func (s *Storage) ReadFile(ctx context.Context, bucket, name string) (*Object, error)
- func (s *Storage) ReadObject(ctx context.Context, bucket, name string) (*Object, error)
- func (s *Storage) Stat(ctx context.Context, bucket, name string) (*Object, error)
Constants ¶
const ( ScopeStorageRead = "https://www.googleapis.com/auth/devstorage.read_only" ScopeStorageOwner = "https://www.googleapis.com/auth/devstorage.full_control" )
Google Cloud Storage OAuth2 scopes
Variables ¶
var DefaultStorage = Storage{
Base: "https://storage.googleapis.com",
Index: "index.html",
}
DefaultStorage is a Storage with sensible default parameters suitable for prod environments on App Engine.
Functions ¶
func ServeObject ¶
func ServeObject(w http.ResponseWriter, o *Object, withBody bool) error
ServeObject writes object o to w, with optional body.
func ValidMethod ¶
ValidMethod reports whether m is a supported HTTP method.
Types ¶
type FetchError ¶
FetchError contains error code and message from a GCS response.
type Object ¶
Object represents a single GCS object.
func (*Object) RedirectCode ¶
RedirectCode returns o's HTTP response code for redirect. It defaults to http.StatusMovedPermanently.
type Storage ¶
type Storage struct { Base string // GCS service base URL, e.g. "https://storage.googleapis.com". Index string // Appended to an object name in certain cases, e.g. "index.html". }
Storage incapsulates configuration params for retrieveing and serving GCS objects.
func (*Storage) CacheKey ¶
CacheKey returns a key to cache an object under, computed from s.Base, bucket and then name.
func (*Storage) HandleChangeHook ¶
func (s *Storage) HandleChangeHook(w http.ResponseWriter, r *http.Request)
HandleChangeHook handles Object Change Notifications as described at https://cloud.google.com/storage/docs/object-change-notification. It removes objects from cache.
func (*Storage) PurgeCache ¶
PurgeCache removes cached object from memcache. It does not return an error in the case of cache miss.
func (*Storage) ReadObject ¶
ReadObject retrieves GCS object name of the bucket from cache or network. Objects fetched from the network are cached before returning from this function.