server

package
v0.1.2-0...-b37f032 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package server provides a simple frontend in form of an App Engine app built atop the weasel.Storage. See README.md for the design details.

This package is a work in progress and makes no API stability promises.

An example usage for App Engine Standard:

# app.yaml
runtime: go
api_version: go1
handlers:
- url: /.*
  script: _go_app

# app.go
package app

import (
  "github.com/google/weasel"
  "github.com/google/weasel/server"
)

func init() {
  conf := &server.Config{
    Storage: weasel.DefaultStorage,
    Buckets: map[string]string{
      "default": "my-gcs-bucket",
    },
    HookPath: "/-/flush-gcs-cache",
  }
  server.Init(nil, conf)
}

The "/-/flush-gcs-cache" needs to be hooked up with "my-gcs-bucket" manually using Object Change Notifications. See the following page for more details: https://cloud.google.com/storage/docs/object-change-notification

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(mux *http.ServeMux, conf *Config)

Init registers server handlers on the provided mux. If the mux argument is nil, http.DefaultServeMux is used.

See package doc for a usage example.

Types

type Config

type Config struct {
	// Storage provides server with the content access.
	Storage *weasel.Storage

	// Buckets defines a mapping between a request attribute
	// and GCS buckets the responses should be served from.
	// The map must contain at least "default" key.
	Buckets map[string]string

	// KeyPathFn is a function that returns the appropriate key
	// that maps to a bucket and file path for a HTTP request.
	// Default is a function that returns the `host` HTTP header as
	// a bucket key and the relative path.
	KeyPathFn KeyPathFn

	// WebRoot is the content serving root pattern.
	// If empty, default is used.
	// Default value is "/".
	WebRoot string

	// GCS object change notification hook pattern.
	// If empty, no hook handler will be setup during Init.
	HookPath string

	// Redirects is a map of URLs the app will permanently redirect to
	// when the request host and path match a key.
	// Map values must not end with "/" and cannot contain query string.
	Redirects map[string]string

	// TLSOnly forces TLS connection for the specified host names.
	TLSOnly []string
}

Config is used to init the server. See Init for more details.

type KeyPathFn

type KeyPathFn func(r *http.Request) (bucketKey, filePath string)

KeyPathFn is a function that determines the lookup key that maps to the appropriate bucket and the adjusted file path from a HTTP request

Jump to

Keyboard shortcuts

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