本文整理汇总了Golang中github.com/toolkits/file.ToTrimString函数的典型用法代码示例。如果您正苦于以下问题:Golang ToTrimString函数的具体用法?Golang ToTrimString怎么用?Golang ToTrimString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ToTrimString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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")
}
示例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
}
示例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)
}
示例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)
}
示例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.]")
}
示例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")
}
示例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")
}
示例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)
}
示例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")
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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)
}