• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang com.IsDir函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/Unknwon/com.IsDir函数的典型用法代码示例。如果您正苦于以下问题:Golang IsDir函数的具体用法?Golang IsDir怎么用?Golang IsDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了IsDir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: New

// New builder with option
func New(opt *BuildOption) *Builder {
	if !com.IsDir(opt.SrcDir) {
		return &Builder{Error: ErrSrcDirMissing}
	}
	if !com.IsDir(opt.TplDir) {
		return &Builder{Error: ErrTplDirMissing}
	}
	builder := &Builder{
		parsers: []parser.Parser{
			parser.NewCommonParser(),
			parser.NewMdParser(),
		},
		Version: builderVersion{
			Num:  opt.Version,
			Date: opt.VerDate,
		},
		opt: opt,
	}
	builder.render = render.New(builder.opt.TplDir)
	builder.tasks = []*BuildTask{
		{"Data", builder.ReadData, nil},
		{"Compile", builder.Compile, nil},
		{"Feed", builder.WriteFeed, nil},
		{"Copy", builder.CopyAssets, nil},
	}
	log15.Debug("Build.Source." + opt.SrcDir)
	log15.Debug("Build.Template." + opt.TplDir)
	log15.Debug("Build.Theme." + opt.Theme)
	return builder
}
开发者ID:cnhans,项目名称:pugo-static,代码行数:31,代码来源:builder.go


示例2: TestGetAndRun

func TestGetAndRun(t *testing.T) {
	os.Chdir("testproject")
	defer func() {
		os.RemoveAll("src/github.com")
		os.Remove("bin")
		os.Remove("pkg")
		os.Remove(".gopmfile")
		os.Chdir("..")
	}()
	_, err := exec.Command("gopm", "gen", "-l").Output()
	if err != nil {
		t.Log(err)
	}
	if !com.IsDir("bin") || !com.IsDir("pkg") {
		t.Fatal("Gen bin and pkg directories failed.")
	}
	_, err = exec.Command("gopm", "get", "-l").Output()
	if !com.IsDir("src/github.com") {
		t.Fatal("Get packages failed")
	}
	out, err := exec.Command("gopm", "run", "-l").Output()
	if err != nil || string(out) != "TEST\n" {
		t.Fatal("Run failed \t", err.Error())
	}
}
开发者ID:kulasama,项目名称:gopm,代码行数:25,代码来源:get_test.go


示例3: ReadTheme

// ReadTheme read *Theme to *Context
func ReadTheme(ctx *Context) {
	if ctx.Source == nil {
		ctx.Err = fmt.Errorf("theme depends on loaded source data")
		return
	}
	dir, _ := toDir(ctx.ThemeName)
	if !com.IsDir(dir) {
		ctx.Err = fmt.Errorf("theme directory '%s' is missing", dir)
		return
	}
	log15.Info("Theme|%s", dir)
	ctx.Theme = theme.New(dir)
	ctx.Theme.Func("url", func(str ...string) string {
		if len(str) > 0 {
			if ur, _ := url.Parse(str[0]); ur != nil {
				if ur.Host != "" {
					return str[0]
				}
			}
		}
		return path.Join(append([]string{ctx.Source.Meta.Path}, str...)...)
	})
	ctx.Theme.Func("fullUrl", func(str ...string) string {
		return ctx.Source.Meta.Root + path.Join(str...)
	})
	if err := ctx.Theme.Validate(); err != nil {
		log15.Warn("Theme|%s|%s", dir, err.Error())
	}
}
开发者ID:go-xiaohei,项目名称:pugo,代码行数:30,代码来源:theme.go


示例4: buildSite

// build site function
func buildSite(opt *builder.BuildOption) func(ctx *cli.Context) {
	return func(ctx *cli.Context) {
		// ctrl+C capture
		signalChan := make(chan os.Signal)
		signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

		opt.Theme = ctx.String("theme")

		b := builder.New(opt)
		if b.Error != nil {
			log15.Crit("Builder.Fail", "error", b.Error.Error())
		}

		targetDir := ctx.String("dest")
		log15.Info("Dest." + targetDir)
		if com.IsDir(targetDir) {
			log15.Warn("Dest." + targetDir + ".Existed")
		}

		// auto watching
		b.Build(targetDir)
		if err := b.Context().Error; err != nil {
			log15.Crit("Build.Fail", "error", err.Error())
		}

		if !ctx.Bool("nowatch") {
			b.Watch(targetDir)
			<-signalChan
		}
		log15.Info("Build.Close")
	}
}
开发者ID:jazzsun,项目名称:pugo-static,代码行数:33,代码来源:build.go


