1 Star 0 Fork 0

CNCF/devstatscode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
io.go 761 Bytes
一键复制 编辑 原始数据 按行查看 历史
Łukasz Gryglicki 提交于 2023-05-24 13:30 +08:00 . More debug info when configured
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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cncf/devstatscode.git
git@gitee.com:cncf/devstatscode.git
cncf
devstatscode
devstatscode
master

搜索帮助