mft

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 6 Imported by: 30

README

mft

some tools (golang)

ID Generator

struct *mft.G - generator next id
field G.AddValue - adds value that adds to each generated id use it with *G.RvGetPart() method
valid values for G.AddValue: 10 - 9990 step 10
method *G.RvGetPart() - returns ids as time.Now().UnixNano() / 10000 * 10000 + AddValue[10-9990; s10] + tail[0-9]
method *G.RvGet() - returns ids as time.Now().UnixNano() / 10000 * 10000 + AddValue + tail[unbounded]
*G.RvGet() faster then *G.RvGetPart() however does not provide uniqueness between generators when using different G.AddValue

Global generator

mft.GlobalGenerator.AddValue = 100 sets global AddValue as 100
mft.RvGet() generates next id
mft.RvGetPart() generates next id uniqueness between generators when using different mft.GlobalGenerator.AddValue

Error

You can create error with code and error from error

Flags

mft.FillCallStack = true - enables call stack

Error codes

Use mft.AddErrorsCodes(m) for append error codes
Use mft.GenerateError(code, params...) for create error with code
Use mft.GenerateErrorE(m) for create error with code from another error
Use mft.GenerateErrorSubList(m) for create error with code from errors list

Example:
package main
import (
	"fmt"
	"github.com/myfantasy/mft"
)
func main() {
	var e error
	e = mft.ErrorCS(7, "Bond Error")
	fmt.Println(e)
	e = mft.ErrorCSE(12, "M Error", e)
	fmt.Println(e)
}
[7] Bond Error
[12] M Error    [7] Bond Error

Documentation

Index

Constants

View Source
const ErrorCommonCode int = 50000

ErrorCommonCode - no code error

Variables

View Source
var ErrorsCodes map[int]string = map[int]string{
	50000: "Undescribe error",
}
View Source
var FillCallStack bool = false
View Source
var InnerErrorPrefix string = "  "

Functions

func AddErrorsCodes added in v0.2.1

func AddErrorsCodes(m map[int]string)

func GetStack added in v0.2.0

func GetStack() string

func RvGet

func RvGet() int64

RvGet - Generate Next RV (sync)

func RvGetPart

func RvGetPart() int64

RvGetPart - Generate Next RV (sync)

Types

type Error

type Error struct {
	Code              int      `json:"code,omitempty"`
	Msg               string   `json:"msg,omitempty"`
	InternalErrorText string   `json:"iet,omitempty"`
	InternalError     *Error   `json:"ie,omitempty"`
	InternalErrors    []*Error `json:"ies,omitempty"`
	CallStack         string   `json:"call_stack,omitempty"`

	Labels map[ErrorLabelName]string `json:"labels,omitempty"`
}

Error type with internal

func ErrorCE

func ErrorCE(code int, err error) *Error

ErrorCE make Error from any error

func ErrorCS

func ErrorCS(code int, err string) *Error

ErrorCS make Error from string

func ErrorCSE

func ErrorCSE(code int, err string, internalError error) *Error

ErrorCSE make Error from string with internal error

func ErrorCSEf added in v0.1.2

func ErrorCSEf(code int, internalError error, format string, a ...interface{}) *Error

ErrorCSEf make Error from string with internal error

func ErrorCSf added in v0.1.2

func ErrorCSf(code int, format string, a ...interface{}) *Error

ErrorCSf make Error from string

func ErrorE

func ErrorE(err error) *Error

ErrorE make Error from any error

func ErrorNew

func ErrorNew(msg string, internalError error) *Error

ErrorNew - Create new Error from msg and another error

func ErrorNew2

func ErrorNew2(msg string, internalError error, internal2Error error) *Error

ErrorNew2 - Create new Error

func ErrorNew2f added in v0.1.2

func ErrorNew2f(internalError error, internal2Error error, format string, a ...interface{}) *Error

ErrorNew2f - Create new Error

func ErrorNewf added in v0.1.2

func ErrorNewf(internalError error, format string, a ...interface{}) *Error

ErrorNewf - Create new Error from msg and another error

func ErrorS

func ErrorS(err string) *Error

ErrorS make Error from string

func ErrorSf added in v0.1.2

func ErrorSf(format string, a ...interface{}) *Error

ErrorSf make Error from string

func GenerateError added in v0.2.1

func GenerateError(key int, a ...interface{}) *Error

GenerateError - generate error with code

func GenerateErrorE added in v0.2.1

func GenerateErrorE(key int, err error, a ...interface{}) *Error

GenerateErrorE - generate error with code and exists error

func GenerateErrorSubList added in v0.2.1

func GenerateErrorSubList(key int, sub []*Error, a ...interface{}) *Error

GenerateErrorSubList -

func (*Error) AppendE

func (e *Error) AppendE(errs error) *Error

AppendE append next error level saving code

func (*Error) AppendLabel added in v0.2.2

func (e *Error) AppendLabel(name ErrorLabelName, value string) *Error

func (*Error) AppendLabels added in v0.2.2

func (e *Error) AppendLabels(labels map[ErrorLabelName]string) *Error

func (*Error) AppendList added in v0.2.0

func (e *Error) AppendList(sub ...*Error) (eOut *Error)

func (*Error) AppendS

func (e *Error) AppendS(errs string) *Error

AppendS append next error level saving code

func (*Error) AppendSf added in v0.1.2

func (e *Error) AppendSf(format string, a ...interface{}) *Error

AppendSf append next error level saving code

func (*Error) Error

func (e *Error) Error() string

Error implement error interface

func (*Error) GetLabel added in v0.2.2

func (e *Error) GetLabel(name ErrorLabelName) (value string, ok bool)

func (*Error) GetLabelOrDefailt added in v0.2.2

func (e *Error) GetLabelOrDefailt(name ErrorLabelName, defaultValue string) (value string)

type ErrorLabelName added in v0.2.2

type ErrorLabelName string

type ErrorProvider

type ErrorProvider interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})

	Debug(args ...interface{})
	Info(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
	Panic(args ...interface{})

	Debugln(args ...interface{})
	Infoln(args ...interface{})
	Warningln(args ...interface{})
	Errorln(args ...interface{})
	Fatalln(args ...interface{})
	Panicln(args ...interface{})
}

ErrorProvider interface for error provider mostly for background processes

type G

type G struct {
	AddValue int64 `json:"generator_add_value,omitempty"`
	// contains filtered or unexported fields
}

G Generator

var GlobalGenerator *G = &G{}

func (*G) RvGet

func (g *G) RvGet() int64

RvGet2 - Generate Next RV (sync)

func (*G) RvGetOrGlobal added in v0.2.3

func (g *G) RvGetOrGlobal() int64

RvGet2 - Generate Next RV (sync) global is used if g == nil

func (*G) RvGetPart

func (g *G) RvGetPart() int64

RvGetPart - Generate Next RV (sync) partitioned by (x%10000)/10

func (*G) RvGetPartOrGlobal added in v0.2.3

func (g *G) RvGetPartOrGlobal() int64

RvGetPartOrGlobal - Generate Next RV (sync) partitioned by (x%10000)/10 global is used if g == nil

Directories

Path Synopsis
Package im - int math simple operations lake max min etc for int
Package im - int math simple operations lake max min etc for int

Jump to

Keyboard shortcuts

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