pkgCtl

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 8 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

This section is empty.

Functions

func Bootstrap added in v1.0.0

func Bootstrap(activeFunc func())

func Register added in v1.5.0

func Register(seq int, name string, handler HandlerFunc)

func UseValue added in v1.4.1

func UseValue[T any](ctx *Context, key string) (T, bool)
Example
package main

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

var ctx = pkgCtl.New()

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

	c.Set("K", "V")

	catch, ok := pkgCtl.UseValue[string](c, "K")
	if !ok {
		return
	}

	if catch != "V" {
		// fail
	}
	// success
}
Output:

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(opts ...Option) *Context

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()

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

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

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 DUnit added in v1.5.0

type DUnit struct {
	Seq  int
	Name string
	Unit Handler
}

type Handler

type Handler interface {
	Create() error
	Start() error
	Destroy() error
	Async() bool
	// contains filtered or unexported methods
}

type HandlerFunc added in v1.2.0

type HandlerFunc func(*Context) Handler

type Logger added in v1.2.0

type Logger interface {
	Debug(msg string, v ...any)
	Info(msg string, v ...any)
	Warn(msg string, v ...any)
	Error(msg string, v ...any)
}

type Option added in v1.5.0

type Option func(*Context)

func WithLogger added in v1.5.0

func WithLogger(logger Logger) Option

func WithValues added in v1.5.0

func WithValues(values map[string]any) Option

type UnimplementedHandler added in v1.5.0

type UnimplementedHandler struct{}

func (UnimplementedHandler) Async added in v1.5.0

func (h UnimplementedHandler) Async() bool

func (UnimplementedHandler) Create added in v1.5.0

func (h UnimplementedHandler) Create() error

func (UnimplementedHandler) Destroy added in v1.5.0

func (h UnimplementedHandler) Destroy() error

func (UnimplementedHandler) Start added in v1.5.0

func (h UnimplementedHandler) Start() error

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