diff --git a/config.go b/config.go index ad3a2ef..ce1ee59 100644 --- a/config.go +++ b/config.go @@ -20,11 +20,17 @@ func loadConfig(path string) (*Config, error) { return nil, err } + config.WorkingDirectory = filepath.ToSlash(config.WorkingDirectory) + + if len(config.WorkingDirectory) > 0 && string(config.WorkingDirectory[len(config.WorkingDirectory)-1]) != "/" { + config.WorkingDirectory += "/" + } + workingDirectory, err := filepath.Abs(config.WorkingDirectory) if err != nil { return nil, err } - config.WorkingDirectory = workingDirectory + config.WorkingDirectory = filepath.ToSlash(workingDirectory) return &config, nil } diff --git a/handlers.go b/handlers.go index 9d111ad..ae405be 100644 --- a/handlers.go +++ b/handlers.go @@ -15,7 +15,12 @@ func getResponse(path string) ([]Item, error) { } for i := range fileNames { - fileNames[i] = strings.TrimPrefix(filepath.ToSlash(fileNames[i]), filepath.ToSlash(config.WorkingDirectory))[1:] // TODO: check is first slash properly removed + prefix := config.WorkingDirectory + if string(prefix[len(prefix)-1]) == "/" { + prefix = prefix[:len(prefix)-1] + } + + fileNames[i] = strings.TrimPrefix(filepath.ToSlash(fileNames[i]), prefix)[1:] // TODO: check is first slash properly removed } items := make([]Item, 0)