示例5: runRun

func runRun(ctx *cli.Context) {
	setup(ctx)

	// Get GOPATH.
	installGopath = com.GetGOPATHs()[0]
	if com.IsDir(installGopath) {
		isHasGopath = true
		log.Log("Indicated GOPATH: %s", installGopath)
		installGopath += "/src"
	}

	genNewGoPath(ctx, false)

	log.Trace("Running...")

	cmdArgs := []string{"go", "run"}
	cmdArgs = append(cmdArgs, ctx.Args()...)
	err := execCmd(newGoPath, newCurPath, cmdArgs...)
	if err != nil {
		log.Error("run", "Fail to run program:")
		log.Fatal("", "\t"+err.Error())
	}

	log.Success("SUCC", "run", "Command executed successfully!")
}
开发者ID:nashtsai,项目名称:gopm,代码行数:25,代码来源:run.go


示例6: 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


示例7: NewTheme

// new theme manager
func NewTheme(dir, name string) *Theme {
	// try to create dir
	if !com.IsDir(dir) {
		os.MkdirAll(dir, os.ModePerm)
	}
	return &Theme{dir, name}
}
开发者ID:Ganben,项目名称:blog,代码行数:8,代码来源:theme.go


示例8: ZipDownload

func ZipDownload(ctx *middleware.Context, params martini.Params) {
	commitId := ctx.Repo.CommitId
	archivesPath := filepath.Join(ctx.Repo.GitRepo.Path, "archives")
	if !com.IsDir(archivesPath) {
		if err := os.Mkdir(archivesPath, 0755); err != nil {
			ctx.Handle(404, "ZipDownload -> os.Mkdir(archivesPath)", err)
			return
		}
	}

	zipPath := filepath.Join(archivesPath, commitId+".zip")

	if com.IsFile(zipPath) {
		ctx.ServeFile(zipPath, ctx.Repo.Repository.Name+".zip")
		return
	}

	err := ctx.Repo.Commit.CreateArchive(zipPath)
	if err != nil {
		ctx.Handle(404, "ZipDownload -> CreateArchive "+zipPath, err)
		return
	}

	ctx.ServeFile(zipPath, ctx.Repo.Repository.Name+".zip")
}
开发者ID:Julianzz,项目名称:gogs,代码行数:25,代码来源:download.go


示例9: 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


示例10: ReadLang

// ReadLang read languages in srcDir
func ReadLang(srcDir string) map[string]*helper.I18n {
	if !com.IsDir(srcDir) {
		return nil
	}
	langs := make(map[string]*helper.I18n)
	filepath.Walk(srcDir, func(p string, fi os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if fi.IsDir() {
			return nil
		}
		p = filepath.ToSlash(p)
		ext := filepath.Ext(p)
		if ext == ".toml" || ext == ".ini" {
			log15.Debug("Read|%s", p)
			b, err := ioutil.ReadFile(p)
			if err != nil {
				log15.Warn("Read|Lang|%s|%v", p, err)
				return nil
			}
			lang := strings.TrimSuffix(filepath.Base(p), ext)
			i18n, err := helper.NewI18n(lang, b, ext)
			if err != nil {
				log15.Warn("Read|Lang|%s|%v", p, err)
				return nil
			}
			langs[lang] = i18n
		}
		return nil
	})
	return langs
}
开发者ID:go-xiaohei,项目名称:pugo,代码行数:34,代码来源:source.go


示例11: LoadRepoConfig

func LoadRepoConfig() {
	// Load .gitignore and license files.
	types := []string{"gitignore", "license"}
	typeFiles := make([][]string, 2)
	for i, t := range types {
		files := getAssetList(path.Join("conf", t))
		customPath := path.Join(setting.CustomPath, "conf", t)
		if com.IsDir(customPath) {
			customFiles, err := com.StatDir(customPath)
			if err != nil {
				log.Fatal("Fail to get custom %s files: %v", t, err)
			}

			for _, f := range customFiles {
				if !com.IsSliceContainsStr(files, f) {
					files = append(files, f)
				}
			}
		}
		typeFiles[i] = files
	}

	LanguageIgns = typeFiles[0]
	Licenses = typeFiles[1]
	sort.Strings(LanguageIgns)
	sort.Strings(Licenses)
}
开发者ID:jcfrank,项目名称:gogs,代码行数:27,代码来源:repo.go


示例12: LoadRepoConfig

