1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00
cowyo/vendor/github.com/shurcooL/go/gopherjs_http/package.go

29 lines
754 B
Go
Raw Normal View History

2017-10-03 21:43:55 +03:00
package gopherjs_http
import (
"go/build"
"net/http"
"os"
)
// Package returns an http.FileSystem that contains a single file at root,
// containing result of building package with importPath using GopherJS.
func Package(importPath string) http.FileSystem {
return packageFS{importPath: importPath}
}
type packageFS struct {
importPath string
}
func (fs packageFS) Open(name string) (http.File, error) {
if name != "/" {
return nil, &os.PathError{Op: "open", Path: name, Err: os.ErrNotExist}
}
p, err := build.Import(fs.importPath, "", build.FindOnly)
if err != nil {
return nil, &os.PathError{Op: `"go/build".Import`, Path: fs.importPath, Err: err}
}
return (&gopherJSFS{source: http.Dir(p.SrcRoot)}).compileGoPackage(p.ImportPath)
}