本文整理汇总了Golang中github.com/Unknwon/com.IsExist函数的典型用法代码示例。如果您正苦于以下问题:Golang IsExist函数的具体用法?Golang IsExist怎么用?Golang IsExist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IsExist函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RelAvatarLink
func (u *User) RelAvatarLink() string {
defaultImgUrl := "/img/avatar_default.jpg"
if u.Id == -1 {
return defaultImgUrl
}
switch {
case u.UseCustomAvatar:
if !com.IsExist(u.CustomAvatarPath()) {
return defaultImgUrl
}
return "/avatars/" + com.ToStr(u.Id)
case setting.DisableGravatar, setting.OfflineMode:
if !com.IsExist(u.CustomAvatarPath()) {
if err := u.GenerateRandomAvatar(); err != nil {
log.Error(3, "GenerateRandomAvatar: %v", err)
}
}
return "/avatars/" + com.ToStr(u.Id)
case setting.Service.EnableCacheAvatar:
return "/avatar/" + u.Avatar
}
return setting.GravatarSource + u.Avatar
}
开发者ID:GoNuuts,项目名称:gogs,代码行数:25,代码来源:user.go
示例2: runNew
func runNew(ctx *cli.Context) {
target := ctx.String("target")
if com.IsExist(target) && !ctx.Bool("yes") {
fmt.Printf(toYellow("Directory '%s' already exists, do you want to overwrite?[Y/n] "), target)
if !checkYesNo() {
os.Exit(0)
}
}
fmt.Printf("➜ Creating '%s'...\n", target)
os.MkdirAll(target, os.ModePerm)
// Create default files.
dirs := []string{"templates", "public"}
for _, dir := range dirs {
fmt.Printf("➜ Creating '%s'...\n", dir)
os.RemoveAll(filepath.Join(target, dir))
restoreAssets(target, dir)
}
// Create custom templates.
yes := ctx.Bool("yes")
if !yes {
fmt.Printf(toYellow("Do you want to use custom templates?[Y/n] "))
yes = checkYesNo()
}
if yes {
fmt.Println("➜ Creating 'custom/templates'...")
restoreAssets(filepath.Join(target, "custom"), "templates")
// Update configuration to use custom templates.
fmt.Println("➜ Updating custom configuration...")
var cfg *ini.File
var err error
customPath := filepath.Join(target, "custom/app.ini")
if com.IsExist(customPath) {
cfg, err = ini.Load(customPath)
if err != nil {
fmt.Printf(toRed("✗ %v\n"), err)
os.Exit(1)
}
} else {
cfg = ini.Empty()
}
cfg.Section("page").Key("USE_CUSTOM_TPL").SetValue("true")
if err = cfg.SaveTo(customPath); err != nil {
fmt.Printf(toRed("✗ %v\n"), err)
os.Exit(1)
}
}
fmt.Println(toGreen("✓ Done!"))
}
开发者ID:52M,项目名称:peach,代码行数:55,代码来源:init.go
示例3: getVcsName
func getVcsName(dirPath string) string {
switch {
case com.IsExist(path.Join(dirPath, ".git")):
return "git"
case com.IsExist(path.Join(dirPath, ".hg")):
return "hg"
case com.IsExist(path.Join(dirPath, ".svn")):
return "svn"
}
return ""
}
开发者ID:josephyzhou,项目名称:gopm,代码行数:11,代码来源:get.go
示例4: updateWikiPage
// updateWikiPage adds new page to repository wiki.
func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, message string, isNew bool) (err error) {
wikiWorkingPool.CheckIn(com.ToStr(repo.ID))
defer wikiWorkingPool.CheckOut(com.ToStr(repo.ID))
if err = repo.InitWiki(); err != nil {
return fmt.Errorf("InitWiki: %v", err)
}
localPath := repo.LocalWikiPath()
// Discard local commits make sure even to remote when local copy exists.
if com.IsExist(localPath) {
// No need to check if nothing in the repository.
if git.IsBranchExist(localPath, "master") {
if err = git.ResetHEAD(localPath, true, "origin/master"); err != nil {
return fmt.Errorf("Reset: %v", err)
}
}
}
if err = repo.UpdateLocalWiki(); err != nil {
return fmt.Errorf("UpdateLocalWiki: %v", err)
}
title = ToWikiPageName(strings.Replace(title, "/", " ", -1))
filename := path.Join(localPath, title+".md")
// If not a new file, show perform update not create.
if isNew {
if com.IsExist(filename) {
return ErrWikiAlreadyExist{filename}
}
} else {
os.Remove(path.Join(localPath, oldTitle+".md"))
}
if err = ioutil.WriteFile(filename, []byte(content), 0666); err != nil {
return fmt.Errorf("WriteFile: %v", err)
}
if len(message) == 0 {
message = "Update page '" + title + "'"
}
if err = git.AddChanges(localPath, true); err != nil {
return fmt.Errorf("AddChanges: %v", err)
} else if err = git.CommitChanges(localPath, message, doer.NewGitSig()); err != nil {
return fmt.Errorf("CommitChanges: %v", err)
} else if err = git.Push(localPath, "origin", "master"); err != nil {
return fmt.Errorf("Push: %v", err)
}
return nil
}
开发者ID:cuteluo1983,项目名称:gogs,代码行数:54,代码来源:wiki.go
示例5: init
func init() {
// Load data.
if com.IsExist("data.txt") {
data, err := ioutil.ReadFile("data.txt")
if err != nil {
log.Printf("Fail to load data file: %v", err)
os.Exit(2)
}
if len(data) == 0 {
log.Println("Data file cannot be empty")
os.Exit(2)
}
for _, line := range strings.Split(string(data), "\n") {
line := strings.TrimSpace(line)
if len(line) == 0 {
continue
}
infos := strings.Split(line, "\t")
if len(infos) < 2 {
continue
}
people = append(people, person{infos[0], infos[1]})
}
} else {
// Generate fake data.
s := rand.NewSource(int64(time.Now().Nanosecond()))
r := rand.New(s)
for i := 0; i < 100; i++ {
info := com.ToStr(r.Int())
people = append(people, person{info, info})
}
}
}
开发者ID:xormplus,项目名称:examples,代码行数:34,代码来源:lottery.go
示例6: NewRepoContext
func NewRepoContext() {
zip.Verbose = false
// Check if server has basic git setting.
stdout, stderr, err := com.ExecCmd("git", "config", "--get", "user.name")
if strings.Contains(stderr, "fatal:") {
log.Fatal("repo.NewRepoContext(fail to get git user.name): %s", stderr)
} else if err != nil || len(strings.TrimSpace(stdout)) == 0 {
if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.email", "[email protected]"); err != nil {
log.Fatal("repo.NewRepoContext(fail to set git user.email): %s", stderr)
} else if _, stderr, err = com.ExecCmd("git", "config", "--global", "user.name", "Gogs"); err != nil {
log.Fatal("repo.NewRepoContext(fail to set git user.name): %s", stderr)
}
}
barePath := path.Join(setting.RepoRootPath, "git-bare.zip")
if !com.IsExist(barePath) {
data, err := bin.Asset("conf/content/git-bare.zip")
if err != nil {
log.Fatal("Fail to get asset 'git-bare.zip': %v", err)
} else if err := ioutil.WriteFile(barePath, data, os.ModePerm); err != nil {
log.Fatal("Fail to write asset 'git-bare.zip': %v", err)
}
}
}
开发者ID:jcfrank,项目名称:gogs,代码行数:25,代码来源:repo.go
示例7: ExampleIsExist
func ExampleIsExist() {
if com.IsExist("file.go") {
fmt.Println("file.go exists")
return
}
fmt.Println("file.go does not exist")
}
开发者ID:matm,项目名称:gobuild,代码行数:7,代码来源:example_test.go
示例8: 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
示例9: init
func init() {
hd, err := com.HomeDir()
if err != nil {
log.Error("", "Fail to get current user")
log.Fatal("", err.Error())
}
HomeDir = strings.Replace(RawHomeDir, "~", hd, -1)
cfgPath := path.Join(HomeDir, GOPM_CONFIG_FILE)
if !com.IsExist(cfgPath) {
os.MkdirAll(path.Dir(cfgPath), os.ModePerm)
if _, err = os.Create(cfgPath); err != nil {
log.Error("", "Fail to create gopm config file")
log.Fatal("", err.Error())
}
}
Cfg, err = goconfig.LoadConfigFile(cfgPath)
if err != nil {
log.Error("", "Fail to load gopm config file")
log.Fatal("", err.Error())
}
LoadLocalNodes()
LoadPkgNameList(path.Join(HomeDir, PKG_NAME_LIST_PATH))
}
开发者ID:kulasama,项目名称:gopm,代码行数:26,代码来源:conf.go
示例10: 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
示例11: LoadConfig
// LoadConfig loads configuration file.
func LoadConfig(cfgPath string) (*goconfig.ConfigFile, error) {
if !com.IsExist(cfgPath) {
os.Create(cfgPath)
}
return goconfig.LoadConfigFile(cfgPath)
}
开发者ID:sirithink,项目名称:beebbs,代码行数:8,代码来源:conf.go
示例12: CheckIsExistWithVCS
// CheckIsExistWithVCS returns false if directory only has VCS folder,
// or doesn't exist.
func CheckIsExistWithVCS(path string) bool {
// Check if directory exist.
if !com.IsExist(path) {
return false
}
// Check if only has VCS folder.
dirs, err := GetDirsInfo(path)
if err != nil {
log.Error("", "Fail to get directory's information")
log.Fatal("", err.Error())
}
if len(dirs) > 1 {
return true
} else if len(dirs) == 0 {
return false
}
switch dirs[0].Name() {
case ".git", ".hg", ".svn":
return false
}
return true
}
开发者ID:kulasama,项目名称:gopm,代码行数:28,代码来源:utils.go
示例13: runInit
func runInit(ctx *cli.Context) {
if com.IsExist(".bra.toml") {
fmt.Print("There is a .bra.toml in the work directory, do you want to overwrite?(y/n): ")
var answer string
fmt.Scan(&answer)
if strings.ToLower(answer) != "y" {
fmt.Println("Existed file is untouched.")
return
}
}
wd, err := os.Getwd()
if err != nil {
log.Fatal("Fail to get work directory: %v", err)
}
data, err := bindata.Asset("templates/default.bra.toml")
if err != nil {
log.Fatal("Fail to get asset: %v", err)
}
appName := filepath.Base(wd)
if runtime.GOOS == "windows" {
appName += ".exe"
}
data = bytes.Replace(data, []byte("$APP_NAME"), []byte(appName), -1)
if err := ioutil.WriteFile(".bra.toml", data, os.ModePerm); err != nil {
log.Fatal("Fail to generate default .bra.toml: %v", err)
}
}
开发者ID:zzhua,项目名称:bra,代码行数:31,代码来源:init.go
示例14: Listen
// Listen starts a SSH server listens on given port.
func Listen(port int) {
config := &ssh.ServerConfig{
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
pkey, err := models.SearchPublicKeyByContent(strings.TrimSpace(string(ssh.MarshalAuthorizedKey(key))))
if err != nil {
log.Error(3, "SearchPublicKeyByContent: %v", err)
return nil, err
}
return &ssh.Permissions{Extensions: map[string]string{"key-id": com.ToStr(pkey.ID)}}, nil
},
}
keyPath := filepath.Join(setting.AppDataPath, "ssh/gogs.rsa")
if !com.IsExist(keyPath) {
os.MkdirAll(filepath.Dir(keyPath), os.ModePerm)
_, stderr, err := com.ExecCmd("ssh-keygen", "-f", keyPath, "-t", "rsa", "-N", "")
if err != nil {
panic(fmt.Sprintf("Fail to generate private key: %v - %s", err, stderr))
}
log.Trace("New private key is generateed: %s", keyPath)
}
privateBytes, err := ioutil.ReadFile(keyPath)
if err != nil {
panic("Fail to load private key")
}
private, err := ssh.ParsePrivateKey(privateBytes)
if err != nil {
panic("Fail to parse private key")
}
config.AddHostKey(private)
go listen(config, port)
}
开发者ID:cuteluo1983,项目名称:gogs,代码行数:35,代码来源:ssh.go
示例15: runGen
// scan a directory and gen a gopm file
func runGen(ctx *cli.Context) {
setup(ctx)
if !com.IsExist(".gopmfile") {
os.Create(".gopmfile")
}
gf, err := goconfig.LoadConfigFile(".gopmfile")
if err != nil {
log.Error("gen", "Cannot load gopmfile:")
log.Fatal("", "\t"+err.Error())
}
// Get dependencies.
imports := doc.GetAllImports([]string{workDir},
parseTarget(gf.MustValue("target", "path")), ctx.Bool("example"))
for _, p := range imports {
p = doc.GetProjectPath(p)
if strings.HasSuffix(workDir, p) {
continue
}
if value := gf.MustValue("deps", p); len(value) == 0 {
gf.SetValue("deps", p, "")
}
}
err = goconfig.SaveConfigFile(gf, ".gopmfile")
if err != nil {
log.Error("gen", "Fail to save gopmfile:")
log.Fatal("", "\t"+err.Error())
}
log.Success("SUCC", "gen", "Generate gopmfile successfully!")
}
开发者ID:nashtsai,项目名称:gopm,代码行数:36,代码来源:gen.go
示例16: RewriteAllPublicKeys
// RewriteAllPublicKeys removes any authorized key and rewrite all keys from database again.
func RewriteAllPublicKeys() error {
sshOpLocker.Lock()
defer sshOpLocker.Unlock()
tmpPath := filepath.Join(setting.SSHRootPath, "authorized_keys.tmp")
f, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
defer os.Remove(tmpPath)
err = x.Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) {
_, err = f.WriteString((bean.(*PublicKey)).GetAuthorizedString())
return err
})
f.Close()
if err != nil {
return err
}
fpath := filepath.Join(setting.SSHRootPath, "authorized_keys")
if com.IsExist(fpath) {
if err = os.Remove(fpath); err != nil {
return err
}
}
if err = os.Rename(tmpPath, fpath); err != nil {
return err
}
return nil
}
开发者ID:cuteluo1983,项目名称:gogs,代码行数:33,代码来源:ssh_key.go
示例17: runGen
func runGen(ctx *cli.Context) {
setup(ctx)
if !com.IsExist(".gopmfile") {
os.Create(".gopmfile")
}
gf, err := goconfig.LoadConfigFile(".gopmfile")
if err != nil {
log.Error("gen", "Cannot load gopmfile:")
log.Fatal("", "\t"+err.Error())
}
targetPath := parseTarget(gf.MustValue("target", "path"))
// Get and set dependencies.
imports := doc.GetAllImports([]string{workDir}, targetPath, ctx.Bool("example"), false)
for _, p := range imports {
p = doc.GetProjectPath(p)
// Skip subpackage(s) of current project.
if isSubpackage(p, targetPath) {
continue
}
// Check if user specified the version.
if value := gf.MustValue("deps", p); len(value) == 0 {
gf.SetValue("deps", p, "")
}
}
// Get and set resources.
res := make([]string, 0, len(commonRes))
for _, cr := range commonRes {
if com.IsExist(cr) {
res = append(res, cr)
}
}
gf.SetValue("res", "include", strings.Join(res, "|"))
err = goconfig.SaveConfigFile(gf, ".gopmfile")
if err != nil {
log.Error("gen", "Fail to save gopmfile:")
log.Fatal("", "\t"+err.Error())
}
log.Success("SUCC", "gen", "Generate gopmfile successfully!")
}
开发者ID:puma007,项目名称:gopm,代码行数:46,代码来源:gen.go
示例18: Update
// Update updates hook settings.
func (h *Hook) Update() error {
if len(strings.TrimSpace(h.Content)) == 0 {
if com.IsExist(h.path) {
return os.Remove(h.path)
}
return nil
}
return ioutil.WriteFile(h.path, []byte(strings.Replace(h.Content, "\r", "", -1)), os.ModePerm)
}
开发者ID:Janfred,项目名称:gogs,代码行数:10,代码来源:hooks.go
示例19: RegisterDB
func RegisterDB() {
if !com.IsExist(_DB_NAME) {
os.MkdirAll(path.Dir(_DB_NAME), os.ModePerm)
os.Create(_DB_NAME)
}
orm.RegisterModel(new(Todo))
orm.RegisterDriver(_SQLITE3_DRIVER, orm.DR_Sqlite)
orm.RegisterDataBase("default", _SQLITE3_DRIVER, _DB_NAME, 10)
}
开发者ID:wocin,项目名称:gochair,代码行数:9,代码来源:todo.go
示例20: RegisterDB
func RegisterDB() {
if !com.IsExist(_DB_NAME) {
os.Mkdir(path.Dir(_DB_NAME), os.ModePerm)
os.Create(_DB_NAME)
}
orm.RegisterModel(new(Category), new(User), new(Companyinfo), new(Inquery), new(Product), new(Feedback), new(Log))
//orm.RegisterDriver(_SQLITE3_DRIVE, orm.DR_Sqlite)
orm.RegisterDataBase("default", _SQLITE3_DRIVE, _DB_NAME, 10)
}
开发者ID:pockees,项目名称:simpleweb,代码行数:9,代码来源:DbEntitys.go
注:本文中的github.com/Unknwon/com.IsExist函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论