app

package
v0.0.0-...-a5a65f0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2017 License: Apache-2.0 Imports: 20 Imported by: 53

Documentation

Overview

Package app helps with configuring and starting server applications from Camlistore. See also https://camlistore.org/doc/app-environment for the related variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler acts as a reverse proxy for a server application started by Camlistore. It can also serve some extra JSON configuration to the app. In addition, the handler can be used as a limited search handler proxy.

func NewHandler

func NewHandler(cfg HandlerConfig) (*Handler, error)

NewHandler creates a new handler from the given HandlerConfig. Two exceptions apply to the HandlerConfig documentation: NewHandler does not create default values for Prefix and ServerBaseURL. Prefix should be provided, and ServerBaseURL might be needed, depending on the other fields.

func (*Handler) AppConfig

func (a *Handler) AppConfig() map[string]interface{}

AppConfig returns the optional configuration parameters object that the app can request from the app handler. It can be nil.

func (*Handler) AuthMode

func (a *Handler) AuthMode() auth.AuthMode

AuthMode returns the app handler's auth mode, which is also the auth that the app's client will be configured with. This mode should be registered with the server's auth modes, for the app to have access to the server's resources.

func (*Handler) BackendURL

func (a *Handler) BackendURL() string

BackendURL returns the appBackendURL that the app handler will proxy to.

func (*Handler) InitHandler

func (a *Handler) InitHandler(hl blobserver.FindHandlerByTyper) error

InitHandler sets the app handler's search handler, if the app handler was configured to have one with HasSearch.

func (*Handler) ProgramName

func (a *Handler) ProgramName() string

ProgramName returns the name of the app's binary. It may be a file name in CAMLI_APP_BINDIR or PATH, or an absolute path.

func (*Handler) Quit

func (a *Handler) Quit() error

Quit sends the app's process a SIGINT, and waits up to 5 seconds for it to exit, returning an error if it doesn't.

func (*Handler) ServeHTTP

func (a *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Handler) Start

func (a *Handler) Start() error

type HandlerConfig

type HandlerConfig struct {
	// Program is the file name of the server app's program executable. Either
	// an absolute path, or the name of a file located in CAMLI_APP_BINDIR or in PATH.
	Program string `json:"program"`

	// Prefix is the URL path prefix on APIHost where the app handler is mounted.
	// It always ends with a trailing slash. Examples: "/pics/", "/blog/".
	// Defaults to the Camlistore URL path prefix for this app handler.
	Prefix string `json:"prefix,omitempty"`

	// Listen is the address (of the form host|ip:port) on which the app
	// will listen. It defines CAMLI_APP_LISTEN.
	// If empty, the default is the concatenation of ServerListen's host
	// part and a random port.
	Listen string `json:"listen,omitempty"`

	// ServerListen is the Camlistore server's listen address. Defaults to
	// the ServerBaseURL host part.
	ServerListen string `json:"serverListen,omitempty"`

	// BackendURL is the URL of the application's process, always ending in a
	// trailing slash. It is the URL that the app handler will proxy to when
	// getting requests for the concerned app.
	// If empty, the default is the concatenation of the ServerBaseURL
	// scheme, the ServerBaseURL host part, and the port of Listen.
	BackendURL string `json:"backendURL,omitempty"`

	// ServerBaseURL is the Camlistore server's BaseURL. Defaults to the
	// BaseURL value in the Camlistore server configuration.
	ServerBaseURL string `json:"serverBaseURL,omitempty"`

	// APIHost is the URL of the Camlistore server which the app should
	// use to make API calls. It always ends in a trailing slash. It defines CAMLI_API_HOST.
	// If empty, the default is ServerBaseURL, with a trailing slash appended.
	APIHost string `json:"apiHost,omitempty"`

	// AppConfig contains some additional configuration specific to each app.
	// See CAMLI_APP_CONFIG_URL.
	AppConfig jsonconfig.Obj
}

HandlerConfig holds the configuration for an app Handler. See https://camlistore.org/doc/app-environment for the corresponding environment variables. If developing an app, see FromJSONConfig and NewHandler for details on where defaults are applied.

func FromJSONConfig

func FromJSONConfig(config jsonconfig.Obj, prefix, serverBaseURL string) (HandlerConfig, error)

FromJSONConfig creates an HandlerConfig from the contents of config. prefix and serverBaseURL are used if not found in config.

Jump to

Keyboard shortcuts

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