func LoadRepoConfig() {
	workDir, err := base.ExecDir()
	if err != nil {
		qlog.Fatalf("Fail to get work directory: %s\n", err)
	}

	// Load .gitignore and license files.
	types := []string{"gitignore", "license"}
	typeFiles := make([][]string, 2)
	for i, t := range types {
		cfgPath := filepath.Join(workDir, "conf", t)
		files, err := com.StatDir(cfgPath)
		if err != nil {
			qlog.Fatalf("Fail to get default %s files: %v\n", t, err)
		}
		cfgPath = filepath.Join(workDir, "custom/conf/gitignore")
		if com.IsDir(cfgPath) {
			customFiles, err := com.StatDir(cfgPath)
			if err != nil {
				qlog.Fatalf("Fail to get custom %s files: %v\n", t, err)
			}

			for _, f := range customFiles {
				if !com.IsSliceContainsStr(files, f) {
					files = append(files, f)
				}
			}
		}
		typeFiles[i] = files
	}

	LanguageIgns = typeFiles[0]
	Licenses = typeFiles[1]
}
开发者ID:j20,项目名称:gogs,代码行数:34,代码来源:repo.go


示例13: MigratePost

func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
	ctx.Data["Title"] = ctx.Tr("new_migrate")

	ctxUser := checkContextUser(ctx, form.Uid)
	if ctx.Written() {
		return
	}
	ctx.Data["ContextUser"] = ctxUser

	if ctx.HasError() {
		ctx.HTML(200, MIGRATE)
		return
	}

	// Remote address can be HTTP/HTTPS/Git URL or local path.
	// Note: remember to change api/v1/repo.go: MigrateRepo
	// FIXME: merge these two functions with better error handling
	remoteAddr := form.CloneAddr
	if strings.HasPrefix(form.CloneAddr, "http://") ||
		strings.HasPrefix(form.CloneAddr, "https://") ||
		strings.HasPrefix(form.CloneAddr, "git://") {
		u, err := url.Parse(form.CloneAddr)
		if err != nil {
			ctx.Data["Err_CloneAddr"] = true
			ctx.RenderWithErr(ctx.Tr("form.url_error"), MIGRATE, &form)
			return
		}
		if len(form.AuthUsername) > 0 || len(form.AuthPassword) > 0 {
			u.User = url.UserPassword(form.AuthUsername, form.AuthPassword)
		}
		remoteAddr = u.String()
	} else if !com.IsDir(remoteAddr) {
		ctx.Data["Err_CloneAddr"] = true
		ctx.RenderWithErr(ctx.Tr("repo.migrate.invalid_local_path"), MIGRATE, &form)
		return
	}

	repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr)
	if err == nil {
		log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
		ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName)
		return
	}

	if repo != nil {
		if errDelete := models.DeleteRepository(ctxUser.Id, repo.ID); errDelete != nil {
			log.Error(4, "DeleteRepository: %v", errDelete)
		}
	}

	if strings.Contains(err.Error(), "Authentication failed") ||
		strings.Contains(err.Error(), " not found") ||
		strings.Contains(err.Error(), "could not read Username") {
		ctx.Data["Err_Auth"] = true
		ctx.RenderWithErr(ctx.Tr("form.auth_failed", strings.Replace(err.Error(), ":"+form.AuthPassword+"@", ":<password>@", 1)), MIGRATE, &form)
		return
	}

	handleCreateError(ctx, err, "MigratePost", MIGRATE, &form)
}
开发者ID:smallnewer,项目名称:gogs,代码行数:60,代码来源:repo.go


示例14: LoadRepoConfig

func LoadRepoConfig() {
	// Load .gitignore and license files and readme templates.
	types := []string{"gitignore", "license", "readme"}
	typeFiles := make([][]string, 3)
	for i, t := range types {
		files, err := bindata.AssetDir("conf/" + t)
		if err != nil {
			log.Fatal(4, "Fail to get %s files: %v", t, err)
		}
		customPath := path.Join(setting.CustomPath, "conf", t)
		if com.IsDir(customPath) {
			customFiles, err := com.StatDir(customPath)
			if err != nil {
				log.Fatal(4, "Fail to get custom %s files: %v", t, err)
			}

			for _, f := range customFiles {
				if !com.IsSliceContainsStr(files, f) {
					files = append(files, f)
				}
			}
		}
		typeFiles[i] = files
	}

	Gitignores = typeFiles[0]
	Licenses = typeFiles[1]
	Readmes = typeFiles[2]
	sort.Strings(Gitignores)
	sort.Strings(Licenses)
	sort.Strings(Readmes)
}
开发者ID:frankkorrell,项目名称:gogs,代码行数:32,代码来源:repo.go


示例15: isRepositoryExist

