Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustMkDirAll ¶
func MustMkDirAll(basePath, dirName string)
MustMkDirAll behaves the same as `os.Mkdir`, but it will panic an error instead of return it.
func MustMkFile ¶
func MustMkFile(dirPath, fileName string)
MustMkFile create a file then close it, if there is an error, it will panic it
func ReturnErrorFromPanic ¶
ReturnErrorFromPanic is a function to handler a panic. Usage:
func foo() (retRrr error) {
defer utils.ReturnErrorFromPanic(&retErr, func(err error) {
fmt.Println(err)
})
// If you unwanted the handler function, you can use `nil` to instead of it.
// defer utils.ReturnErrorFromPanic(&retErr, nil)
// If there is a panic, `foo` will return an error which recover from ReturnErrorFromPanic.
// If there is an error to return, you can panic it,
// then the handler function can do something, like log the error, release the resource, etc.
if err != nil {
panic(err)
}
return
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.