server

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package server provides the core runtime for Blip.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ControlChans

func ControlChans() (stopChan, doneChan chan struct{})

ControlChans is a convenience function to return arguments for Run.

func Defaults

func Defaults() (blip.Env, blip.Plugins, blip.Factories)

Defaults returns the default environment, plugins, and factories. It is used in main.go as the args to Server.Boot. Third-party integration will likely _not_ call this function and, instead, provide its own environment, plugins, or factories when calling Server.Boot.

Types

type API

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

func NewAPI

func NewAPI(cfg blip.Config, ml *monitor.Loader) *API

func (*API) Run

func (api *API) Run() error

Run runs the API and restarts on error.

func (*API) ServeHTTP

func (api *API) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP allows the API to statisfy the http.HandlerFunc interface.

type CommandLine

type CommandLine struct {
	Options
	Args []string `arg:"positional"`
}

CommandLine represents options (--addr, etc.) and args: entity type, return labels, and query predicates. The caller is expected to copy and use the embedded structs separately, like:

var o config.Options = cmdLine.Options
for i, arg := range cmdline.Args {

func ParseCommandLine

func ParseCommandLine(args []string) (CommandLine, error)

ParseCommandLine parses the command line and env vars. Command line options override env vars. Default options are used unless overridden by env vars or command line options. Defaults are usually parsed from config files.

type Options

type Options struct {
	Config        string `arg:"env:BLIP_CONFIG"`
	Debug         bool   `arg:"env:BLIP_DEBUG"`
	Help          bool
	Log           bool `arg:"env:BLIP_LOG"`
	PrintConfig   bool `arg:"--print-config"`
	PrintDomains  bool `arg:"--print-domains"`
	PrintMonitors bool `arg:"--print-monitors"`
	PrintPlans    bool `arg:"--print-plans"`
	Run           bool `arg:"env:BLIP_RUN" default:"true"`
	Version       bool `arg:"-v"`
}

Options represents typical command line options: --addr, --config, etc.

type Server

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

Server is the core runtime for one instance of Blip. It's responsible for starting and running everything: Boot and Run, respectively. As long as the server is running, Blip is running.

See bin/blip/main.go for the simplest use case.

func (*Server) Boot

func (s *Server) Boot(env blip.Env, plugins blip.Plugins, factories blip.Factories) error

Boot boots Blip. That means it loads, validates, and creates everything, but it doesn't start (run) anything--that happens when Run is called. If Boot returns nil, then Blip is ready to run; else, any error is fatal: sometimes is too wrong for Blip to run (for example, an invalid config).

Boot must be called once before Run.

func (*Server) Run

func (s *Server) Run(stopChan, doneChan chan struct{}) error

Jump to

Keyboard shortcuts

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