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

Golang file.IsExist函数代码示例

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

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



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

示例1: ParseConfig

func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("use -c to specify configuration file")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("config file:", cfg, "is not existent")
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("read config file:", cfg, "fail:", err)
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("parse config file:", cfg, "fail:", err)
	}
	if !file.IsExist(c.ExternalNodes) {
		log.Printf("WARN: the external_nodes file [%s] is not exist!", c.ExternalNodes)
		c.ExternalNodes = ""
	}

	configLock.Lock()
	defer configLock.Unlock()

	config = &c

	log.Println("read config file:", cfg, "successfully")
}
开发者ID:Liuyanglong,项目名称:monitor-hbs,代码行数:33,代码来源:cfg.go


示例2: StopAgentOf

func StopAgentOf(agentName, newVersion string) error {
	agentDir := path.Join(g.SelfDir, agentName)
	versionFile := path.Join(agentDir, ".version")

	if !file.IsExist(versionFile) {
		log.Printf("WARN: %s is nonexistent", versionFile)
		return nil
	}

	version, err := file.ToTrimString(versionFile)
	if err != nil {
		log.Printf("WARN: read %s fail %s", version, err)
		return nil
	}

	if version == newVersion {
		// do nothing
		return nil
	}

	versionDir := path.Join(agentDir, version)
	if !file.IsExist(versionDir) {
		log.Printf("WARN: %s nonexistent", versionDir)
		return nil
	}

	return ControlStopIn(versionDir)
}
开发者ID:Cepave,项目名称:ops-updater,代码行数:28,代码来源:stop.go


示例3: configPluginRoutes

func configPluginRoutes() {
	http.HandleFunc("/plugin/update", func(w http.ResponseWriter, r *http.Request) {
		if !g.Config().Plugin.Enabled {
			w.Write([]byte("plugin not enabled"))
			return
		}

		dir := g.Config().Plugin.Dir
		parentDir := file.Dir(dir)
		file.InsureDir(parentDir)

		if file.IsExist(dir) {
			// git pull
			cmd := exec.Command("git", "pull")
			cmd.Dir = dir
			err := cmd.Run()
			if err != nil {
				w.Write([]byte(fmt.Sprintf("git pull in dir:%s fail. error: %s", dir, err)))
				return
			}
		} else {
			// git clone
			cmd := exec.Command("git", "clone", g.Config().Plugin.Git, file.Basename(dir))
			cmd.Dir = parentDir
			err := cmd.Run()
			if err != nil {
				w.Write([]byte(fmt.Sprintf("git clone in dir:%s fail. error: %s", parentDir, err)))
				return
			}
		}

		w.Write([]byte("success"))
	})

	http.HandleFunc("/plugin/reset", func(w http.ResponseWriter, r *http.Request) {
		if !g.Config().Plugin.Enabled {
			w.Write([]byte("plugin not enabled"))
			return
		}

		dir := g.Config().Plugin.Dir

		if file.IsExist(dir) {
			cmd := exec.Command("git", "reset", "--hard")
			cmd.Dir = dir
			err := cmd.Run()
			if err != nil {
				w.Write([]byte(fmt.Sprintf("git reset --hard in dir:%s fail. error: %s", dir, err)))
				return
			}
		}
		w.Write([]byte("success"))
	})

	http.HandleFunc("/plugins", func(w http.ResponseWriter, r *http.Request) {
		//TODO: not thread safe
		RenderDataJson(w, plugins.Plugins)
	})
}
开发者ID:ZeaLoVe,项目名称:falcon-winAgent,代码行数:59,代码来源:plugin.go


示例4: AllProcs

