mirror of
https://github.com/axllent/mailpit.git
synced 2026-06-27 22:46:09 +00:00
- Updated error handling to use the error return value for resource closures in tests and functions, ensuring proper error reporting. - Replaced direct calls to `Close()` with deferred functions that handle errors gracefully. - Improved readability by using `strings.ReplaceAll` instead of `strings.Replace` for string manipulation. - Enhanced network connection handling by adding default cases for unsupported network types. - Updated HTTP response handling to use the appropriate status codes and error messages. - Removed unused variables and commented-out code to clean up the codebase.
24 lines
431 B
Go
24 lines
431 B
Go
package tools
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// IsFile returns whether a file exists and is readable
|
|
func IsFile(path string) bool {
|
|
f, err := os.Open(filepath.Clean(path))
|
|
defer func() { _ = f.Close() }()
|
|
return err == nil
|
|
}
|
|
|
|
// IsDir returns whether a path is a directory
|
|
func IsDir(path string) bool {
|
|
info, err := os.Stat(path)
|
|
if err != nil || os.IsNotExist(err) || !info.IsDir() {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|