utils

package
Version: v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExist

func IsExist(path string) bool

IsExist judge whether the file/directory exists.

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

func ReturnErrorFromPanic(ep *error, errorHandlerFunc func(err error))

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.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL