...

Source file src/github.com/ory/x/urlx/path_windows.go

Documentation: github.com/ory/x/urlx

     1  // +build windows
     2  
     3  package urlx
     4  
     5  import (
     6  	"net/url"
     7  	"path/filepath"
     8  	"strings"
     9  )
    10  
    11  // GetURLFilePath returns the path of a URL that is compatible with the runtime os filesystem
    12  func GetURLFilePath(u *url.URL) string {
    13  	if u == nil {
    14  		return ""
    15  	}
    16  	if !(u.Scheme == "file" || u.Scheme == "") {
    17  		return u.Path
    18  	}
    19  
    20  	fPath := u.Path
    21  	if u.Host != "" {
    22  		// Make UNC Path
    23  		fPath = "\\\\" + u.Host + filepath.FromSlash(fPath)
    24  		return fPath
    25  	}
    26  	fPathTrimmed := strings.TrimLeft(fPath, "/")
    27  	if winPathRegex.MatchString(fPathTrimmed) {
    28  		// On Windows we should remove the initial path separator in case this
    29  		// is a normal path (for example: "\c:\" -> "c:\"")
    30  		fPath = fPathTrimmed
    31  	}
    32  	return filepath.FromSlash(fPath)
    33  }
    34  

View as plain text