-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathio.go
More file actions
28 lines (26 loc) · 761 Bytes
/
io.go
File metadata and controls
28 lines (26 loc) · 761 Bytes
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
package devstatscode
import (
"io/ioutil"
"strings"
)
// ReadFile tries to read any filename, but have a fallback
// it attempts to replace current project name with shared: /proj/ -> /shared/
// This is to allow reading files that can be shared between projects
func ReadFile(ctx *Ctx, path string) ([]byte, error) {
data, err := ioutil.ReadFile(path)
if err == nil || ctx.Project == "" {
if ctx.Debug > 0 {
Printf("lib.ReadFile('%s'): ok\n", path)
}
return data, err
}
path = strings.Replace(path, "/"+ctx.Project+"/", "/shared/", -1)
data, err = ioutil.ReadFile(path)
if err == nil && ctx.Debug > 0 {
Printf("lib.ReadFile('%s'): ok", path)
}
if err != nil {
Printf("lib.ReadFile('%s'): error: %+v", path, err)
}
return data, err
}