diff --git a/internal/internal.go b/internal/internal.go index bbd233fb..3ae00440 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -22,6 +22,10 @@ func ConfigDir() (string, error) { return configDir, nil } + if osUserConfigDir := getOSUserConfigDir(); osUserConfigDir != "" { + return osUserConfigDir, nil + } + if runtime.GOOS == "windows" { return filepath.Join(os.Getenv("APPDATA"), "gops"), nil } diff --git a/internal/internal_go1_13.go b/internal/internal_go1_13.go new file mode 100644 index 00000000..6e823138 --- /dev/null +++ b/internal/internal_go1_13.go @@ -0,0 +1,19 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.13 + +package internal + +import ( + "os" +) + +func getOSUserConfigDir() string { + configDir, err := os.UserConfigDir() + if err != nil { + return "" + } + return configDir +} diff --git a/internal/internal_lt_go1_13.go b/internal/internal_lt_go1_13.go new file mode 100644 index 00000000..8506cf5f --- /dev/null +++ b/internal/internal_lt_go1_13.go @@ -0,0 +1,11 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !go1.13 + +package internal + +func getOSUserConfigDir() string { + return "" +}