path.go 560 B

123456789101112131415161718192021222324252627
  1. // Copyright 2025 BackendServerTemplate Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package filesystemutils
  5. import (
  6. "path/filepath"
  7. "runtime"
  8. "strings"
  9. )
  10. func CleanFilePathAbs(path string) (string, error) {
  11. path, err := filepath.Abs(filepath.Clean(path))
  12. if err != nil {
  13. return "", err
  14. }
  15. if runtime.GOOS == "windows" {
  16. index := strings.Index(path, `:\`)
  17. pf := strings.ToUpper(path[:index])
  18. ph := path[index:]
  19. path = pf + ph
  20. }
  21. return path, nil
  22. }