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

     1  //go:build darwin
     2  
     3  package app
     4  
     5  import (
     6  	"net/url"
     7  	"path/filepath"
     8  )
     9  
    10  // Darwin appears to need paths pre-escaped.
    11  
    12  func FilePathToURL(name string) (string, error) {
    13  	path, err := filepath.Abs(name)
    14  	if err != nil { // can't pwd if name was relative, probably impossible
    15  		return "", err
    16  	}
    17  	fileURL, err := url.Parse("file://" + path)
    18  	if err != nil {
    19  		return "", err
    20  	}
    21  	// url.Parse can be touchy, so consider replacing only spaces, manually:
    22  	// path = strings.ReplaceAll(path, " ", "%20")
    23  	return fileURL.String(), nil
    24  }