func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
	has, err := e.Get(&Repository{
		OwnerID:   u.Id,
		LowerName: strings.ToLower(repoName),
	})
	return has && com.IsDir(RepoPath(u.Name, repoName)), err
}
开发者ID:frankkorrell,项目名称:gogs,代码行数:7,代码来源:repo.go


示例16: NewTable

// create or read table in directory with schema.
func NewTable(name string, directory string, sc *Schema, s Mapper) (t *Table, e error) {
	if !com.IsDir(directory) {
		if e = os.MkdirAll(directory, os.ModePerm); e != nil {
			return
		}
	}
	t = new(Table)
	t.name = name
	t.directory = directory
	t.s = s
	t.sc = sc

	// add or read pk index
	t.pkIndex, e = NewPkIndex(path.Join(directory, strings.ToLower(sc.PK+".pk")), s)
	if e != nil {
		return
	}

	// add or read value index
	t.valueIndex = make(map[string]*Index)
	for _, v := range sc.Index {
		t.valueIndex[v], e = NewIndex(strings.ToLower(name+"_"+v), path.Join(directory, strings.ToLower(v+".idx")), s)
		if e != nil {
			return
		}
	}

	// add or read chunk
	t.chunk, e = NewChunk(directory, s, sc.ChunkSize)
	return
}
开发者ID:rejoicelee,项目名称:gojx,代码行数:32,代码来源:table.go


示例17: init

// init pk.
// create files in first init.
// read files after first init.
func (p *PK) init() (e error) {
	if !com.IsDir(p.directory) {
		return p.firstInit()
	}

	// try to use optimized files
	if e = p.tryOptimized(); e != nil {
		return
	}

	// read auto increment
	if p.auto {
		p.autoFile = path.Join(p.directory, "auto.pk")
		e = p.ReadIncrement()
		if e != nil {
			return
		}
	}

	// read file in
	p.file, e = os.OpenFile(path.Join(p.directory, "pk.pk"), os.O_APPEND|os.O_RDWR, os.ModePerm)
	if e != nil {
		return
	}
	e = p.Read()
	//println("read pk items :", len(p.data))
	if e != nil && e != io.EOF {
		return
	}
	e = nil

	return
}
开发者ID:Comdex,项目名称:jx,代码行数:36,代码来源:pk.go


示例18: Upload

func (ms *MediaService) Upload(v interface{}) (*Result, error) {
	opt, ok := v.(MediaUploadOption)
	if !ok {
		return nil, ErrServiceFuncNeedType(ms.Upload, opt)
	}

	f, h, err := opt.Ctx.Req().FormFile(opt.FormName)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	// check file size
	size, err := getUploadFileSize(f)
	if err != nil {
		return nil, err
	}
	if (size / 1024) > Setting.Media.MaxFileSize {
		return nil, ErrMediaTooLarge
	}

	// check file type
	ext := path.Ext(h.Filename)
	fileType := Setting.Media.GetType(ext)
	if fileType == 0 {
		return nil, ErrMediaDisAllowType
	}

	// hash file name, make dir
	now := time.Now()
	hashName := utils.Md5String(fmt.Sprintf("%d%s%d", opt.User, h.Filename, now.UnixNano())) + ext
	fileName := path.Join("static/upload", hashName)
	fileDir := path.Dir(fileName)

	if !com.IsDir(fileDir) {
		if err = os.MkdirAll(fileDir, os.ModePerm); err != nil {
			return nil, err
		}
	}
	if err = opt.Ctx.SaveToFile(opt.FormName, fileName); err != nil {
		return nil, err
	}

	// save media data
	media := &model.Media{
		UserId:   opt.User,
		Name:     h.Filename,
		FileName: hashName,
		FilePath: fileName,
		FileSize: size,
		FileType: fileType,
	}
	if _, err := core.Db.Insert(media); err != nil {
		return nil, err
	}

	defer ms.msgUpload(media)

	return newResult(ms.Upload, media), nil
}
开发者ID:hxdyxd,项目名称:pugo,代码行数:60,代码来源:media.go


示例19: 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


示例20: IsRepositoryExist

// IsRepositoryExist returns true if the repository with given name under user has already existed.
func IsRepositoryExist(u *User, repoName string) bool {
	has, _ := x.Get(&Repository{
		OwnerId:   u.Id,
		LowerName: strings.ToLower(repoName),
	})
	return has && com.IsDir(RepoPath(u.Name, repoName))
}
开发者ID:wxiangbo,项目名称:gogs,代码行数:8,代码来源:repo.go



注:本文中的github.com/Unknwon/com.IsDir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang com.IsExist函数代码示例发布时间:2022-05-28
下一篇:
Golang com.HttpGetJSON函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap