proc

package module
v0.0.37 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: Unlicense Imports: 16 Imported by: 12

README

proc

Process control, logging and child processes

Description

Golang is a great language for concurrency, but sometimes you want parallelism, and it's often simpler to design apps as little units that plug together via RPC APIs. Services don't always have easy start/stop/reconfig/restart controls, and sometimes they use their own custom configuration scheme that is complicated to integrate with yours.

In addition, you may want to design your applications as neat little pieces, but how to attach them together and orchestrate them starting up and coming down cleanly, and not have to deal with several different ttys to get the logs.

Proc creates a simple framework for creating observable, controllable execution units out of your code, and more easily integrating the code of others.

This project is the merge of several libraries for logging, spawning and controlling child processes, and creating an RPC to child processes that controls the run of the child process. Due to the confusing duplication of signals as a means of control and the lack of uniformity in signals (ie windows) the goal of proc is to create one way to do, following the principles of design used for Go itself.

Badges

<insert badges here

Installation

For developers:

To make nice tagged versions with the version number in the commit as well as matching to the tag, there is a tool called bumper that bumps the version to the next patch version (vX.X.PATCH), embeds this new version number into version.go with the matching corresponding git commit hash. This will make importing this library at an exact commit much more human.

In addition, it makes it easy to make a nice multi line commit message as many repositories request in their CONTRIBUTION file by replacing -- with two carriage returns.

To install:

go install ./bumper/.

To use:

bumper make a commit comment here -- text after double \
    hyphen will be separated by a carriage return -- \
    anywhere in the text

Usage

reasonably include in the README.

Support

Roadmap

  • Implement basic logger v0.0.x
  • Create concurrent safe configuration CLI/env/config system v0.1.x
    • Created types with mutex/atomic locks to prevent concurrent access
    • Created key value map type containing collections of concurrent safe values with concurrent safe access to members
    • Created tests for generating and concurrently accessing/mutating data
    • Created application directory and load configuration from file (using json, with all values stored in file, no unnecessary comments)
    • Read values from environment variables overlay on config file values
    • Created command line parsing system overlay values above previous
  • Child process control system v0.2.x
    • Launch, pause, continue and stop child process. Use only one method: the IPC API, no complication with signals.
    • Read and pass through logging from child process
    • Correctly handle process signals from OS/tty to trigger orderly shutdown of child processes and leave none orphaned

Contributing

Authors and acknowledgment

David Vennik david@cybriq.systems

License

Unlicenced: see here

Project status

In the process of revision and merging together several related libraries that need to be unified.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// App is the name of the application
	App = "  main"
	// AllSubsystems stores all of the package subsystem names found in the current
	// application
	AllSubsystems []string
)
View Source
var (
	// URL is the git URL for the repository
	URL = "github.com/cybriq/proc"
	// GitRef is the gitref, as in refs/heads/branchname
	GitRef = "refs/heads/master"
	// ParentGitCommit is the commit hash of the parent HEAD
	ParentGitCommit = "f9f2f2046ce52bfad7327b6fc89af1c7b661cf6c"
	// BuildTime stores the time when the current binary was built
	BuildTime = "2022-08-01T16:51:12+02:00"
	// SemVer lists the (latest) git tag on the build
	SemVer = "v0.0.37"
	// PathBase is the path base returned from runtime caller
	PathBase = "/home/davidvennik/src/github.com/cybriq/proc/"
	// Major is the major number from the tag
	Major = 0
	// Minor is the minor number from the tag
	Minor = 0
	// Patch is the patch version number from the tag
	Patch = 37
)
View Source
var LevelSpecs = map[LogLevel]LevelSpec{
	Off:   gLS(Off, 0, 0, 0),
	Fatal: gLS(Fatal, 255, 0, 0),
	Error: gLS(Error, 255, 128, 0),
	Check: gLS(Check, 255, 255, 0),
	Warn:  gLS(Warn, 255, 255, 0),
	Info:  gLS(Info, 0, 255, 0),
	Debug: gLS(Debug, 0, 128, 255),
	Trace: gLS(Trace, 128, 0, 255),
}

LevelSpecs specifies the id, string name and color-printing function

View Source
var LvlStr = map[LogLevel]string{
	Off:   "off  ",
	Fatal: "fatal",
	Error: "error",
	Warn:  "warn ",
	Info:  "info ",
	Check: "check",
	Debug: "debug",
	Trace: "trace",
}

Functions

func Add added in v0.0.30

func Add(pathBase string) (subsystem string)

Add adds a subsystem to the list of known subsystems and returns the string so it is nice and neat in the package logg.go file

func GetLoc added in v0.0.30

func GetLoc(skip int, subsystem string) (output string)

