func Clean(os, path string) string {
	abs := IsAbs(os, path)
	sep := Separator(os)
	elements := strings.Split(path, string(sep))
	for i := 0; i < len(elements); i++ {
		if len(elements[i]) == 0 {
			elements = append(elements[:i], elements[i+1:]...)
			i--
		}
	}
	for i := 0; i < len(elements); i++ {
		if elements[i] == "." && len(elements) > 1 {
			elements = append(elements[:i], elements[i+1:]...)
			i--
		}
	}
	for i := 1; i < len(elements); i++ {
		if i == 1 && abs && sep == '\\' {
			continue
		}
		if i > 0 && elements[i] == ".." {
			elements = append(elements[:i-1], elements[i+1:]...)
			i -= 2
		}
	}
	offset := 0
	if sep == '\\' {
		offset = 1
	}
	if abs {
		for len(elements) > offset && elements[offset] == ".." {
			elements = append(elements[:offset], elements[offset+1:]...)
		}
	}
	cleaned := strings.Join(elements, string(sep))
	if abs {
		if sep == '/' {
			cleaned = fmt.Sprintf("%c%s", sep, cleaned)
		} else if len(elements) == 1 {
			cleaned = fmt.Sprintf("%s%c", cleaned, sep)
		}
	}
	if len(cleaned) == 0 {
		cleaned = "."
	}
	if cleaned == path {
		return path
	}
	return Clean(os, cleaned)
}
Clean is an explicit-OS version of path/filepath's Clean.
package filepath
import (
	"fmt"
	"strings"
)