pareto

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 7 Imported by: 0

README

pareto

Frequently used go code for 80% projects when programming.

NOT stable yet and may change dramatically.

Features:

  • basics(box)
    • type converters
    • encoder & decoders
    • file operations
    • math functions
    • network operations
    • timestamps
    • cpu id
  • meta patterns
    • loop controller
    • state machine
  • network topology
    • MQTT broker embedded based on Mochi
    • MQTT client based on paho
    • MQ client based on nats
    • RPC server based on msgpack-rpc
    • RPC client based on msgpack-rpc
    • inter-module communication
      • inner-proc event bus based on EventBus
  • distributed node management
    • node provisioning & configuration
    • node status keeping & monitoring
    • node online/offline(join & leave)
    • admin api
      • node info maintenance
      • uploader & downloader
  • inner-process services
    • logging based on logrus
    • profiling
    • config management based on viper
    • options management based on cobra
    • working directory management
    • resource management
      • string literals

Examples:

package main

import (
	"fmt"
	"github.com/zourva/pareto"
	"github.com/zourva/pareto/meta"
	"time"
)

func main() {
	pareto.Setup()

	loop := meta.NewLoop("monitor", meta.LoopConfig{
		Tick:        1000,  // tick interval, 1000 ms
		Work:        1,     //event callback trigger ticks
		Sync:        false, //execute callback in a separate goroutine
		BailOnError: false,
	})

	loop.Run(meta.LoopRunHook{
		Working: func() error {
			fmt.Println("monitoring...")
			return nil
		},
	})

	time.Sleep(time.Second * 10)

	loop.Stop()

	pareto.Teardown()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config added in v0.2.0

func Config() *config.Store

Config returns the default global instance of config object.

func DefaultConfig added in v0.2.0

func DefaultConfig(v *config.Store)

func DefaultNormalize added in v0.2.0

func DefaultNormalize(v *config.Store) error

func Logger added in v0.2.0

func Logger() *logger.Logger

Logger returns the default global instance of logger object.

func SetupWithOpts

func SetupWithOpts(options ...Option)

SetupWithOpts creates a pareto environment for an app with the given options.

func Teardown

func Teardown()

Teardown tears down the working space.

Types

type ConfigDefaultsProvider added in v0.2.0

type ConfigDefaultsProvider = func(v *config.Store)

type ConfigNormalizer added in v0.2.0

type ConfigNormalizer = func(v *config.Store) error

type LoggerProvider added in v0.2.0

type LoggerProvider = func() *logger.Logger

type Option

type Option func(*Pareto)

Option defines pareto initialization options.

func DisableFlags added in v0.2.0

func DisableFlags() Option

DisableFlags disables flag.Parse.

func DisableLogger added in v0.2.0

func DisableLogger() Option

func WithConfigDefaultsProvider added in v0.2.0

func WithConfigDefaultsProvider(fn ConfigDefaultsProvider) Option

func WithConfigNormalizer added in v0.2.0

func WithConfigNormalizer(fn ConfigNormalizer) Option

WithConfigNormalizer provides a config normalizer function which will be called when the config, if exists, is loaded.

func WithConfigStore added in v0.2.0

func WithConfigStore(file string, ft config.FileType, dt config.DataType, rootKeys ...string) Option

WithConfigStore specifies a config file to load, which will overwrite the default pareto config store.

func WithJsonConfParser deprecated

func WithJsonConfParser(file string, obj any, normalize func(obj any) error) Option

WithJsonConfParser loads the json config file and invokes the normalize function.

Deprecated: WithJsonConfParser accepts json format config file only, and is outdated. Use WithConfigDefaultsProvider, WithConfigNormalizer and WithConfigStore instead.

func WithLogger

func WithLogger(l *logger.Logger) Option

WithLogger allows to provide a logger config as an option.

func WithLoggerProvider

func WithLoggerProvider(provider func() *logger.Logger) Option

WithLoggerProvider allows to provide a logger create function.

func WithWorkingDir

func WithWorkingDir(wd *env.WorkingDir) Option

WithWorkingDir acts the same as WithWorkingDirLayout except that it also set system level working dir, using os.Chdir, to the parent directory of this executable.

func WithWorkingDirLayout

func WithWorkingDirLayout(wd *env.WorkingDir) Option

WithWorkingDirLayout allows to hint working dir layout.

type Pareto added in v0.2.0

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

Pareto defines the context.

func New added in v0.2.0

func New() *Pareto

New create a pareto env.

func (*Pareto) Config added in v0.2.0

func (p *Pareto) Config() *config.Store

func (*Pareto) Logger added in v0.2.0

func (p *Pareto) Logger() *logger.Logger

func (*Pareto) Setup added in v0.2.0

func (p *Pareto) Setup()

Directories

Path Synopsis
box
env
cmd

Jump to

Keyboard shortcuts

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