GetLoc calls runtime.Caller and formats as expected by source code editors for terminal hyperlinks

Regular expressions and the substitution texts to make these clickable in Tilix and other RE hyperlink configurable terminal emulators:

This matches the shortened paths generated in this command and printed at the very beginning of the line as this logger prints:

^((([\/a-zA-Z@0-9-_.]+/)+([a-zA-Z@0-9-_.]+)):([0-9]+))
/usr/local/bin/goland --line $5 $GOPATH/src/github.com/p9c/matrjoska/$2

I have used a shell variable there but tilix doesn't expand them, so put your GOPATH in manually, and obviously change the repo subpath.

func Item added in v0.0.30

func Item(m *metadata) (t types.Item)

func List added in v0.0.30

func List(items ...string) []string

List is a more compact way of declaring a []string

func New added in v0.0.30

func New(args Desc) *metadata

New allows you to create a metadata with a sparsely filled, named field struct literal.

name, type, group and tags all will be canonicalized to lower case.

func SetLogLevel added in v0.0.30

func SetLogLevel(l LogLevel)

func SetTimeStampFormat added in v0.0.30

func SetTimeStampFormat(format string)

func Version added in v0.0.30

func Version() string

Version returns a pretty printed version information string

Types

type BoolT added in v0.0.35

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

func NewBool added in v0.0.30

func NewBool(m *metadata) (b *BoolT)

func (BoolT) Aliases added in v0.0.35

func (m BoolT) Aliases() []string

func (BoolT) Bool added in v0.0.35

func (b BoolT) Bool() bool

func (BoolT) Default added in v0.0.35

func (m BoolT) Default() string

func (BoolT) Description added in v0.0.35

func (m BoolT) Description() string

func (BoolT) Documentation added in v0.0.35

func (m BoolT) Documentation() string

func (BoolT) Duration added in v0.0.35

func (b BoolT) Duration() time.Duration

func (BoolT) Float added in v0.0.35

func (b BoolT) Float() float64

func (*BoolT) FromString added in v0.0.35

func (b *BoolT) FromString(s string) error

func (BoolT) Group added in v0.0.35

func (m BoolT) Group() string

func (BoolT) Int added in v0.0.35

func (b BoolT) Int() int64

func (BoolT) List added in v0.0.35

func (b BoolT) List() []string

func (BoolT) Name added in v0.0.35

func (m BoolT) Name() string

func (*BoolT) Set added in v0.0.35

func (b *BoolT) Set(bo bool)

func (BoolT) String added in v0.0.35

func (b BoolT) String() string

func (BoolT) Tags added in v0.0.35

func (m BoolT) Tags() []string

func (BoolT) Type added in v0.0.35

func (m BoolT) Type() types.Type

func (BoolT) Uint added in v0.0.35

func (b BoolT) Uint() uint64

type Chk

type Chk func(e error) bool

Chk is a shortcut for printing if there is an error, or returning true

type Configs added in v0.0.30

type Configs struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func Create added in v0.0.30

func Create(items ...Desc) (c Configs)

func (*Configs) Get added in v0.0.30

func (c *Configs) Get(name string) (t types.Item, err error)

func (*Configs) MarshalJSON added in v0.0.30

func (c *Configs) MarshalJSON() ([]byte, error)

func (*Configs) UnmarshalJSON added in v0.0.30

func (c *Configs) UnmarshalJSON(bytes []byte) error

type Desc added in v0.0.30

type Desc struct {
	Name, Group, Description, Documentation, Default string
	Type                                             types.Type
	Tags, Aliases                                    []string
}

Desc is the named field form of metadata for generating a metadata

type DurT added in v0.0.35

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

func NewDuration added in v0.0.30

func NewDuration(m *metadata) (b *DurT)

func (DurT) Aliases added in v0.0.35

func (m DurT) Aliases() []string

func (DurT) Bool added in v0.0.35

func (d DurT) Bool() bool

func (DurT) Default added in v0.0.35

func (m DurT) Default() string

func (DurT) Description added in v0.0.35

func (m DurT) Description() string

func (DurT) Documentation added in v0.0.35

func (m DurT) Documentation() string

func (DurT) Duration added in v0.0.35

func (d DurT) Duration() time.Duration

func (DurT) Float added in v0.0.35

func (d DurT) Float() float64

func (*DurT) FromString added in v0.0.35

func (d *DurT) FromString(s string) error

func (DurT) Group added in v0.0.35

func (m DurT) Group() string

func (DurT) Int added in v0.0.35

func (d DurT) Int() int64

func (DurT) List added in v0.0.35

func (d DurT) List() []string

func (DurT) Name added in v0.0.35

func (m DurT) Name() string

