Skip to content

Commit 4041287

Browse files
authored
Fix versioning and config/cache path (#13)
* Bump v0.0.10 * Fix config and cache path in different OS
1 parent c60ea6d commit 4041287

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

cmd/ipdex/config/options.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package config
22

33
import (
4-
"os"
5-
"path/filepath"
4+
"github.com/kirsle/configdir"
65

76
"github.com/crowdsecurity/ipdex/pkg/display"
87
)
@@ -20,19 +19,21 @@ var CacheFolder string
2019
var ConfigFolder string
2120

2221
func GetCacheFolder() (string, error) {
23-
home, err := os.UserHomeDir()
22+
cachePath := configdir.LocalCache("ipdex")
23+
err := configdir.MakePath(cachePath)
2424
if err != nil {
2525
return "", err
2626
}
27-
return filepath.Join(home, ".cache", "ipdex"), nil
27+
return cachePath, nil
2828
}
2929

3030
func GetConfigFolder() (string, error) {
31-
home, err := os.UserHomeDir()
31+
configPath := configdir.LocalConfig("ipdex")
32+
err := configdir.MakePath(configPath)
3233
if err != nil {
3334
return "", err
3435
}
35-
return filepath.Join(home, ".config", "ipdex"), nil
36+
return configPath, nil
3637
}
3738

3839
func IsSupportedOutputFormat(outputFormat string) bool {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ require (
3333
github.com/jinzhu/inflection v1.0.0 // indirect
3434
github.com/jinzhu/now v1.1.5 // indirect
3535
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
36+
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f // indirect
3637
github.com/lithammer/fuzzysearch v1.1.8 // indirect
3738
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
3839
github.com/magiconair/properties v1.8.9 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
7474
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
7575
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
7676
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
77+
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f h1:dKccXx7xA56UNqOcFIbuqFjAWPVtP688j5QMgmo6OHU=
78+
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f/go.mod h1:4rEELDSfUAlBSyUjPG0JnaNGjf13JySHFeRdD/3dLP0=
7779
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
7880
github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
7981
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=

pkg/version/version.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package version
22

33
import (
44
"fmt"
5+
"runtime/debug"
56
)
67

78
const (
8-
LatestVersion = "v0.0.8"
9+
LatestVersion = "v0.0.10"
910
)
1011

1112
var (
@@ -20,6 +21,11 @@ func FullString() string {
2021
}
2122

2223
func String() string {
24+
if info, ok := debug.ReadBuildInfo(); ok {
25+
if Version == "" {
26+
Version = info.Main.Version
27+
}
28+
}
2329
if Version == "" {
2430
Version = LatestVersion
2531
}

0 commit comments

Comments
 (0)