gh-ost/go/base/utils.go

34 lines
546 B
Go
Raw Normal View History

2016-04-18 10:59:34 -07:00
/*
Copyright 2016 GitHub Inc.
2016-05-16 11:09:17 +02:00
See https://github.com/github/gh-ost/blob/master/LICENSE
2016-04-18 10:59:34 -07:00
*/
package base
import (
"fmt"
"os"
2016-04-18 10:59:34 -07:00
"regexp"
"time"
)
var (
prettifyDurationRegexp = regexp.MustCompile("([.][0-9]+)")
)
func PrettifyDurationOutput(d time.Duration) string {
if d < time.Second {
return "0s"
}
result := fmt.Sprintf("%s", d)
result = prettifyDurationRegexp.ReplaceAllString(result, "")
return result
}
func FileExists(fileName string) bool {
if _, err := os.Stat(fileName); err == nil {
return true
}
return false
}