proc

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: BSD-3-Clause Imports: 25 Imported by: 32

Documentation

Index

Constants

View Source
const (
	PRI_SYS_INIT      uint16 // init & register each system.module
	PRI_SYS_PRESTART         // prepare each system.module's depend
	PRI_MODULE               // init each module
	PRI_SYS_START            // start each system.module
	PRI_SYS_POSTSTART        // no use
)

Variables

View Source
var (
	DefaultProcess = NewProcess()
	ErrDryrun      = errors.New("dry run")
)

Functions

func AddFlags

func AddFlags(f *pflag.FlagSet)

func AttrFrom

func AttrFrom(ctx context.Context) (map[interface{}]interface{}, bool)

func AttrMustFrom

func AttrMustFrom(ctx context.Context) map[interface{}]interface{}

func ConfigVar added in v0.0.2

func ConfigVar(fs *pflag.FlagSet, path string, sample interface{}, opts ...configer.ConfigFieldsOption) error

func Configer added in v0.0.2

func Configer() configer.ParsedConfiger

func Context added in v0.0.2

func Context() context.Context

func Description

func Description() string

func Init

func Init(cmd *cobra.Command, opts ...ProcessOption) error

func Name

func Name() string

func NamedFlagSets

func NamedFlagSets() *flag.NamedFlagSets

func NewContext

func NewContext() context.Context

func NewRootCmd

func NewRootCmd(opts ...ProcessOption) *cobra.Command

func Parse added in v0.0.2

func PrintConfig

func PrintConfig(w io.Writer)

func PrintErrln added in v0.0.2

func PrintErrln(err error) int

func PrintFlags

func PrintFlags(fs *pflag.FlagSet, w io.Writer)

func RegisterFlags

func RegisterFlags(configPath, groupName string, sample interface{}, opts ...configer.ConfigFieldsOption) error

func RegisterHooks

func RegisterHooks(in []HookOps) error

func Shutdown

func Shutdown() error

func Start

func Start(fs *pflag.FlagSet) error

func WgFrom

func WgFrom(ctx context.Context) (*sync.WaitGroup, bool)

func WgMustFrom

func WgMustFrom(ctx context.Context) *sync.WaitGroup

func WithAttr

func WithAttr(ctx context.Context, attributes map[interface{}]interface{}) context.Context

func WithHookOps

func WithHookOps(parent context.Context, ops *HookOps) context.Context

func WithValue

func WithValue(parent context.Context, key interface{}, val interface{}) context.Context

WithValue returns a copy of parent in which the value associated with key is val.

func WithWg

func WithWg(ctx context.Context, wg *sync.WaitGroup)

WithWg returns a copy of parent in which the user value is set

Types

type ConfigOps added in v0.0.2

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

type HookFn

type HookFn func(context.Context) error

type HookOps

type HookOps struct {
	Hook        HookFn
	Owner       string
	HookNum     ProcessAction
	Priority    uint16
	SubPriority uint16
	Data        interface{}
	// contains filtered or unexported fields
}

func HookOpsFrom

func HookOpsFrom(ctx context.Context) (*HookOps, bool)

func (HookOps) Configer

func (p HookOps) Configer() configer.ParsedConfiger

func (HookOps) Context

func (p HookOps) Context() context.Context

func (HookOps) ContextAndConfiger

func (p HookOps) ContextAndConfiger() (context.Context, configer.ParsedConfiger)

func (HookOps) SetContext

func (p HookOps) SetContext(ctx context.Context)

type Process

type Process struct {
	*ProcessOptions
	// contains filtered or unexported fields
}

func NewProcess

func NewProcess(opts ...ProcessOption) *Process

func (*Process) AddFlags

func (p *Process) AddFlags(fs *pflag.FlagSet)

func (*Process) AddGlobalFlags added in v0.0.2

func (p *Process) AddGlobalFlags()

func (*Process) BindRegisteredFlags added in v0.0.2

func (p *Process) BindRegisteredFlags(fs *pflag.FlagSet) error

func (*Process) ConfigVar added in v0.0.2

func (p *Process) ConfigVar(fs *pflag.FlagSet, path string, sample interface{}, opts ...configer.ConfigFieldsOption) error

func (*Process) Context added in v0.0.2

func (p *Process) Context() context.Context

func (*Process) Description

func (p *Process) Description() string

func (*Process) Init added in v0.0.2

func (p *Process) Init(cmd *cobra.Command, opts ...ProcessOption) error

Init set configer options alloc p.ctx validate config each module sort hook options

func (*Process) Name

func (p *Process) Name() string

func (*Process) NewRootCmd

func (p *Process) NewRootCmd(opts ...ProcessOption) *cobra.Command

with proc.Start

func (*Process) Parse added in v0.0.2

func (*Process) PrintConfig

func (p *Process) PrintConfig(out io.Writer)

func (*Process) PrintFlags

func (p *Process) PrintFlags(fs *pflag.FlagSet, w io.Writer)

func (*Process) RegisterFlags added in v0.0.2

func (p *Process) RegisterFlags(configPath, groupName string, sample interface{}, opts ...configer.ConfigFieldsOption) error

func (*Process) RegisterHooks added in v0.0.2

func (p *Process) RegisterHooks(in []HookOps) error

RegisterHooks register hookOps as a module

func (*Process) Start

func (p *Process) Start(fs *pflag.FlagSet) error

type ProcessAction

type ProcessAction uint32
const (
	ACTION_START ProcessAction = iota
	ACTION_RELOAD
	ACTION_STOP
	ACTION_SIZE
)

func (ProcessAction) String

func (p ProcessAction) String() string

type ProcessOption

type ProcessOption func(*ProcessOptions)

func WithConfigOptions

func WithConfigOptions(options ...configer.ConfigerOption) ProcessOption

func WithContext

func WithContext(ctx context.Context) ProcessOption

func WithDescription

func WithDescription(description string) ProcessOption

func WithName

func WithName(name string) ProcessOption

func WithWaitGroup

func WithWaitGroup(wg *sync.WaitGroup) ProcessOption

func WithoutGroup

func WithoutGroup() ProcessOption

func WithoutLoop

func WithoutLoop() ProcessOption

type ProcessOptions

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

type ProcessPriority

type ProcessPriority uint32

func (ProcessPriority) String

func (p ProcessPriority) String() string

type ProcessStatus

type ProcessStatus uint32
const (
	STATUS_INIT ProcessStatus = iota
	STATUS_PENDING
	STATUS_RUNNING
	STATUS_RELOADING
	STATUS_EXIT
)

func (*ProcessStatus) Set

func (p *ProcessStatus) Set(v ProcessStatus)

Jump to

Keyboard shortcuts

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