base

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package base provide some basic functions

Index

Constants

View Source
const (
	// AllFuncLevelMask indicates all levels
	AllFuncLevelMask FuncLevel = ^FuncLevel(0)

	// MinorFuncLevelMask contains minor level
	MinorFuncLevelMask = MinorFuncLevel

	// MajorFuncLevelMask contains major level and minor level
	MajorFuncLevelMask = MajorFuncLevel | MinorFuncLevel

	// LoggerFuncLevelMask contains logger level
	LoggerFuncLevelMask = loggerReloadLevel | loggerLevelLevel

	// PrimaryLevelMask contains logger mask and primary mask
	PrimaryFuncLevelMask = LoggerFuncLevelMask | MajorFuncLevelMask
)

LevelMask

Variables

This section is empty.

Functions

func GetBuildDir

func GetBuildDir() string

GetBuildDir return directory that set by LDFLAGS at building

func GetBuildGo

func GetBuildGo() string

GetBuildGo return version of go compiler

func GetBuildTime

func GetBuildTime() string

GetBuildTime return time that set by LDFLAGS at building

func GetBuildVCS

func GetBuildVCS() []string

GetBuildVCS return version control system information

func GetExecDir

func GetExecDir() string

GetExecDir return directory of execute file

func GetExecName

func GetExecName() string

GetExecName return file name of execute file

func GetPath

func GetPath(p ...string) string

GetPath return the absolute path relative to the binary file by input

func GetPathWork

func GetPathWork(p ...string) string

GetPathWork return the absolute path relative to the work directory by input

func GetReloadTime

func GetReloadTime() time.Time

GetReloadTime return reload time of app

func GetStartTime

func GetStartTime() time.Time

GetStartTime return start time of app

func GetWorkDir

func GetWorkDir() string

GetWorkDir return working directory at staring

func LiteMode

func LiteMode() bool

LiteMode return whether it is currently in lite mode

func LiteModeDisable

func LiteModeDisable()

LiteModeDisable disable lite mode

func LiteModeEnable

func LiteModeEnable()

LiteModeEnable enable lite mode

func Reload

func Reload(args ...FuncLevel)

Reload will execute functions registered

func ReloadCancel

func ReloadCancel(key string, args ...FuncLevel)

ReloadCancel cancel a function that has been registered by ReloadRegister

func ReloadRegister

func ReloadRegister(key string, function func(context.Context) error, args ...FuncLevel)

ReloadRegister register a function that will be executed while reload

func Retire

func Retire(code int, args ...bool)

Retire will execute all functions registered Shadow process will be started if args[0] is true

func RetireCancel

func RetireCancel(key string, args ...FuncLevel)

RetireCancel cancel a function that has been registered by RetireRegister

func RetireRegister

func RetireRegister(key string, function func(context.Context) error, args ...FuncLevel)

RetireRegister register a function that will be executed while retire

func Shadow

func Shadow()

Shadow will retire current process and start a shadow process

func TestMode

func TestMode() bool

TestMode return whether it is currently in test mode

Types

type Config

type Config struct {
	*viper.Viper
	// contains filtered or unexported fields
}

Config wrap *viper.Viper

func AcceptConfig

func AcceptConfig(new *Config) (old *Config)

AcceptConfig for base package

func GetConfig

func GetConfig() *Config

GetConfig return a *viper.Viper instance that accept from other package or default

func (*Config) BindOption

func (c *Config) BindOption(defaultValue interface{}, configKeys ...string) *Option

BindOption return an *Option bind with the *Config

type FuncLevel

type FuncLevel uint8

FuncLevel indicates level of a function Functions in same level with be executed in parallel

const (

	// MajorFuncLevel is used for normal functions that execute firstly
	MajorFuncLevel FuncLevel
	// MinorFuncLevel is used for normal functions that execute secondly
	MinorFuncLevel
)

type Logger

type Logger struct {
	*zap.SugaredLogger
	// contains filtered or unexported fields
}

Logger wrap *zap.SugaredLogger

func AcceptLogger

func AcceptLogger(new *Logger) (old *Logger)

AcceptLogger for base package

func GetLogger

func GetLogger() *Logger

GetLogger return a *zap.SugaredLogger instance that accept from other package or default

type LoggerOption

type LoggerOption struct {
	Level      *Option
	Filename   *Option
	Directory  *Option
	Compress   *Option
	Stderr     *Option
	MaxAge     *Option
	MaxSize    *Option
	MaxBackups *Option
}

LoggerOption for Logger

type Option

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

Option contains a default value and bind key with a *Config

func NewOption

func NewOption(defaultValue interface{}, configKeys ...string) *Option

NewOption return an *Option

func (*Option) Bool

func (o *Option) Bool() (ret bool)

Bool return bool value of *Option

func (*Option) Duration

func (o *Option) Duration() (ret time.Duration)

Duration return time.Duration value of *Option

func (*Option) Int

func (o *Option) Int() (ret int)

Int return int value of *Option

func (*Option) IsSet added in v0.1.3

func (o *Option) IsSet() bool

IsSet checks to see if the key has been set in config file

func (*Option) String

func (o *Option) String() (ret string)

String return string value of *Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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