summaryrefslogtreecommitdiff
path: root/os.go
diff options
context:
space:
mode:
Diffstat (limited to 'os.go')
-rw-r--r--os.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/os.go b/os.go
index 59c24ccdf..44ec2ba9c 100644
--- a/os.go
+++ b/os.go
@@ -3,7 +3,9 @@ package main
import (
"github.com/golang/protobuf/proto"
"io/ioutil"
+ "net/url"
"os"
+ "path"
"strings"
)
@@ -31,6 +33,26 @@ func InitOS() {
})
}
+func ResolveModule(moduleSpecifier string, containingFile string) (
+ moduleName string, filename string, err error) {
+ moduleUrl, err := url.Parse(moduleSpecifier)
+ if err != nil {
+ return
+ }
+ baseUrl, err := url.Parse(containingFile)
+ if err != nil {
+ return
+ }
+ resolved := baseUrl.ResolveReference(moduleUrl)
+ moduleName = resolved.String()
+ if moduleUrl.IsAbs() {
+ filename = path.Join(SrcDir, resolved.Host, resolved.Path)
+ } else {
+ filename = resolved.Path
+ }
+ return
+}
+
func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out []byte) {
assert(moduleSpecifier != "", "moduleSpecifier shouldn't be empty")
res := &Msg{}