-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.go
executable file
·75 lines (64 loc) · 1.28 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package fdfs_client
import (
"errors"
"fmt"
"io"
"os"
"strings"
config "github.com/keonjeo/goconfig"
//"github.com/hxllyl/goconfig"
)
type Errno struct {
status int
}
func (e Errno) Error() string {
errmsg := fmt.Sprintf("errno [%d] ", e.status)
switch e.status {
case 17:
errmsg += "File Exist"
case 22:
errmsg += "Argument Invlid"
}
return errmsg
}
type FdfsConfigParser struct{}
var (
ConfigFile *config.Config
)
func (this *FdfsConfigParser) Read(filename string) (*config.Config, error) {
return config.ReadDefault(filename)
}
func fdfsCheckFile(filename string) error {
if _, err := os.Stat(filename); err != nil {
return err
}
return nil
}
func readCstr(buff io.Reader, length int) (string, error) {
str := make([]byte, length)
n, err := buff.Read(str)
if err != nil || n != len(str) {
return "", Errno{255}
}
for i, v := range str {
if v == 0 {
str = str[0:i]
break
}
}
return string(str), nil
}
func getFileExt(filename string) string {
parts := strings.Split(filename, ".")
if len(parts) >= 2 {
return parts[len(parts)-1]
}
return ""
}
func splitRemoteFileId(remoteFileId string) ([]string, error) {
parts := strings.SplitN(remoteFileId, "/", 2)
if len(parts) < 2 {
return nil, errors.New("error remoteFileId")
}
return parts, nil
}