base

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 22 Imported by: 0

README

go-base

Documentation

Overview

Package base provide some base functions of GoLang

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Daemon

func Daemon()

Daemon will retire current process and pretend to start a daemon process

func GetAppName

func GetAppName() string

GetAppName return name of app

func GetAssetsPath

func GetAssetsPath(p ...string) string

GetAssetsPath return the absolute path of assets

func GetBuildDir

func GetBuildDir() string

GetBuildDir return directory at building

func GetBuildGo

func GetBuildGo() string

GetBuildGo return version of go at building

func GetBuildHash

func GetBuildHash() string

GetBuildHash return Git HEAD hash of source code at building

func GetBuildTime

func GetBuildTime() string

GetBuildTime return time at building

func GetExecDir

func GetExecDir() string

GetExecDir return directory of execute file

func GetExecName

func GetExecName() string

GetExecName return file name of execute file

func GetIP added in v0.0.4

func GetIP() net.IP

GetIP return outer IP of host

func GetPath

func GetPath(p ...string) string

GetPath return the absolute path relative to the binary file 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 GetVersion

func GetVersion() string

GetVersion return version of app

func GetWorkDir

func GetWorkDir() string

GetWorkDir return working directory at staring

func IsLiteMode

func IsLiteMode() bool

IsLiteMode return whether it is currently in lite mode

func LiverCancel

func LiverCancel(key string)

LiverCancel is used to cancel a liver hunter

func LiverRegister

func LiverRegister(key string, timeout time.Duration)

LiverRegister is used to register a liver hunter

func Reload

func Reload()

Reload configure and logger, and functions in reloadFuncs

func ReloadCancel

func ReloadCancel(key string)

ReloadCancel is used to cancel a function to be executed when reload

func ReloadRegister

func ReloadRegister(function func() error, key string)

ReloadRegister is used to register a function to be executed when reload

func Retire

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

Retire will execute all functions in retireFuncs and exit by code

func RetireCancel

func RetireCancel(key string)

RetireCancel is used to cancel a function to be executed when retire

func RetireRegister

func RetireRegister(function func() error, key string)

RetireRegister is used to register a function to be executed when retire

func SetLiteMode

func SetLiteMode(mode bool)

SetLiteMode set whether it is in lite mode

func Usr2Register added in v0.0.9

func Usr2Register(usr2 func())

Usr2Register register a callback function that execute after SIGUSR2 received

Types

type Task

type Task struct {
	Tasker
	// contains filtered or unexported fields
}

Task context

func NewTask added in v0.0.5

func NewTask(tasker Tasker) (t *Task, err error)

NewTask return a task from tasker interface

func NewTasking added in v0.0.5

func NewTasking(tasker Tasker) (t *Task, err error)

NewTasking return a task from tasker interface and start immediately

func (*Task) Died

func (t *Task) Died() bool

Died return true if task has done

func (*Task) Fire

func (t *Task) Fire() error

Fire will trigger task immediately

func (*Task) Reload

func (t *Task) Reload() (err error)

Reload is used to reload task

func (*Task) Start

func (t *Task) Start() (err error)

Start the Task

func (*Task) Stop

func (t *Task) Stop() (err error)

Stop the Task

type TaskBase

type TaskBase struct {
	Name string
	Type TaskType
	Log  *logrus.Entry

	// Trigger's type is according to task type
	//   TaskTypeManual:     nil
	//   TaskTypeOnAccept:   net.Listener
	//   TaskTypeOnChannel:  Channel
	//   TaskTypeOnInterval: time.Duration
	Trigger interface{}
	// Argument's value is according to task type
	//   TaskTypeManual:     enable auto reload if value is true
	//   TaskTypeOnAccept:   net.Conn that accept from net.Listener
	//   TaskTypeOnChannel:  value that received from channel
	//   TaskTypeOnInterval: disable liver hunter if value is true
	Argument interface{}

	// Level is used to control log level of complex log
	Level logrus.Level

	// Log less if Lite is true
	// TaskOnInterval will sleep if Sleep flag is true
	// Task will schedule immediately after start if Immediately flag is true
	Lite, Sleep, Immediately bool
	// contains filtered or unexported fields
}

TaskBase is used for options of Task It must be wrapped in struct which implement Tasker interface by unnamed pointer

type IntervalTask struct {
    *TaskBase
    variables...
}

type TaskType added in v0.0.5

type TaskType uint

TaskType is used to indicate type of task

const (
	// TaskTypeManual indicates task will schedule manually
	TaskTypeManual TaskType = 0
	// TaskTypeOnAccept indicates task will schedule after tcp connection was established
	TaskTypeOnAccept TaskType = 1 << iota
	// TaskTypeOnChannel indicates task will schedule after data received from the channel
	TaskTypeOnChannel
	// TaskTypeOnInterval indicates task will schedule on interval
	TaskTypeOnInterval
)

type Tasker

type Tasker interface {
	// Schedule will execute when trigger fire
	Schedule(context.Context) error

	// Reload will execute when start or reload
	Reload(context.Context) error
	// Retire will execute when destruct
	Retire(context.Context) error
}

Tasker Interface

Directories

Path Synopsis
Package client - Http Client
Package client - Http Client
Package kv provide k/v storage by LevelDB
Package kv provide k/v storage by LevelDB
Package s3kv provide k/v storage by S3 Resty API
Package s3kv provide k/v storage by S3 Resty API

Jump to

Keyboard shortcuts

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