Documentation ¶
Index ¶
- Constants
- Variables
- func CacheTime() string
- func Dup(from, to int) error
- func GenerateUUID() string
- func GoWithRecover(handler func(), recoverHandler func(r interface{}))
- func ReadJsonFile(file string, v interface{}) error
- func RegisterRecoverLogger(f func(w io.Writer, r interface{}))
- func ResetHjiackStdPipeline()
- func SetHijackStdPipeline(filepath string, stdout, stderr bool)
- func WriteFileSafety(filename string, data []byte, perm os.FileMode) (err error)
- type ExpiredMap
- type Mutex
- type SyncList
- type Ticker
- type Timer
Constants ¶
const JsonExt = ".json"
const NeverExpire time.Duration = -1
Variables ¶
var ErrIgnore = errors.New("error ignore")
Functions ¶
func CacheTime ¶
func CacheTime() string
CacheTime returns a time cache in seconds. we use a cache to reduce the format
func GenerateUUID ¶
func GenerateUUID() string
GenerateUUID generates an uuid https://tools.ietf.org/html/rfc4122 crypto.rand use getrandom(2) or /dev/urandom It is maybe occur an error due to system error panic if an error occurred
func GoWithRecover ¶
func GoWithRecover(handler func(), recoverHandler func(r interface{}))
GoWithRecover wraps a `go func()` with recover()
func ReadJsonFile ¶
ReadJsonFile reads a json into interface If a file is not .json ignore it If a file is empty, ignore it
func RegisterRecoverLogger ¶
RegisterRecoverLogger replace the log handler when go with recover catch a panic notice the replaced handler should be simple. if the handler panic, the recover handler will be failed.
func ResetHjiackStdPipeline ¶
func ResetHjiackStdPipeline()
func SetHijackStdPipeline ¶
SetHijackStdPipeline hijacks stdout and stderr outputs into the file path
Types ¶
type ExpiredMap ¶
type ExpiredMap struct { // When the cache expires, it is used to update the cache. UpdateHandler func(interface{}) (interface{}, bool) // contains filtered or unexported fields }
func NewExpiredMap ¶
func NewExpiredMap(handler func(interface{}) (interface{}, bool), syncMod bool) *ExpiredMap
handler is used to update the data if the cache is invalid during Get. syncMod is set true means that the handler is called synchronously, and the others are asynchronous.
func (*ExpiredMap) Get ¶
func (e *ExpiredMap) Get(key interface{}) (interface{}, bool)
Get the cache indexed by key. If the cache is hit, the bool value indicates whether the cache is expired.
func (*ExpiredMap) Set ¶
func (e *ExpiredMap) Set(key, val interface{}, valid time.Duration)
Set a key and val with an expiration time. key and val represent cached index and user data. valid is used to set the expire time of the cache. For example, if valid=10 means the data expires after 10 Duration.
type SyncList ¶
type SyncList struct {
// contains filtered or unexported fields
}
SyncList similar with the builtin List container while it is concurrency safe.
func (*SyncList) PushBack ¶
PushBack inserts a new element e with value v at the back of list l and returns e.
func (*SyncList) Remove ¶
Remove removes e from l if e is an element of list l. It returns the element value e.Value. The element must not be nil.
func (*SyncList) VisitSafe ¶
func (l *SyncList) VisitSafe(f func(v interface{}))
VisitSafe means the visit function f can visit each element safely even f may block some time. Also, it won't block other operations(e.g. Remove) when the visit function f is blocked. But, it can not run parallel since there is an instance level curr point.