func AllProcs() (ps []*Proc, err error) {
	var dirs []string
	dirs, err = file.DirsUnder("/proc")
	if err != nil {
		return
	}

	size := len(dirs)
	if size == 0 {
		return
	}

	for i := 0; i < size; i++ {
		pid, e := strconv.Atoi(dirs[i])
		if e != nil {
			continue
		}

		statusFile := fmt.Sprintf("/proc/%d/status", pid)
		cmdlineFile := fmt.Sprintf("/proc/%d/cmdline", pid)
		if !file.IsExist(statusFile) || !file.IsExist(cmdlineFile) {
			continue
		}

		name, e := ReadName(statusFile)
		if e != nil {
			continue
		}

		cmdlineBytes, e := file.ToBytes(cmdlineFile)
		if e != nil {
			continue
		}

		cmdlineBytesLen := len(cmdlineBytes)
		if cmdlineBytesLen == 0 {
			continue
		}

		noNut := make([]byte, 0, cmdlineBytesLen)

		for j := 0; j < cmdlineBytesLen; j++ {
			if cmdlineBytes[j] != 0 {
				noNut = append(noNut, cmdlineBytes[j])
			}
		}

		p := Proc{Pid: pid, Name: name, Cmdline: string(noNut)}
		ps = append(ps, &p)
	}

	return
}
开发者ID:shenjh369,项目名称:nux,代码行数:53,代码来源:proc.go


示例5: BuildHeartbeatRequest

func BuildHeartbeatRequest(hostname string, agentDirs []string) model.HeartbeatRequest {
	req := model.HeartbeatRequest{Hostname: hostname}

	realAgents := []*model.RealAgent{}
	now := time.Now().Unix()

	for _, agentDir := range agentDirs {
		// 如果目录下没有.version,我们认为这根本不是一个agent
		versionFile := path.Join(g.SelfDir, agentDir, ".version")
		if !f.IsExist(versionFile) {
			continue
		}

		version, err := f.ToTrimString(versionFile)
		if err != nil {
			log.Printf("read %s/.version fail: %v", agentDir, err)
			continue
		}

		controlFile := path.Join(g.SelfDir, agentDir, version, "control")
		if !f.IsExist(controlFile) {
			log.Printf("%s is nonexistent", controlFile)
			continue
		}

		cmd := exec.Command("./control", "status")
		cmd.Dir = path.Join(g.SelfDir, agentDir, version)
		bs, err := cmd.CombinedOutput()

		status := ""
		if err != nil {
			status = fmt.Sprintf("exec `./control status` fail: %s", err)
		} else {
			status = strings.TrimSpace(string(bs))
		}

		realAgent := &model.RealAgent{
			Name:      agentDir,
			Version:   version,
			Status:    status,
			Timestamp: now,
		}

		realAgents = append(realAgents, realAgent)
	}

	req.RealAgents = realAgents
	return req
}
开发者ID:GaoJiasheng,项目名称:agent-updater,代码行数:49,代码来源:request.go


示例6: FilesReady

func FilesReady(da *model.DesiredAgent) bool {
	if !file.IsExist(da.Md5Filepath) {
		return false
	}

	if !file.IsExist(da.TarballFilepath) {
		return false
	}

	if !file.IsExist(da.ControlFilepath) {
		return false
	}

	return utils.Md5sumCheck(da.AgentVersionDir, da.Md5Filename)
}
开发者ID:GaoJiasheng,项目名称:agent-updater,代码行数:15,代码来源:start.go


示例7: ParseConfig

func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("use -c to specify one config file")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("config file:", cfg, "not exist")
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("read config file:", cfg, "failed:", err)
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("parse config file:", cfg, "failed:", err)
	}

	// check
	if !checkConfig(c) {
		log.Fatalln("check config file:", cfg, "failed")
	}

	configLock.Lock()
	defer configLock.Unlock()
	config = &c

	log.Println("g.ParseConfig ok, file ", cfg)
}
开发者ID:niean,项目名称:godemos,代码行数:33,代码来源:cfg.go


示例8: StopDesiredAgent

func StopDesiredAgent(da *model.DesiredAgent) {
	if !file.IsExist(da.ControlFilepath) {
		return
	}

	ControlStopIn(da.AgentVersionDir)
}
开发者ID:Cepave,项目名称:ops-updater,代码行数:7,代码来源:stop.go


