lib

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package lib defines common code between op server and clients

Index

Constants

View Source
const (
	CmdCancel  CmdSwitch = "-c" // cancel client command; not for end users
	CmdExit              = "-e" // shut down dedicated server
	CmdGlobal            = "-g" // global switch; only valid as a command line arg
	CmdKill              = "-k" // kill routes
	CmdList              = "-l" // list active routes
	CmdMeta              = "-m" // generate config from template and meta
	CmdPrint             = "-p" // print config routes
	CmdRestart           = "-r" // restart routes
	CmdRun               = ""   // run routes
	CmdServer            = "-s" // run as dedicated server
)

Variables

View Source
var (
	BasePath     string // general pipe directory
	LockPath     string // server lock file
	ConfigPath   string // config file path
	TemplatePath string // template file path
	MetaPath     string // meta file path
	Port         string // server port
)
View Source
var (
	ArgSwitch CmdSwitch // execution switch
	ArgMajor  string    // route to execute, or meta variant to apply
	ArgMinor  string    // proc to execute
)

Functions

func ExecuteTemplate

func ExecuteTemplate(variant string) error

ExecuteTemplate reads the template from "op_template.yaml" in the current directory and applies the specified variant to it from working meta. If the OP_TEMPLATE env is set, reads the template from there instead. See DecodeMeta for meta specifications.

func PipePaths

func PipePaths(id byte) [3]string

PipePaths returns the full paths for the pipe set to be used by the client with given id.

func UpdateMeta

func UpdateMeta(m Meta) error

UpdateMeta updates the meta file to the specified meta.

Types

type Cmd

type Cmd struct {
	Sw        CmdSwitch        // command switch
	Namespace string           // target namespace
	Route     string           // target route
	Proc      string           // target proc
	Config    map[string]Route // manifest to use for command; may be nil for commands that don't need it
}

Cmd represents an op program command

type CmdSwitch

type CmdSwitch string

type Fmt

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

A Fmt wraps an io.Writer to be concurrent safe. Also provides fmt package formating.

var (
	Stdout *Fmt = NewFmt(os.Stdout)
	Stderr *Fmt = NewFmt(os.Stderr)
)

func NewFmt

func NewFmt(w io.Writer) *Fmt

func (*Fmt) Print

func (x *Fmt) Print(a ...interface{}) (n int, err error)

func (*Fmt) Println

func (x *Fmt) Println(a ...interface{}) (n int, err error)

func (*Fmt) Write

func (x *Fmt) Write(b []byte) (int, error)

type Manifest

type Manifest struct {
	Namespace string
	Var       map[string]string
	Env       map[string]string
	Routes    map[string]Route
}

A Manifest holds routes and their individual process configs.

func DecodeConfig

func DecodeConfig() (Manifest, error)

DecodeConfig returns the manifest found at config path ("op.yaml" by default).

func MakeManifest

func MakeManifest() Manifest

type Meta

type Meta struct {
	Active   string
	Variants map[string]map[string]string
}

func DecodeMeta

func DecodeMeta() (Meta, error)

DecodeMeta returns a meta object from "op_meta.yaml" in the current directory. If the OP_META env is set, decodes from there instead.

type Proc

type Proc struct {
	Var  map[string]string
	Env  map[string]string
	Name string
	Path string
	Dir  string
	Args []string
	In   string
	Out  string
	Err  string
}

A Proc holds the information necessary to execute a process.

type Route

type Route struct {
	Default   bool              // will run on no-argument forms
	Namespace string            // route-scope namespace
	Var       map[string]string // route-scope var
	Env       map[string]string // route-scope env
	Procs     []Proc            // process configurations
}

A Route holds information relevant to a single execution route.

Jump to

Keyboard shortcuts

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