pkgCtl

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

Package controller

  • a modular project management (startup) framework
go get github.com/RealFax/pkg-ctl@latest

how to use

  • First add pkg-ctl to your go.mod
  • Then refer to the example code to register your package in pkg-ctl

example

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultLogger = defaultLogger{
	log.New(os.Stderr, "", log.LstdFlags),
}

Functions

func Bootstrap added in v1.0.0

func Bootstrap(activeFunc func())

func RegisterHandler

func RegisterHandler(seq int, name string, handler HandlerFunc)
Example
package main

import (
	pkgCtl "github.com/RealFax/pkg-ctl"
)

func main() {
	pkgCtl.RegisterHandler(-1, "test-loader", func(c *pkgCtl.Context) pkgCtl.Handler {
		c.Set("ctx1", false)
		return nil
	})
}

Types

type Context added in v1.4.0

type Context struct {
	context.Context
	CancelFunc context.CancelFunc
	// contains filtered or unexported fields
}

func New added in v1.1.0

func New(logger Logger) *Context

func Self added in v1.3.0

func Self(ctx context.Context) (*Context, bool)

func Use added in v1.4.0

func Use(ctx context.Context) (*Context, bool)
Example
package main

import (
	pkgCtl "github.com/RealFax/pkg-ctl"
)

var ctx = pkgCtl.New(nil)

func main() {
	c, ok := pkgCtl.Use(ctx)
	if !ok {
		// not pkgCtl.Context
		return
	}

	// call pkgCtl.Context api
	c.Get("Key")
}

func (*Context) Del added in v1.4.0

func (c *Context) Del(key string)

func (*Context) Destroy added in v1.4.0

func (c *Context) Destroy() error

func (*Context) Exit added in v1.4.0

func (c *Context) Exit() error

func (*Context) Get added in v1.4.0

func (c *Context) Get(key string) (any, bool)

func (*Context) ListenAndDestroy added in v1.4.0

func (c *Context) ListenAndDestroy() error

func (*Context) Set added in v1.4.0

func (c *Context) Set(key string, value any)

func (*Context) Startup added in v1.4.0

func (c *Context) Startup() error

func (*Context) Stop added in v1.4.0

func (c *Context) Stop()

type DestroyUnit

type DestroyUnit struct {
	Seq  int
	Name string
	Unit Handler
}

type Handler

type Handler interface {
	Create() error
	Start() error
	Destroy() error
	Async() bool
}

type HandlerFunc added in v1.2.0

type HandlerFunc func(*Context) Handler

type Logger added in v1.2.0

type Logger interface {
	Debug(v ...any)
	Info(v ...any)
	Error(v ...any)
}

type Unit

type Unit struct {
	Seq    int
	Name   string
	Handle HandlerFunc
}

Jump to

Keyboard shortcuts

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