示例9: ParseConfig

func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("use -c to specify configuration file")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("config file:", cfg, "is not existent. maybe you need `mv cfg.example.json cfg.json`")
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("read config file:", cfg, "fail:", err)
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("parse config file:", cfg, "fail:", err)
	}

	// split cluster config
	c.Judge.Cluster2 = formatClusterItems(c.Judge.Cluster)
	c.Graph.Cluster2 = formatClusterItems(c.Graph.Cluster)
	c.Graph.ClusterMigrating2 = formatClusterItems(c.Graph.ClusterMigrating)

	configLock.Lock()
	defer configLock.Unlock()
	config = &c

	log.Println("g.ParseConfig ok, file ", cfg)
}
开发者ID:Charlesdong,项目名称:transfer,代码行数:33,代码来源:cfg.go


示例10: ParseConfig

func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("config file not specified: use -c $filename")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("config file specified not found:", cfg)
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("read config file", cfg, "error:", err.Error())
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("parse config file", cfg, "error:", err.Error())
	}

	if c.Migrate.Enabled && len(c.Migrate.Cluster) == 0 {
		c.Migrate.Enabled = false
	}

	// set config
	atomic.StorePointer(&ptr, unsafe.Pointer(&c))

	log.Println("g.ParseConfig ok, file", cfg)
}
开发者ID:masato25,项目名称:graph,代码行数:31,代码来源:cfg.go


示例11: ParseConfig

func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("use -c to specify configuration file")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("config file:", cfg, "is not existent. maybe you need `mv cfg.example.json cfg.json`")
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("read config file:", cfg, "fail:", err)
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("parse config file:", cfg, "fail:", err)
	}

	lock.Lock()
	defer lock.Unlock()

	config = &c

	log.Println("read config file:", cfg, "successfully")
}
开发者ID:donh,项目名称:agent,代码行数:29,代码来源:cfg.go


示例12: ParseConfig

// Reference to Open-Falcon's ParseConfig()
func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("Config file not specified: use -c $filename")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("Config file specified not found:", cfg)
	}

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("Read config file", cfg, "error:", err.Error())
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("Parse config file", cfg, "error:", err.Error())
	}

	// set config
	configLock.Lock()
	defer configLock.Unlock()
	Config = &c

	printDebug(2, "ParseConfig:", cfg, "[DONE.]")
}
开发者ID:crosserclaws,项目名称:openfalcon-test,代码行数:28,代码来源:main.go


示例13: LoadAddrs

func (t *RingBackend) LoadAddrs(f string) error {
	if !file.IsExist(f) {
		return errors.New("backends file is not exist")
	}

	file_content, err := file.ToString(f)
	if err != nil {
		return err
	}
	file_content = strings.Trim(file_content, " \n\t")

	lines := strings.Split(file_content, "\n")
	if len(lines) == 0 {
		return errors.New("empty backends")
	}

	tmp_addrs := make(map[string][]string)
	for _, line := range lines {
		fields := strings.Fields(line)
		size := len(fields)
		if size < 2 {
			logger.Warn("invalid backend %s", line)
			continue
		}
		name := fields[0]
		addr := fields[1:size]
		tmp_addrs[name] = addr
	}

	t.Lock()
	defer t.Unlock()
	t.Addrs = tmp_addrs

	return nil
}
开发者ID:huangjiasingle,项目名称:cpool,代码行数:35,代码来源:pool.go


示例14: ParseConfig

func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("use -c to specify configuration file")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("config file:", cfg, "is not existent")
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("read config file:", cfg, "fail:", err)
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("parse config file:", cfg, "fail:", err)
	}

	configLock.Lock()
	defer configLock.Unlock()

	config = &c

	logger.SetLevel(config.LogLevel)
	log.Println("read config file:", cfg, "successfully")
}
开发者ID:Jimbean0615,项目名称:query,代码行数:30,代码来源:cfg.go


示例15: ParseConfig

