forked from hypersleep/easyssh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
42 lines (37 loc) · 763 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package easyssh
import (
"crypto/sha1"
"fmt"
"io"
"log"
"os"
"strings"
)
// Sha1 is a helper method of sha1 algo.
func Sha1(input string) string {
hash := sha1.New()
hash.Write([]byte(input))
hashed := hash.Sum(nil)
return fmt.Sprintf("%x", hashed)
}
// IsFileExists tests whether specified filepath is exists.
func IsFileExists(filepath string) bool {
_, err := os.Stat(filepath)
if err == nil {
return true
}
return os.IsExist(err)
}
// RemoveTrailingSlash removes trailing slash from a path.
func RemoveTrailingSlash(path string) string {
if len(path) > 1 && strings.HasSuffix(path, "/") {
return path[:len(path)-1]
}
return path
}
func Close(c io.Closer) {
err := c.Close()
if err != nil && err != io.EOF {
log.Println(err)
}
}