Overview ▹
Overview ▾
Package app helps with configuring and starting server applications from Perkeep. See also https://perkeep.org/doc/app-environment for the related variables.
Index
- type Handler
- func NewHandler(cfg HandlerConfig) (*Handler, error)
- func (a *Handler) AppConfig() map[string]interface{}
- func (a *Handler) AuthMode() auth.AuthMode
- func (a *Handler) BackendURL() string
- func (a *Handler) InitHandler(hl blobserver.FindHandlerByTyper) error
- func (a *Handler) ProgramName() string
- func (a *Handler) Quit() error
- func (a *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *Handler) Start() error
- type HandlerConfig
- func FromJSONConfig(config jsonconfig.Obj, prefix, serverBaseURL string) (HandlerConfig, error)
Package files
type Handler
type Handler struct {
// contains filtered or unexported fields
}
Handler acts as a reverse proxy for a server application started by Perkeep. 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 Perkeep 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 Perkeep 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 Perkeep server's BaseURL. Defaults to the // BaseURL value in the Perkeep server configuration. ServerBaseURL string `json:"serverBaseURL,omitempty"` // APIHost is the URL of the Perkeep 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://perkeep.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.