Home Download Docs Code Community
import "perkeep/pkg/serverinit"
Overview
Index

Overview ▾

Package serverinit is responsible for mapping from a Perkeep configuration file and instantiating HTTP Handlers for all the necessary endpoints.

Index

Variables
func WriteDefaultConfigFile(filePath string) error
type Config
    func DefaultEnvConfig() (*Config, error)
    func Load(config []byte) (*Config, error)
    func LoadFile(filename string) (*Config, error)
    func (c *Config) AppURL() map[string]string
    func (c *Config) BaseURL() string
    func (c *Config) HTTPS() bool
    func (c *Config) HTTPSCert() string
    func (c *Config) HTTPSKey() string
    func (c *Config) InstallHandlers(hi HandlerInstaller, baseURL string) (shutdown io.Closer, err error)
    func (c *Config) IsTailscaleListener() bool
    func (c *Config) KeyRingAndId() (keyRing, keyId string, err error)
    func (c *Config) ListenAddr() string
    func (c *Config) LowLevelJSONConfig() map[string]interface{}
    func (c *Config) SetKeepGoing(v bool)
    func (c *Config) SetReindex(v bool)
    func (c *Config) StartApps() error
    func (c *Config) UIPath() string
    func (c *Config) UploadPublicKey(ctx context.Context) error
type HandlerInstaller

Package files

devmode.go env.go genconfig.go serverinit.go

Variables

var ErrCamliPath = errors.New("invalid Perkeep request path")

func WriteDefaultConfigFile

func WriteDefaultConfigFile(filePath string) error

WriteDefaultConfigFile generates a new default high-level server configuration file at filePath. The default indexer will use SQLite. If filePath already exists, it is overwritten.

type Config

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

A Config is the wrapper around a Perkeep JSON configuration file. Files on disk can be in either high-level or low-level format, but the Load function always returns the Config in its low-level format (a.k.a. the "handler" format).

TODO(bradfitz): document and/or link to the low-level format; for now you can see the high-level config format at https://perkeep.org/pkg/types/serverconfig/#Config and the the low-level format by running "camtool dumpconfig".

func DefaultEnvConfig

func DefaultEnvConfig() (*Config, error)

DefaultEnvConfig returns the default configuration when running on a known environment. Currently this just includes Google Compute Engine. If the environment isn't known (nil, nil) is returned.

func Load

func Load(config []byte) (*Config, error)

Load returns a low-level "handler config" from the provided config. If the config doesn't contain a top-level JSON key of "handlerConfig" with boolean value true, the configuration is assumed to be a high-level "user config" file, and transformed into a low-level config.

func LoadFile

func LoadFile(filename string) (*Config, error)

LoadFile returns a low-level "handler config" from the provided filename. If the config file doesn't contain a top-level JSON key of "handlerConfig" with boolean value true, the configuration is assumed to be a high-level "user config" file, and transformed into a low-level config.

func (*Config) AppURL

func (c *Config) AppURL() map[string]string

AppURL returns a map of app name to app base URL for all the configured server apps.

func (*Config) BaseURL

func (c *Config) BaseURL() string

BaseURL returns the optional URL prefix listening the root of this server. It does not end in a trailing slash.

func (*Config) HTTPS

func (c *Config) HTTPS() bool

HTTPS reports whether this configuration wants to serve HTTPS.

func (*Config) HTTPSCert

func (c *Config) HTTPSCert() string

HTTPSCert returns the optional path to an HTTPS public key certificate file.

func (*Config) HTTPSKey

func (c *Config) HTTPSKey() string

HTTPSKey returns the optional path to an HTTPS private key file.

func (*Config) InstallHandlers

func (c *Config) InstallHandlers(hi HandlerInstaller, baseURL string) (shutdown io.Closer, err error)

InstallHandlers creates and registers all the HTTP Handlers needed by config into the provided HandlerInstaller and validates that the configuration is valid.

baseURL is required and specifies the root of this webserver, without trailing slash.

The returned shutdown value can be used to cleanly shut down the handlers.

func (*Config) IsTailscaleListener

func (c *Config) IsTailscaleListener() bool

IsTailscaleListener reports whether c is configured to run in Tailscale tsnet mode.

func (*Config) KeyRingAndId

func (c *Config) KeyRingAndId() (keyRing, keyId string, err error)

KeyRingAndId returns the GPG identity keyring path and the user's GPG keyID (TODO: length/case), if configured. TODO: which error value if not configured?

func (*Config) ListenAddr

func (c *Config) ListenAddr() string

ListenAddr returns the optional configured listen address in ":port" or "ip:port" form.

func (*Config) LowLevelJSONConfig

func (c *Config) LowLevelJSONConfig() map[string]interface{}

LowLevelJSONConfig returns the config's underlying low-level JSON form for debugging.

Deprecated: this is provided for debugging only and will be going away as the move to TOML-based configuration progresses. Do not depend on this.

func (*Config) SetKeepGoing

func (c *Config) SetKeepGoing(v bool)

SetKeepGoing changes each configured prefix to set "keepGoing" to true. This indicates that validation, reindexing, or recovery behavior should not cause the process to end.

func (*Config) SetReindex

func (c *Config) SetReindex(v bool)

func (*Config) StartApps

func (c *Config) StartApps() error

StartApps starts all the server applications that were configured during InstallHandlers. It should only be called after perkeepd has started serving, since these apps might request some configuration from Perkeep to finish initializing.

func (*Config) UIPath

func (c *Config) UIPath() string

UIPath returns the relative path to the server's user interface handler, if the UI is configured. Otherwise it returns the empty string. It is not valid until after a call to InstallHandlers

If non-empty, the returned value will both begin and end with a slash.

func (*Config) UploadPublicKey

func (c *Config) UploadPublicKey(ctx context.Context) error

UploadPublicKey uploads the public key blob with the sign handler that was configured during InstallHandlers.

type HandlerInstaller

type HandlerInstaller interface {
    Handle(path string, h http.Handler)
}

A HandlerInstaller is anything that can register an HTTP Handler at a prefix path. Both *http.ServeMux and perkeep.org/pkg/webserver.Server implement HandlerInstaller.

Website layout inspired by memcached.
Content by the authors.