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

Golang file.ToTrimString函数代码示例

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

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



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

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


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


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


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


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


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


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


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


示例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")
	}

	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


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


示例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)
	}

	// 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


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


示例13: SystemUptime

func SystemUptime() (days, hours, mins int64, err error) {
	var content string
	content, err = file.ToTrimString("/proc/uptime")
	if err != nil {
		return
	}

	fields := strings.Fields(content)
	if len(fields) < 2 {
		err = fmt.Errorf("/proc/uptime format not supported")
		return
	}

	secStr := fields[0]
	var secF float64
	secF, err = strconv.ParseFloat(secStr, 64)
	if err != nil {
		return
	}

	minTotal := secF / 60.0
	hourTotal := minTotal / 60.0

	days = int64(hourTotal / 24.0)
	hours = int64(hourTotal) - days*24
	mins = int64(minTotal) - (days * 60 * 24) - (hours * 60)

	return
}
开发者ID:ziyel,项目名称:nux,代码行数:29,代码来源:system.go


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


示例15: KernelAllocateFiles

func KernelAllocateFiles() (ret uint64, err error) {
	var content string
	file_nr := "/proc/sys/fs/file-nr"
	content, err = file.ToTrimString(file_nr)
	if err != nil {
		return
	}

	arr := strings.Fields(content)
	if len(arr) != 3 {
		err = fmt.Errorf("%s format error", file_nr)
		return
	}

	return strconv.ParseUint(arr[0], 10, 64)
}
开发者ID:shenjh369,项目名称:nux,代码行数:16,代码来源:kernel.go


示例16: ParseConfig

func ParseConfig(cfg string) error {
	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		return err
	}

	var c GlobalConfig

	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		return err
	}

	Cfg = &c

	return nil
}
开发者ID:yj2317916,项目名称:yj-agent,代码行数:17,代码来源:config.go


示例17: ParseNodeConfig

func ParseNodeConfig(cfg string) {
	if cfg == "" {
		log.Println("请配置nodepath")
		cfg = "node.file"
	}

	if !file.IsExist(cfg) {
		log.Println("node file:", cfg, "is not existent.`")
		return
	}

	NodeFilePath = cfg

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

	c := Nodefile{}
	err = json.Unmarshal([]byte(configContent), &c)
	if err != nil {
		log.Println("parse node file:", cfg, "fail:", err)
		return
	}

	nm := make(map[string]string)
	for _, node := range c.Data {
		if len(node.Nodeout_ports) == 0 {
			continue
		}
		//fmt.Printf("%v\n", node)
		//fmt.Printf("%#v\n", len(node.Nodeout_ports))
		for _, port := range node.Nodeout_ports {
			nm[node.Manage_ip+port.Name] = node.Node.ID
			//fmt.Printf("%s%s:%s\n", node.Manage_ip, port.Name, node.Node.ID)
		}
	}
	lock.Lock()
	defer lock.Unlock()

	nodemap = &nm

	log.Println("read node file:", cfg, "successfully")
}
开发者ID:yanghongkjxy,项目名称:octopux-swtfr,代码行数:45,代码来源:nodeinfo.go


示例18: InitFlows

func InitFlows() {
	cfg := revel.BasePath + "/conf/flow.json"

	if !file.IsExist(cfg) {
		file, _ := os.Getwd()
		revel.ERROR.Fatalln("config file:", cfg, "is not existent. getcwd", file)
	}
	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		revel.ERROR.Fatalln("read config file:", cfg, "fail:", err)
	}

	err = json.Unmarshal([]byte(configContent), &Flows)
	if err != nil {
		revel.ERROR.Fatalln("parse config file:", cfg, "fail:", err)
	} else {
		revel.INFO.Println("InitFlows ok")
	}
}
开发者ID:baiyuxiong,项目名称:lms,代码行数:19,代码来源:init.go


示例19: parseConfig

/**
 * @function name:   func parseConfig()
 * @description:     This function parses config file cfg.json.
 * @related issues:  OWL-201, OWL-115, OWL-085
 * @param:           void
 * @return:          void
 * @author:          Don Hsieh
 * @since:           09/14/2015
 * @last modified:   12/10/2015
 * @called by:       func Register(r *macaron.Macaron)
 */
func parseConfig() {
	cfg := "cfg.json"
	if !file.IsExist(cfg) {
		log.Fatal(4, "config file:", cfg, "is not existent. maybe you need `mv cfg.example.json cfg.json`")
	}
	configContent, err := file.ToTrimString(cfg)
	if err != nil {
		log.Fatal(4, "read config file:", cfg, "fail:", err)
	}

	var configGlobal GlobalConfig
	err = json.Unmarshal([]byte(configContent), &configGlobal)
	if err != nil {
		log.Fatal(4, "parse config file:", cfg, "fail:", err)
		return
	}
	lock.Lock()
	defer lock.Unlock()
	ConfigOpenFalcon = &configGlobal
}
开发者ID:Cepave,项目名称:grafana,代码行数:31,代码来源:setting.go


示例20: ReadDesiredAgents

func ReadDesiredAgents() []*model.DesiredAgent {
	var desiredAgents []*model.DesiredAgent
	strJson, err := f.ToTrimString(path.Join(f.SelfDir(), "desired_agent.json"))
	if nil != err {
		logger.Errorln("read desired agent file error", err)
		return desiredAgents
	}
	err = json.Unmarshal([]byte(strJson), &desiredAgents)
	if nil != err {
		logger.Errorln("unmarshal json error", strJson, err)
	}

	for _, da := range desiredAgents {
		actualVersion := ReadVersion(da.RunUser, path.Join(da.WorkDir, da.Name))
		if "" != actualVersion {
			da.Version = actualVersion
		}
	}
	return desiredAgents
}
开发者ID:coraldane,项目名称:ops-updater,代码行数:20,代码来源:request.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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