本文整理汇总了Golang中github.com/Unknwon/com.IsFile函数的典型用法代码示例。如果您正苦于以下问题:Golang IsFile函数的具体用法?Golang IsFile怎么用?Golang IsFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: needCheckUpdate
func needCheckUpdate() bool {
// Does not have record for check update.
stamp, err := Cfg.Int64("app", "update_check_time")
if err != nil {
return true
}
if !com.IsFile("conf/docTree.json") || !com.IsFile("conf/blogTree.json") {
return true
}
return time.Unix(stamp, 0).Add(5 * time.Minute).Before(time.Now())
}
开发者ID:rails0330,项目名称:beeweb,代码行数:13,代码来源:models.go
示例2: copyAssets
// copy static assets
func (b *Builder) copyAssets(ctx *Context, srcDir string, dstDir string) error {
return filepath.Walk(srcDir, func(p string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
if fi.IsDir() {
return nil
}
// if file exist, check mod time
rel, _ := filepath.Rel(srcDir, p)
toFile := filepath.Join(dstDir, rel)
if com.IsFile(toFile) {
if fi2, _ := os.Stat(toFile); fi2 != nil {
if fi2.ModTime().Sub(fi.ModTime()).Seconds() > 0 {
ctx.Diff.Add(toFile, DIFF_KEEP, fi2.ModTime())
return nil
}
if err := helper.CopyFile(p, toFile); err != nil {
return err
}
ctx.Diff.Add(toFile, DIFF_UPDATE, time.Now())
return nil
}
}
// not exist, just copy
if err := helper.CopyFile(p, toFile); err != nil {
return err
}
ctx.Diff.Add(toFile, DIFF_ADD, time.Now())
return nil
})
}
开发者ID:cnhans,项目名称:pugo-static,代码行数:35,代码来源:build_copy.go
示例3: LoadPkgNameList
func LoadPkgNameList(filePath string) {
PackageNameList = make(map[string]string)
// If file does not exist, simply ignore.
if !com.IsFile(filePath) {
return
}
data, err := ioutil.ReadFile(filePath)
if err != nil {
log.Error("Package name list", "Fail to read file")
log.Fatal("", err.Error())
}
pkgs := strings.Split(string(data), "\n")
for i, line := range pkgs {
infos := strings.Split(line, "=")
if len(infos) != 2 {
// Last item might be empty line.
if i == len(pkgs)-1 {
continue
}
log.Error("", "Fail to parse package name: "+line)
log.Fatal("", "Invalid package name information")
}
PackageNameList[strings.TrimSpace(infos[0])] =
strings.TrimSpace(infos[1])
}
}
开发者ID:kulasama,项目名称:gopm,代码行数:29,代码来源:conf.go
示例4: TarGzDownload
func TarGzDownload(ctx *middleware.Context, params martini.Params) {
commitId := ctx.Repo.CommitId
archivesPath := filepath.Join(ctx.Repo.GitRepo.Path, "archives/targz")
if !com.IsDir(archivesPath) {
if err := os.MkdirAll(archivesPath, 0755); err != nil {
ctx.Handle(404, "TarGzDownload -> os.Mkdir(archivesPath)", err)
return
}
}
archivePath := filepath.Join(archivesPath, commitId+".tar.gz")
if com.IsFile(archivePath) {
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+".tar.gz")
return
}
err := ctx.Repo.Commit.CreateArchive(archivePath, git.AT_TARGZ)
if err != nil {
ctx.Handle(404, "TarGzDownload -> CreateArchive "+archivePath, err)
return
}
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+".tar.gz")
}
开发者ID:j20,项目名称:gogs,代码行数:25,代码来源:download.go
示例5: Pages
func Pages(ctx *middleware.Context) {
toc := models.Tocs[ctx.Locale.Language()]
if toc == nil {
toc = models.Tocs[setting.Docs.Langs[0]]
}
pageName := strings.ToLower(strings.TrimSuffix(ctx.Req.URL.Path[1:], ".html"))
for i := range toc.Pages {
if toc.Pages[i].Name == pageName {
page := toc.Pages[i]
if !com.IsFile(page.FileName) {
ctx.Data["IsShowingDefault"] = true
page = models.Tocs[setting.Docs.Langs[0]].Pages[i]
}
if !setting.ProdMode {
page.ReloadContent()
}
ctx.Data["Title"] = page.Title
ctx.Data["Content"] = fmt.Sprintf(`<script type="text/javascript" src="/%s/%s?=%d"></script>`, toc.Lang, page.DocumentPath+".js", page.LastBuildTime)
ctx.Data["Pages"] = toc.Pages
renderEditPage(ctx, page.DocumentPath)
ctx.HTML(200, "docs")
return
}
}
NotFound(ctx)
}
开发者ID:TDose,项目名称:peach,代码行数:30,代码来源:home.go
示例6: regenerate
func (p *FileProvider) regenerate(oldsid, sid string) (err error) {
p.lock.Lock()
defer p.lock.Unlock()
filename := p.filepath(sid)
if com.IsExist(filename) {
return fmt.Errorf("new sid '%s' already exists", sid)
}
oldname := p.filepath(oldsid)
if !com.IsFile(oldname) {
data, err := EncodeGob(make(map[interface{}]interface{}))
if err != nil {
return err
}
if err = os.MkdirAll(path.Dir(oldname), os.ModePerm); err != nil {
return err
}
if err = ioutil.WriteFile(oldname, data, os.ModePerm); err != nil {
return err
}
}
if err = os.MkdirAll(path.Dir(filename), os.ModePerm); err != nil {
return err
}
if err = os.Rename(oldname, filename); err != nil {
return err
}
return nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:31,代码来源:file.go
示例7: InitSetting
func InitSetting() {
var err error
WorkDir, err = os.Getwd()
if err != nil {
log.Fatal("Fail to get work directory: %v", err)
}
confPath := path.Join(WorkDir, ".bra.toml")
if !com.IsFile(confPath) {
log.Fatal(".bra.toml not found in work directory")
} else if _, err = toml.DecodeFile(confPath, &Cfg); err != nil {
log.Fatal("Fail to decode .bra.toml: %v", err)
}
if Cfg.Run.InterruptTimeout == 0 {
Cfg.Run.InterruptTimeout = 15
}
// Init default ignore lists.
Cfg.Run.IgnoreDirs = com.AppendStr(Cfg.Run.IgnoreDirs, ".git")
Cfg.Run.IgnoreRegexps = make([]*regexp.Regexp, len(Cfg.Run.IgnoreFiles))
for i, regStr := range Cfg.Run.IgnoreFiles {
Cfg.Run.IgnoreRegexps[i], err = regexp.Compile(regStr)
if err != nil {
log.Fatal("Invalid regexp[%s]: %v", regStr, err)
}
}
}
开发者ID:replay,项目名称:bra,代码行数:28,代码来源:setting.go
示例8: ExampleIsFile
func ExampleIsFile() {
if com.IsFile("file.go") {
fmt.Println("file.go exists")
return
}
fmt.Println("file.go is not a file or does not exist")
}
开发者ID:matm,项目名称:gobuild,代码行数:7,代码来源:example_test.go
示例9: TestRegister
func TestRegister(t *testing.T) {
e := s.Register(new(School), 55)
if e != nil {
t.Error(e)
return
}
name := strings.ToLower(fmt.Sprint(reflect.TypeOf(new(School)).Elem()))
sc := s.schema[name]
if sc == nil {
printError(t, "RegisterNoSchema", name, nil)
return
}
if sc.PK != "Id" {
printError(t, "RegisterPk", "Id", sc.PK)
return
}
if sc.Index[0] != "Rank" {
printError(t, "RegisterIndexHas", "Rank", sc.Index[1])
return
}
file := path.Join(directory, name, "rank.idx")
if !com.IsFile(file) {
printError(t, "RegisterHasFile:"+file, true, false)
return
}
if sc.ChunkSize != 55 {
printError(t, "RegisterChunkSize", 55, sc.ChunkSize)
}
}
开发者ID:rejoicelee,项目名称:gojx,代码行数:33,代码来源:gojx_test.go
示例10: DeleteUploads
func DeleteUploads(uploads ...*Upload) (err error) {
if len(uploads) == 0 {
return nil
}
sess := x.NewSession()
defer sessionRelease(sess)
if err = sess.Begin(); err != nil {
return err
}
ids := make([]int64, len(uploads))
for i := 0; i < len(uploads); i++ {
ids[i] = uploads[i].ID
}
if _, err = sess.In("id", ids).Delete(new(Upload)); err != nil {
return fmt.Errorf("delete uploads: %v", err)
}
for _, upload := range uploads {
localPath := upload.LocalPath()
if !com.IsFile(localPath) {
continue
}
if err := os.Remove(localPath); err != nil {
return fmt.Errorf("remove upload: %v", err)
}
}
return sess.Commit()
}
开发者ID:andreynering,项目名称:gogs,代码行数:32,代码来源:repo_editor.go
示例11: init
func init() {
var err error
Cfg, err = ini.Load(CFG_PATH)
if err != nil {
panic(fmt.Errorf("fail to load config file '%s': %v", CFG_PATH, err))
}
if com.IsFile(CFG_CUSTOM_PATH) {
if err = Cfg.Append(CFG_CUSTOM_PATH); err != nil {
panic(fmt.Errorf("fail to load config file '%s': %v", CFG_CUSTOM_PATH, err))
}
}
appNames := Cfg.Section("").Key("apps").Strings(",")
Apps = make([]App, len(appNames))
for i, name := range appNames {
Apps[i] = App{name, Cfg.Section(name).Key("repo_name").String()}
}
sec := Cfg.Section("app")
if sec.Key("run_mode").MustString("dev") == "prod" {
macaron.Env = macaron.PROD
}
HttpPort = sec.Key("http_port").MustInt(8091)
Https = sec.Key("https").MustBool()
HttpsCert = sec.Key("https_cert").String()
HttpsKey = sec.Key("https_key").String()
Langs = Cfg.Section("i18n").Key("langs").Strings(",")
Names = Cfg.Section("i18n").Key("names").Strings(",")
setGithubCredentials(Cfg.Section("github").Key("client_id").String(), Cfg.Section("github").Key("client_secret").String())
}
开发者ID:nauticaustin,项目名称:gogsweb,代码行数:32,代码来源:setting.go
示例12: GetCurrentTheme
// get current theme
func GetCurrentTheme() (*Theme, error) {
themeSetting, err := GetSettings("theme")
if err != nil {
return nil, err
}
t := new(Theme)
t.Directory = themeSetting["theme"]
t.IsCurrent = true
tomlFile := path.Join("static", t.Directory, "theme.toml")
if com.IsFile(tomlFile) {
if _, err := toml.DecodeFile(tomlFile, t); err != nil {
log.Error("Db|GetCurrentTheme|%s|%s", tomlFile, err.Error())
return nil, err
}
}
// fill data
if t.Name == "" {
t.Name = t.Directory
}
if t.Version == "" {
t.Version = "0.0"
}
return t, nil
}
开发者ID:insionng,项目名称:purine,代码行数:27,代码来源:setting.go
示例13: Download
func Download(ctx *middleware.Context) {
ext := "." + ctx.Params(":ext")
var archivePath string
switch ext {
case ".zip":
archivePath = path.Join(ctx.Repo.GitRepo.Path, "archives/zip")
case ".tar.gz":
archivePath = path.Join(ctx.Repo.GitRepo.Path, "archives/targz")
default:
ctx.Error(404)
return
}
if !com.IsDir(archivePath) {
if err := os.MkdirAll(archivePath, os.ModePerm); err != nil {
ctx.Handle(500, "Download -> os.MkdirAll(archivePath)", err)
return
}
}
archivePath = path.Join(archivePath, ctx.Repo.CommitId+ext)
if !com.IsFile(archivePath) {
if err := ctx.Repo.Commit.CreateArchive(archivePath, git.ZIP); err != nil {
ctx.Handle(500, "Download -> CreateArchive "+archivePath, err)
return
}
}
ctx.ServeFile(archivePath, ctx.Repo.Repository.Name+"-"+base.ShortSha(ctx.Repo.CommitId)+ext)
}
开发者ID:felipelovato,项目名称:gogs,代码行数:31,代码来源:repo.go
示例14: makeLink
func makeLink(srcPath, destPath string) error {
// Check if Windows version is XP.
if getWindowsVersion() >= 6 {
cmd := exec.Command("cmd", "/c", "mklink", "/j", destPath, srcPath)
return cmd.Run()
}
// XP.
isWindowsXP = true
// if both are ntfs file system
if volumnType(srcPath) == "NTFS" && volumnType(destPath) == "NTFS" {
// if has junction command installed
file, err := exec.LookPath("junction")
if err == nil {
path, _ := filepath.Abs(file)
if com.IsFile(path) {
cmd := exec.Command("cmd", "/c", "junction", destPath, srcPath)
return cmd.Run()
}
}
}
os.RemoveAll(destPath)
return com.CopyDir(srcPath, destPath, func(filePath string) bool {
return strings.Contains(filePath, doc.VENDOR)
})
}
开发者ID:kulasama,项目名称:gopm,代码行数:27,代码来源:helper_windows.go
示例15: validPath
// validPath checks if the information of the package is valid.
func validPath(info string) (string, string) {
infos := strings.Split(info, ":")
l := len(infos)
switch {
case l == 1:
// for local imports
if com.IsFile(infos[0]) {
return doc.LOCAL, infos[0]
}
return doc.BRANCH, ""
case l == 2:
switch infos[1] {
case doc.TRUNK, doc.MASTER, doc.DEFAULT:
infos[1] = ""
}
return infos[0], infos[1]
default:
log.Error("", "Cannot parse dependency version:")
log.Error("", "\t"+info)
log.Help("Try 'gopm help get' to get more information")
return "", ""
}
}
开发者ID:nashtsai,项目名称:gopm,代码行数:26,代码来源:cmd.go
示例16: InitModels
func InitModels() {
if !com.IsFile(_CFG_PATH) {
os.Create(_CFG_PATH)
}
var err error
Cfg, err = goconfig.LoadConfigFile(_CFG_PATH)
if err == nil {
beego.Info("Initialize app.ini")
}
setGithubCredentials(Cfg.MustValue("github", "client_id"),
Cfg.MustValue("github", "client_secret"))
docLock = new(sync.RWMutex)
blogLock = new(sync.RWMutex)
initMaps()
// Start check ticker.
checkTicker = time.NewTicker(5 * time.Minute)
go checkTickerTimer(checkTicker.C)
// ATTENTION: you'd better comment following code when developing.
if needCheckUpdate() {
checkFileUpdates()
Cfg.SetValue("app", "update_check_time", strconv.Itoa(int(time.Now().Unix())))
goconfig.SaveConfigFile(Cfg, _CFG_PATH)
}
}
开发者ID:rails0330,项目名称:beeweb,代码行数:31,代码来源:models.go
示例17: NewConfigContext
func NewConfigContext() {
workDir, err := ExecDir()
if err != nil {
qlog.Fatalf("Fail to get work directory: %s\n", err)
}
cfgPath := filepath.Join(workDir, "conf/app.ini")
Cfg, err = goconfig.LoadConfigFile(cfgPath)
if err != nil {
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
}
Cfg.BlockMode = false
cfgPaths := []string{os.Getenv("GOGS_CONFIG"), filepath.Join(workDir, "custom/conf/app.ini")}
for _, cfgPath := range cfgPaths {
if com.IsFile(cfgPath) {
if err = Cfg.AppendFiles(cfgPath); err != nil {
qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
}
}
}
AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN")
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
DisableRouterLog = Cfg.MustBool("server", "DISABLE_ROUTER_LOG", false)
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
RunUser = Cfg.MustValue("", "RUN_USER")
curUser := os.Getenv("USER")
if len(curUser) == 0 {
curUser = os.Getenv("USERNAME")
}
// Does not check run user when the install lock is off.
if InstallLock && RunUser != curUser {
qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
}
LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME")
CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")
PictureService = Cfg.MustValue("picture", "SERVICE")
DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR", false)
// Determine and create root git reposiroty path.
homeDir, err := com.HomeDir()
if err != nil {
qlog.Fatalf("Fail to get home directory): %v\n", err)
}
RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
}
ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash")
}
开发者ID:CubeLite,项目名称:gogs,代码行数:60,代码来源:conf.go
示例18: reloadProtects
func reloadProtects(localRoot string) error {
Protector.lock.Lock()
defer Protector.lock.Unlock()
protectPath := path.Join(localRoot, "protect.ini")
if !com.IsFile(protectPath) {
return nil
}
Protector.HasProtection = true
cfgs, err := ini.Load(protectPath)
if err != nil {
return fmt.Errorf("Fail to load protect.ini: %v", err)
}
for _, k := range cfgs.Section("user").Keys() {
Protector.Users[k.Name()] = strings.ToLower(k.Value())
}
fmt.Println("\nProtected Resources:")
for _, k := range cfgs.Section("auth").Keys() {
fmt.Println("➜ ", k.Name())
Protector.Resources[k.Name()] = make(map[string]bool)
for _, name := range k.Strings(",") {
fmt.Println(" ✓ ", name)
Protector.Resources[k.Name()][name] = true
}
}
return nil
}
开发者ID:52M,项目名称:peach,代码行数:32,代码来源:protect.go
示例19: LoadConfig
// LoadConfig loads configuration file.
func LoadConfig(cfgPath string) {
if !com.IsExist(cfgPath) {
os.Create(cfgPath)
}
var err error
Cfg, err = goconfig.LoadConfigFile(cfgPath)
if err != nil {
log.Fatalf("Fail to load configuration file: %v", err)
}
if com.IsFile("custom/app.ini") {
if err = Cfg.AppendFiles("custom/app.ini"); err != nil {
log.Fatalf("Fail to load custom configuration file: %v", err)
}
}
DocsJsPath, err = Cfg.GetValue("server", "docs_js_path")
if err != nil {
log.Fatalln("Fail to load configuration file: cannot find key docs_js_path")
}
HvJsPath, err = Cfg.GetValue("server", "hv_js_path")
if err != nil {
log.Fatalln("Fail to load configuration file: cannot find key hv_js_path")
}
}
开发者ID:John-Appleseed,项目名称:gowalker,代码行数:27,代码来源:utils.go
示例20: TestBuilderBuild
func TestBuilderBuild(t *testing.T) {
Convey("Build Process", t, func() {
b.Build(target)
So(b.Error, ShouldBeNil)
So(b.Context(), ShouldNotBeNil)
So(b.Context().Error, ShouldBeNil)
// check dirs and files
Convey("Check Built And Files", func() {
var flag = true
t := path.Join(target, b.Context().Meta.Base)
for _, dir := range shoudlExistDirs {
if flag = flag && com.IsDir(path.Join(t, dir)); !flag {
break
}
}
So(flag, ShouldBeTrue)
for _, f := range shouldExistFiles {
if flag = flag && com.IsFile(path.Join(t, f)); !flag {
break
}
}
So(flag, ShouldBeTrue)
})
})
}
开发者ID:cnhans,项目名称:pugo-static,代码行数:27,代码来源:builder_test.go
注:本文中的github.com/Unknwon/com.IsFile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论