func (*DurT) Set added in v0.0.35

func (d *DurT) Set(du time.Duration)

func (DurT) String added in v0.0.35

func (d DurT) String() string

func (DurT) Tags added in v0.0.35

func (m DurT) Tags() []string

func (DurT) Type added in v0.0.35

func (m DurT) Type() types.Type

func (DurT) Uint added in v0.0.35

func (d DurT) Uint() uint64

type FltT added in v0.0.35

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

func NewFloat added in v0.0.30

func NewFloat(m *metadata) (b *FltT)

func (FltT) Aliases added in v0.0.35

func (m FltT) Aliases() []string

func (FltT) Bool added in v0.0.35

func (f FltT) Bool() bool

func (FltT) Default added in v0.0.35

func (m FltT) Default() string

func (FltT) Description added in v0.0.35

func (m FltT) Description() string

func (FltT) Documentation added in v0.0.35

func (m FltT) Documentation() string

func (FltT) Duration added in v0.0.35

func (f FltT) Duration() time.Duration

func (FltT) Float added in v0.0.35

func (f FltT) Float() float64

func (*FltT) FromString added in v0.0.35

func (f *FltT) FromString(s string) error

func (FltT) Group added in v0.0.35

func (m FltT) Group() string

func (FltT) Int added in v0.0.35

func (f FltT) Int() int64

func (FltT) List added in v0.0.35

func (f FltT) List() []string

func (FltT) Name added in v0.0.35

func (m FltT) Name() string

func (*FltT) Set added in v0.0.35

func (f *FltT) Set(fl float64)

func (FltT) String added in v0.0.35

func (f FltT) String() string

func (FltT) Tags added in v0.0.35

func (m FltT) Tags() []string

func (FltT) Type added in v0.0.35

func (m FltT) Type() types.Type

func (FltT) Uint added in v0.0.35

func (f FltT) Uint() uint64

type IntT added in v0.0.35

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

func NewInt added in v0.0.30

func NewInt(m *metadata) (b *IntT)

func (IntT) Aliases added in v0.0.35

func (m IntT) Aliases() []string

func (IntT) Bool added in v0.0.35

func (in IntT) Bool() bool

func (IntT) Default added in v0.0.35

func (m IntT) Default() string

func (IntT) Description added in v0.0.35

func (m IntT) Description() string

func (IntT) Documentation added in v0.0.35

func (m IntT) Documentation() string

func (IntT) Duration added in v0.0.35

func (in IntT) Duration() time.Duration

func (IntT) Float added in v0.0.35

func (in IntT) Float() float64

func (*IntT) FromString added in v0.0.35

func (in *IntT) FromString(s string) error

func (IntT) Group added in v0.0.35

func (m IntT) Group() string

func (IntT) Int added in v0.0.35

func (in IntT) Int() int64

func (IntT) List added in v0.0.35

func (in IntT) List() []string

func (IntT) Name added in v0.0.35

func (m IntT) Name() string

func (*IntT) Set added in v0.0.35

func (in *IntT) Set(i int64)

func (IntT) String added in v0.0.35

func (in IntT) String() string

func (IntT) Tags added in v0.0.35

func (m IntT) Tags() []string

func (IntT) Type added in v0.0.35

func (m IntT) Type() types.Type

func (IntT) Uint added in v0.0.35

func (in IntT) Uint() uint64

type LevelPrinter

type LevelPrinter struct {
	Ln Println
	// F prints like fmt.Println surrounded by log details
	F Printf
	// S uses spew.dump to show the content of a variable
	S Prints
	// C accepts a function so that the extra computation can be avoided if
	// it is not being viewed
	C Printc
	// Chk is a shortcut for printing if there is an error, or returning
	// true
	Chk Chk
}

LevelPrinter defines a set of terminal printing primitives that output with extra data, time, level, and code location

type LevelSpec

type LevelSpec struct {
	Name      string
	Colorizer func(format string, a ...interface{}) string
}

type LogLevel

type LogLevel int32
const (
	Off LogLevel = iota
	Fatal
	Error
	Check
	Warn
	Info
	Debug
	Trace
)

type Logger

type Logger struct {
	F, E, W, I, D, T LevelPrinter
}

func GetLogger added in v0.0.30

func GetLogger(pathBase string) (l *Logger)

GetLogger returns a set of LevelPrinter with their subsystem preloaded

type LstT added in v0.0.35

type LstT struct {
	*sync.Mutex
	// contains filtered or unexported fields
}

func NewList added in v0.0.30

func NewList(m *metadata) (b *LstT)

func (LstT) Aliases added in v0.0.35

func (m LstT) Aliases() []string

func (LstT) Bool added in v0.0.35

