MCPcopy
hub / github.com/eddycjy/go-gin-example / MustOpen

Function MustOpen

pkg/file/file.go:69–92  ·  view source on GitHub ↗

MustOpen maximize trying to open the file

(fileName, filePath string)

Source from the content-addressed store, hash-verified

67
68// MustOpen maximize trying to open the file
69func MustOpen(fileName, filePath string) (*os.File, error) {
70 dir, err := os.Getwd()
71 if err != nil {
72 return nil, fmt.Errorf("os.Getwd err: %v", err)
73 }
74
75 src := dir + "/" + filePath
76 perm := CheckPermission(src)
77 if perm == true {
78 return nil, fmt.Errorf("file.CheckPermission Permission denied src: %s", src)
79 }
80
81 err = IsNotExistMkDir(src)
82 if err != nil {
83 return nil, fmt.Errorf("file.IsNotExistMkDir src: %s, err: %v", src, err)
84 }
85
86 f, err := Open(src+fileName, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
87 if err != nil {
88 return nil, fmt.Errorf("Fail to OpenFile :%v", err)
89 }
90
91 return f, nil
92}

Callers 4

OpenMergedImageMethod · 0.92
GenerateMethod · 0.92
SetupFunction · 0.92
EncodeMethod · 0.92

Calls 3

CheckPermissionFunction · 0.85
IsNotExistMkDirFunction · 0.85
OpenFunction · 0.85

Tested by

no test coverage detected