filepath.Join
instead of concatenating strings with os.PathSeparator
GO-W4014path/filepath.Join
takes care of removing leading and trailing separators
and simplifying relative paths. This reduces the risk of path related bugs.
package main
import (
"os"
)
func getPath(dir, file string) string {
return dir + string(os.PathSeparator) + file
}
package main
import (
"path/filepath"
)
func getPath(dir, file string) string {
return filepath.Join(dir, file)
}