func (l LstT) Bool() bool

func (LstT) Default added in v0.0.35

func (m LstT) Default() string

func (LstT) Description added in v0.0.35

func (m LstT) Description() string

func (LstT) Documentation added in v0.0.35

func (m LstT) Documentation() string

func (LstT) Duration added in v0.0.35

func (l LstT) Duration() time.Duration

func (LstT) Float added in v0.0.35

func (l LstT) Float() float64

func (*LstT) FromString added in v0.0.35

func (l *LstT) FromString(s string) error

FromString converts a comma separated list of strings into a _lst

func (LstT) Group added in v0.0.35

func (m LstT) Group() string

func (LstT) Int added in v0.0.35

func (l LstT) Int() int64

func (LstT) List added in v0.0.35

func (l LstT) List() (li []string)

func (LstT) Name added in v0.0.35

func (m LstT) Name() string

func (*LstT) Set added in v0.0.35

func (l *LstT) Set(li ...string)

func (LstT) String added in v0.0.35

func (l LstT) String() (o string)

func (LstT) Tags added in v0.0.35

func (m LstT) Tags() []string

func (LstT) Type added in v0.0.35

func (m LstT) Type() types.Type

func (LstT) Uint added in v0.0.35

func (l LstT) Uint() uint64

type Printc

type Printc func(closure func() string)

Printc accepts a function so that the extra computation can be avoided if it is not being viewed

type Printf

type Printf func(format string, a ...interface{})

Printf prints like fmt.Println surrounded by log details

type Println

type Println func(a ...interface{})

Println prints lists of interfaces with spaces in between

type Prints

type Prints func(a ...interface{})

Prints prints a spew.Sdump for an interface slice

type StrT added in v0.0.35

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

func NewString added in v0.0.30

func NewString(m *metadata) (b *StrT)

func (StrT) Aliases added in v0.0.35

func (m StrT) Aliases() []string

func (StrT) Bool added in v0.0.35

func (s StrT) Bool() bool

func (StrT) Default added in v0.0.35

func (m StrT) Default() string

func (StrT) Description added in v0.0.35

func (m StrT) Description() string

func (StrT) Documentation added in v0.0.35

func (m StrT) Documentation() string

func (StrT) Duration added in v0.0.35

func (s StrT) Duration() time.Duration

func (StrT) Float added in v0.0.35

func (s StrT) Float() float64

func (*StrT) FromString added in v0.0.35

func (s *StrT) FromString(st string) error

func (StrT) Group added in v0.0.35

func (m StrT) Group() string

func (StrT) Int added in v0.0.35

func (s StrT) Int() int64

func (StrT) List added in v0.0.35

func (s StrT) List() []string

func (StrT) Name added in v0.0.35

func (m StrT) Name() string

func (*StrT) Set added in v0.0.35

func (s *StrT) Set(st string)

func (StrT) String added in v0.0.35

func (s StrT) String() string

func (StrT) Tags added in v0.0.35

func (m StrT) Tags() []string

func (StrT) Type added in v0.0.35

func (m StrT) Type() types.Type

func (StrT) Uint added in v0.0.35

func (s StrT) Uint() uint64

type UinT added in v0.0.35

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

func NewUint added in v0.0.30

func NewUint(m *metadata) (b *UinT)

func (UinT) Aliases added in v0.0.35

func (m UinT) Aliases() []string

func (UinT) Bool added in v0.0.35

func (u UinT) Bool() bool

func (UinT) Default added in v0.0.35

func (m UinT) Default() string

func (UinT) Description added in v0.0.35

func (m UinT) Description() string

func (UinT) Documentation added in v0.0.35

func (m UinT) Documentation() string

func (UinT) Duration added in v0.0.35

func (u UinT) Duration() time.Duration

func (UinT) Float added in v0.0.35

func (u UinT) Float() float64

func (*UinT) FromString added in v0.0.35

func (u *UinT) FromString(s string) error

func (UinT) Group added in v0.0.35

func (m UinT) Group() string

func (UinT) Int added in v0.0.35

func (u UinT) Int() int64

func (UinT) List added in v0.0.35

func (u UinT) List() []string

func (UinT) Name added in v0.0.35

func (m UinT) Name() string

func (*UinT) Set added in v0.0.35

func (u *UinT) Set(ui uint64)

func (UinT) String added in v0.0.35

func (u UinT) String() string

func (UinT) Tags added in v0.0.35

func (m UinT) Tags() []string

func (UinT) Type added in v0.0.35

func (m UinT) Type() types.Type

func (UinT) Uint added in v0.0.35

func (u UinT) Uint() uint64

Directories

Path Synopsis
cmd
gen

Jump to

Keyboard shortcuts

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