func ParseConfig(cfg string) error {
	if cfg == "" {
		return fmt.Errorf("use -c to specify configuration file")
	}

	if !file.IsExist(cfg) {
		return fmt.Errorf("config file %s is nonexistent", cfg)
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		return fmt.Errorf("read config file %s fail %s", cfg, err)
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		return fmt.Errorf("parse config file %s fail %s", cfg, err)
	}

	configLock.Lock()
	defer configLock.Unlock()

	config = &c

	log.Println("read config file:", cfg, "successfully")
	return nil
}
开发者ID:coraldane,项目名称:ops-meta,代码行数:30,代码来源:cfg.go


示例16: ParseConfig

func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("config file not specified: use -c $filename")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("config file specified not found:", cfg)
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("read config file", cfg, "error:", err.Error())
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("parse config file", cfg, "error:", err.Error())
	}

	SetConfig(&c)

	logger.InitLogger(c.Debug)
	log.Println("g.ParseConfig ok, file", cfg)
}
开发者ID:donh,项目名称:query,代码行数:27,代码来源:cfg.go


示例17: ParseConfig

func ParseConfig(cfg string) {
	if cfg == "" {
		log.Fatalln("config file not specified: use -c $filename")
	}

	if !file.IsExist(cfg) {
		log.Fatalln("config file specified not found:", cfg)
	}

	ConfigFile = cfg

	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatalln("read config file", cfg, "error:", err.Error())
	}

	var c GlobalConfig
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("parse config file", cfg, "error:", err.Error())
	}

	// set config
	configLock.Lock()
	defer configLock.Unlock()
	config = &c

	log.Println("g.ParseConfig ok, file", cfg)
}
开发者ID:tal-nino,项目名称:query,代码行数:29,代码来源:cfg.go


示例18: loadJSONConfig

func loadJSONConfig(cfgFile string) {
	cfgFile = filepath.Clean(cfgFile)
	cfgPath := getCfgAbsPath(cfgFile)

	if !file.IsExist(cfgPath) {
		log.Fatalln("Configuration file [", cfgFile, "] doesn't exist")
	}

	configContent, err := file.ToTrimString(cfgPath)
	if err != nil {
		log.Fatalln("Reading configuration file [", cfgFile, "] failed:", err)
	}

	var c JSONConfigFile
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Fatalln("Parsing configuration file [", cfgFile, "] failed:", err)
	}

	jsonCfgLock.Lock()
	defer jsonCfgLock.Unlock()

	jsonConfig = &c

	log.Println("Reading configuration file [", cfgFile, "] succeeded")
}
开发者ID:Cepave,项目名称:nqm-agent,代码行数:26,代码来源:cfg.go


示例19: configPageRoutes

func configPageRoutes() {

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		if strings.HasSuffix(r.URL.Path, "/") {
			if !file.IsExist(filepath.Join(g.Root, "/public", r.URL.Path, "index.html")) {
				http.NotFound(w, r)
				return
			}
		}
		http.FileServer(http.Dir(filepath.Join(g.Root, "/public"))).ServeHTTP(w, r)
	})

}
开发者ID:tplink-zgc,项目名称:falcon-agent,代码行数:13,代码来源:page.go


示例20: CheckFileOrDirExists

func CheckFileOrDirExists(username, fp, fileType string) bool {
	if CurrentUser == username {
		return file.IsExist(fp)
	} else {
		cmd := BuildCommand(username, "sh", "check_file.sh", fileType, fp)
		cmd.Dir = file.SelfDir()
		strOut, err := ExecuteCommandWithOutput(cmd)
		if nil != err {
			logger.Errorln("check dir exists", strOut, err)
			return false
		}
		result, _ := strconv.ParseBool(strings.Replace(strOut, "\n", "", -1))
		return result
	}
	return false
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:16,代码来源:control.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang file.ReadLine函数代码示例发布时间:2022-05-28
下一篇:
Golang list.SafeListLimited类代码示例发布时间: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