Refactor utils
This commit is contained in:
parent
903d33178d
commit
c2c941e94b
25
main.go
25
main.go
|
@ -18,6 +18,7 @@ import (
|
|||
|
||||
"github.com/cjbassi/gotop/colorschemes"
|
||||
"github.com/cjbassi/gotop/src/logging"
|
||||
"github.com/cjbassi/gotop/src/utils"
|
||||
w "github.com/cjbassi/gotop/src/widgets"
|
||||
)
|
||||
|
||||
|
@ -29,8 +30,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
configDir = getConfigDir(appName)
|
||||
logDir = getLogDir(appName)
|
||||
configDir = utils.GetConfigDir(appName)
|
||||
logDir = utils.GetLogDir(appName)
|
||||
logPath = filepath.Join(logDir, "errors.log")
|
||||
|
||||
stderrLogger = log.New(os.Stderr, "", 0)
|
||||
|
@ -59,26 +60,6 @@ var (
|
|||
bar *w.StatusBar
|
||||
)
|
||||
|
||||
func getConfigDir(name string) string {
|
||||
var basedir string
|
||||
if env := os.Getenv("XDG_CONFIG_HOME"); env != "" {
|
||||
basedir = env
|
||||
} else {
|
||||
basedir = filepath.Join(os.Getenv("HOME"), ".config")
|
||||
}
|
||||
return filepath.Join(basedir, name)
|
||||
}
|
||||
|
||||
func getLogDir(name string) string {
|
||||
var basedir string
|
||||
if env := os.Getenv("XDG_STATE_HOME"); env != "" {
|
||||
basedir = env
|
||||
} else {
|
||||
basedir = filepath.Join(os.Getenv("HOME"), ".local", "state")
|
||||
}
|
||||
return filepath.Join(basedir, name)
|
||||
}
|
||||
|
||||
func parseArgs() error {
|
||||
usage := `
|
||||
Usage: gotop [options]
|
||||
|
|
|
@ -45,10 +45,3 @@ func ConvertBytes(b uint64) (float64, string) {
|
|||
return BytesToTB(b), "TB"
|
||||
}
|
||||
}
|
||||
|
||||
func MaxInt(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
8
src/utils/math.go
Normal file
8
src/utils/math.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package utils
|
||||
|
||||
func MaxInt(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
26
src/utils/xdg.go
Normal file
26
src/utils/xdg.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func GetConfigDir(name string) string {
|
||||
var basedir string
|
||||
if env := os.Getenv("XDG_CONFIG_HOME"); env != "" {
|
||||
basedir = env
|
||||
} else {
|
||||
basedir = filepath.Join(os.Getenv("HOME"), ".config")
|
||||
}
|
||||
return filepath.Join(basedir, name)
|
||||
}
|
||||
|
||||
func GetLogDir(name string) string {
|
||||
var basedir string
|
||||
if env := os.Getenv("XDG_STATE_HOME"); env != "" {
|
||||
basedir = env
|
||||
} else {
|
||||
basedir = filepath.Join(os.Getenv("HOME"), ".local", "state")
|
||||
}
|
||||
return filepath.Join(basedir, name)
|
||||
}
|
Loading…
Reference in New Issue
Block a user