decred.org/dcrdex@v1.0.5/client/app/fileurl_windows.go (about)

     1  //go:build windows
     2  
     3  package app
     4  
     5  import (
     6  	"path/filepath"
     7  )
     8  
     9  // Windows requires a leading "/" before the "C:" of an absolute path, and
    10  // slashes converted to forward slashes.
    11  // https://en.wikipedia.org/wiki/File_URI_scheme#Windows
    12  
    13  func FilePathToURL(name string) (string, error) {
    14  	path, err := filepath.Abs(name)
    15  	if err != nil { // can't pwd if name was relative, probably impossible
    16  		return "", err
    17  	}
    18  	path = filepath.ToSlash(path)
    19  	return "file:///" + path, nil
    20  }