Skip to content

Commit

Permalink
Fix default path loading under windows
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiojr committed May 10, 2020
1 parent fbad443 commit 602668a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion beehive.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func main() {
if err != nil {
log.Fatalf("Error loading configuration file from %s. err: %v", config.URL(), err)
}
log.Infof("Loading configuration from %s", config.URL())
log.Infof("Loading configuration from %s", config.URL().Raw)
} else { // try to load default config from user paths
path := cfg.Lookup()
if path == "" {
Expand Down
13 changes: 12 additions & 1 deletion cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strings"

"github.com/muesli/beehive/bees"
gap "github.com/muesli/go-app-paths"
Expand Down Expand Up @@ -157,7 +158,7 @@ func DefaultPath() string {
return cfgFileName
}

return path
return fixWindowsPath(path)
}

// Lookup tries to find the config file.
Expand Down Expand Up @@ -205,3 +206,13 @@ func exist(file string) bool {

return false
}

// Replace backward slashes in Windows paths with /, to make them suitable
// for Go URL parsing.
func fixWindowsPath(path string) string {
if runtime.GOOS == "windows" {
return strings.Replace(path, `\`, "/", -1)
}

return path
}
12 changes: 0 additions & 12 deletions cfg/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
)

// Replace backward slashes in Windows paths with /, to make them suitable
// for Go URL parsing.
func fixWindowsPath(path string) string {
if runtime.GOOS == "windows" {
return strings.Replace(path, `\`, "/", -1)
}

return path
}

func encryptedConfPath() string {
cwd, _ := os.Getwd()
return fixWindowsPath(filepath.Join(cwd, "testdata", "beehive-crypto.conf"))
Expand Down

0 comments on commit 602668a

Please sign in to comment.