本文整理汇总了Golang中golang.org/x/tools/godoc/vfs/mapfs.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMakeFnIncludeFile_BasicRule
func TestMakeFnIncludeFile_BasicRule(t *testing.T) {
templateRules := template.Rules{}
templateRules.Attach(func(path []interface{}, node interface{}) (interface{}, interface{}) {
key := interface{}(nil)
if len(path) > 0 {
key = path[len(path)-1]
}
if key == "content" {
return key, interface{}("replaced")
}
return key, node
})
fs := mapfs.New(map[string]string{"a": "{\"content\": 1}"})
fnIncludeFile := MakeFnIncludeFile(fs, &templateRules)
input := interface{}(map[string]interface{}{
"Fn::IncludeFile": "/a",
})
expected := interface{}(map[string]interface{}{"content": "replaced"})
newKey, newNode := fnIncludeFile([]interface{}{"x", "y"}, input)
if newKey != "y" {
t.Fatalf("FnIncludeFile modified the path (%v instead of %v)", newKey, "y")
}
if !reflect.DeepEqual(newNode, expected) {
t.Fatalf("FnIncludeFile did not return the expected result (%#v instead of %#v)", newNode, expected)
}
}
开发者ID:wpalmer,项目名称:condense,代码行数:31,代码来源:FnIncludeFile_test.go
示例2: fsMapHandler
func fsMapHandler() types.RequestHandler {
var fileHandler = http.FileServer(httpfs.New(mapfs.New(fsmap)))
return types.RequestHandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
fileHandler.ServeHTTP(w, r)
})
}
开发者ID:na--,项目名称:nedomi,代码行数:7,代码来源:flv_test.go
示例3: TestNewNameSpace
func TestNewNameSpace(t *testing.T) {
// We will mount this filesystem under /fs1
mount := mapfs.New(map[string]string{"fs1file": "abcdefgh"})
// Existing process. This should give error on Stat("/")
t1 := vfs.NameSpace{}
t1.Bind("/fs1", mount, "/", vfs.BindReplace)
// using NewNameSpace. This should work fine.
t2 := emptyvfs.NewNameSpace()
t2.Bind("/fs1", mount, "/", vfs.BindReplace)
testcases := map[string][]bool{
"/": []bool{false, true},
"/fs1": []bool{true, true},
"/fs1/fs1file": []bool{true, true},
}
fss := []vfs.FileSystem{t1, t2}
for j, fs := range fss {
for k, v := range testcases {
_, err := fs.Stat(k)
result := err == nil
if result != v[j] {
t.Errorf("fs: %d, testcase: %s, want: %v, got: %v, err: %s", j, k, v[j], result, err)
}
}
}
}
开发者ID:srinathh,项目名称:emptyvfs,代码行数:31,代码来源:emptyvfs_test.go
示例4: TestReadOnly
func TestReadOnly(t *testing.T) {
m := map[string]string{"x": "y"}
rfs := mapfs.New(m)
wfs := ReadOnly(rfs)
if _, err := rfs.Stat("/x"); err != nil {
t.Error(err)
}
_, err := wfs.Create("/y")
if want := (&os.PathError{"create", "/y", ErrReadOnly}); !reflect.DeepEqual(err, want) {
t.Errorf("Create: got err %v, want %v", err, want)
}
err = wfs.Mkdir("/y")
if want := (&os.PathError{"mkdir", "/y", ErrReadOnly}); !reflect.DeepEqual(err, want) {
t.Errorf("Mkdir: got err %v, want %v", err, want)
}
err = wfs.Remove("/y")
if want := (&os.PathError{"remove", "/y", ErrReadOnly}); !reflect.DeepEqual(err, want) {
t.Errorf("Remove: got err %v, want %v", err, want)
}
}
开发者ID:ildarisaev,项目名称:srclib-go,代码行数:25,代码来源:vfs_test.go
示例5: ExampleWalk
func ExampleWalk() {
var fs http.FileSystem = httpfs.New(mapfs.New(map[string]string{
"zzz-last-file.txt": "It should be visited last.",
"a-file.txt": "It has stuff.",
"another-file.txt": "Also stuff.",
"folderA/entry-A.txt": "Alpha.",
"folderA/entry-B.txt": "Beta.",
}))
walkFn := func(path string, fi os.FileInfo, err error) error {
if err != nil {
log.Printf("can't stat file %s: %v\n", path, err)
return nil
}
fmt.Println(path)
return nil
}
err := vfsutil.Walk(fs, "/", walkFn)
if err != nil {
panic(err)
}
// Output:
// /
// /a-file.txt
// /another-file.txt
// /folderA
// /folderA/entry-A.txt
// /folderA/entry-B.txt
// /zzz-last-file.txt
}
开发者ID:pombredanne,项目名称:httpfs,代码行数:32,代码来源:walk_test.go
示例6: Example
func Example() {
fs0 := httpfs.New(mapfs.New(map[string]string{
"zzz-last-file.txt": "It should be visited last.",
"a-file.txt": "It has stuff.",
"another-file.txt": "Also stuff.",
"folderA/entry-A.txt": "Alpha.",
"folderA/entry-B.txt": "Beta.",
}))
fs1 := httpfs.New(mapfs.New(map[string]string{
"sample-file.txt": "This file compresses well. Blaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah!",
"not-worth-compressing-file.txt": "Its normal contents are here.",
"folderA/file1.txt": "Stuff 1.",
"folderA/file2.txt": "Stuff 2.",
"folderB/folderC/file3.txt": "Stuff C-3.",
}))
fs := union.New(map[string]http.FileSystem{
"/fs0": fs0,
"/fs1": fs1,
})
err := vfsutil.Walk(fs, "/", walk)
if err != nil {
panic(err)
}
// Output:
// /
// /fs0
// /fs0/a-file.txt
// /fs0/another-file.txt
// /fs0/folderA
// /fs0/folderA/entry-A.txt
// /fs0/folderA/entry-B.txt
// /fs0/zzz-last-file.txt
// /fs1
// /fs1/folderA
// /fs1/folderA/file1.txt
// /fs1/folderA/file2.txt
// /fs1/folderB
// /fs1/folderB/folderC
// /fs1/folderB/folderC/file3.txt
// /fs1/not-worth-compressing-file.txt
// /fs1/sample-file.txt
}
开发者ID:shurcooL,项目名称:httpfs,代码行数:45,代码来源:union_test.go
示例7: init
func init() {
enforceHosts = !appengine.IsDevAppServer()
playEnabled = true
log.Println("initializing godoc ...")
log.Printf(".zip file = %s", zipFilename)
log.Printf(".zip GOROOT = %s", zipGoroot)
log.Printf("index files = %s", indexFilenames)
goroot := path.Join("/", zipGoroot) // fsHttp paths are relative to '/'
// read .zip file and set up file systems
const zipfile = zipFilename
rc, err := zip.OpenReader(zipfile)
if err != nil {
log.Fatalf("%s: %s\n", zipfile, err)
}
// rc is never closed (app running forever)
fs.Bind("/", zipfs.New(rc, zipFilename), goroot, vfs.BindReplace)
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
corpus := godoc.NewCorpus(fs)
corpus.Verbose = false
corpus.MaxResults = 10000 // matches flag default in main.go
corpus.IndexEnabled = true
corpus.IndexFiles = indexFilenames
if err := corpus.Init(); err != nil {
log.Fatal(err)
}
corpus.IndexDirectory = indexDirectoryDefault
go corpus.RunIndexer()
pres = godoc.NewPresentation(corpus)
pres.TabWidth = 8
pres.ShowPlayground = true
pres.ShowExamples = true
pres.DeclLinks = true
pres.NotesRx = regexp.MustCompile("BUG")
readTemplates(pres, true)
mux := registerHandlers(pres)
dl.RegisterHandlers(mux)
short.RegisterHandlers(mux)
// Register /compile and /share handlers against the default serve mux
// so that other app modules can make plain HTTP requests to those
// hosts. (For reasons, HTTPS communication between modules is broken.)
proxy.RegisterHandlers(http.DefaultServeMux)
log.Println("godoc initialization complete")
}
开发者ID:ChloeTigre,项目名称:golang-tools,代码行数:52,代码来源:appinit.go
示例8: main
func main() {
server, err := blog.NewServer(cfg)
if err != nil {
log.Fatal(err)
}
http.Handle("/", server)
http.Handle("/lib/godoc/", http.StripPrefix("/lib/godoc/",
http.FileServer(httpfs.New(mapfs.New(static.Files))),
))
log.Fatal(http.ListenAndServe(":3999", nil))
}
开发者ID:iolg,项目名称:golangdoc,代码行数:13,代码来源:local.go
示例9: NewTestShell
// NewTestShell builds a test shell, notionally at path, with a set of files available
// to it built from the files map. Note that relative paths in the map are
// considered wrt the path
func NewTestShell(path string, files map[string]string) (*TestShell, error) {
ts := TestShell{
CmdsF: blissfulSuccess,
Sh: Sh{
Cwd: path,
Env: os.Environ(),
},
}
fs := make(map[string]string)
for n, c := range files {
fs[strings.TrimPrefix(ts.Abs(n), "/")] = c
}
ts.FS = mapfs.New(fs)
return &ts, nil
}
开发者ID:opentable,项目名称:sous,代码行数:18,代码来源:test_shell.go
示例10: Map
// Map returns a new FileSystem from the provided map. Map keys should be
// forward slash-separated pathnames and not contain a leading slash.
func Map(m map[string]string) FileSystem {
fs := mapFS{
m: m,
dirs: map[string]struct{}{"": struct{}{}},
FileSystem: mapfs.New(m),
}
// Create initial dirs.
for path := range m {
if err := MkdirAll(fs, filepath.Dir(path)); err != nil {
panic(err.Error())
}
}
return fs
}
开发者ID:ildarisaev,项目名称:srclib-go,代码行数:18,代码来源:map.go
示例11: newCorpus
func newCorpus(t *testing.T) *Corpus {
c := NewCorpus(mapfs.New(map[string]string{
"src/foo/foo.go": `// Package foo is an example.
package foo
import "bar"
const Pi = 3.1415
var Foos []Foo
// Foo is stuff.
type Foo struct{}
func New() *Foo {
return new(Foo)
}
`,
"src/bar/bar.go": `// Package bar is another example to test races.
package bar
`,
"src/other/bar/bar.go": `// Package bar is another bar package.
package bar
func X() {}
`,
"src/skip/skip.go": `// Package skip should be skipped.
package skip
func Skip() {}
`,
"src/bar/readme.txt": `Whitelisted text file.
`,
"src/bar/baz.zzz": `Text file not whitelisted.
`,
}))
c.IndexEnabled = true
c.IndexDirectory = func(dir string) bool {
return !strings.Contains(dir, "skip")
}
if err := c.Init(); err != nil {
t.Fatal(err)
}
return c
}
开发者ID:ChloeTigre,项目名称:golang-tools,代码行数:44,代码来源:index_test.go
示例12: init
func init() {
playEnabled = true
log.Println("initializing godoc ...")
log.Printf(".zip file = %s", zipFilename)
log.Printf(".zip GOROOT = %s", zipGoroot)
log.Printf("index files = %s", indexFilenames)
goroot := path.Join("/", zipGoroot) // fsHttp paths are relative to '/'
// read .zip file and set up file systems
const zipfile = zipFilename
rc, err := zip.OpenReader(zipfile)
if err != nil {
log.Fatalf("%s: %s\n", zipfile, err)
}
// rc is never closed (app running forever)
fs.Bind("/", zipfs.New(rc, zipFilename), goroot, vfs.BindReplace)
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
corpus := godoc.NewCorpus(fs)
corpus.Verbose = false
corpus.MaxResults = 10000 // matches flag default in main.go
corpus.IndexEnabled = true
corpus.IndexFiles = indexFilenames
if err := corpus.Init(); err != nil {
log.Fatal(err)
}
corpus.IndexDirectory = indexDirectoryDefault
go corpus.RunIndexer()
pres = godoc.NewPresentation(corpus)
pres.TabWidth = 8
pres.ShowPlayground = true
pres.ShowExamples = true
pres.DeclLinks = true
pres.NotesRx = regexp.MustCompile("BUG")
readTemplates(pres, true)
registerHandlers(pres)
log.Println("godoc initialization complete")
}
开发者ID:2722,项目名称:lantern,代码行数:43,代码来源:appinit.go
示例13: main
func main() {
var fs http.FileSystem = httpfs.New(mapfs.New(map[string]string{
"sample-file.txt": "This file compresses well. Blaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah!",
"not-worth-compressing-file.txt": "Its normal contents are here.",
"folderA/file1.txt": "Stuff in /folderA/file1.txt.",
"folderA/file2.txt": "Stuff in /folderA/file2.txt.",
"folderB/folderC/file3.txt": "Stuff in /folderB/folderC/file3.txt.",
// TODO: Empty folder somehow?
//"folder-empty/": "",
}))
err := vfsgen.Generate(fs, vfsgen.Options{
Filename: "test_vfsdata_test.go",
PackageName: "test_test",
})
if err != nil {
log.Fatalln(err)
}
}
开发者ID:pombredanne,项目名称:vfsgen,代码行数:19,代码来源:test_gen.go
示例14: loadFS
// loadFS reads the zip file of Go source code and binds.
func loadFS() {
// Load GOROOT (in zip file)
rsc, err := asset.Open(gorootZipFile) // asset file, never closed.
if err != nil {
panic(err)
}
offset, err := rsc.Seek(0, os.SEEK_END)
if err != nil {
panic(err)
}
if _, err = rsc.Seek(0, os.SEEK_SET); err != nil {
panic(err)
}
r, err := zip.NewReader(&readerAt{wrapped: rsc}, offset)
if err != nil {
panic(err)
}
fs.Bind("/", newZipFS(r, gorootZipFile), "/go", vfs.BindReplace)
// static files for godoc.
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
}
开发者ID:RoneyThomas,项目名称:mgodoc,代码行数:24,代码来源:godoc.go
示例15:
// This file was automatically generated based on the contents of *.tmpl
// If you need to update this file, change the contents of those files
// (or add new ones) and run 'go generate'
package main
import "golang.org/x/tools/godoc/vfs/mapfs"
var Templates = mapfs.New(map[string]string{
`ssl-config.tmpl`: "[ req ]\nprompt = no\ndistinguished_name=req_distinguished_name\nx509_extensions = va_c3\nencrypt_key = no\ndefault_keyfile=testing.key\ndefault_md = sha256\n\n[ va_c3 ]\nbasicConstraints=critical,CA:true,pathlen:1\n{{range . -}}\nsubjectAltName = IP:{{.}}\n{{end}}\n[ req_distinguished_name ]\nCN=registry.test\n",
})
开发者ID:opentable,项目名称:sous,代码行数:11,代码来源:vfs_template.go
示例16: NewMapFS
func NewMapFS(m map[string]string) *MapFS {
return &MapFS{mapfs.New(m)}
}
开发者ID:nucleardump,项目名称:go-wires,代码行数:3,代码来源:mapfs_test.go
示例17: main
func main() {
flag.Usage = usage
flag.Parse()
playEnabled = *showPlayground
// Check usage: either server and no args, command line and args, or index creation mode
if (*httpAddr != "" || *urlFlag != "") != (flag.NArg() == 0) && !*writeIndex {
usage()
}
var fsGate chan bool
fsGate = make(chan bool, 20)
// Determine file system to use.
if *zipfile == "" {
// use file system of underlying OS
rootfs := gatefs.New(vfs.OS(*goroot), fsGate)
fs.Bind("/", rootfs, "/", vfs.BindReplace)
} else {
// use file system specified via .zip file (path separator must be '/')
rc, err := zip.OpenReader(*zipfile)
if err != nil {
log.Fatalf("%s: %s\n", *zipfile, err)
}
defer rc.Close() // be nice (e.g., -writeIndex mode)
fs.Bind("/", zipfs.New(rc, *zipfile), *goroot, vfs.BindReplace)
}
if *templateDir != "" {
fs.Bind("/lib/godoc", vfs.OS(*templateDir), "/", vfs.BindBefore)
} else {
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
}
// Bind $GOPATH trees into Go root.
for _, p := range filepath.SplitList(build.Default.GOPATH) {
fs.Bind("/src", gatefs.New(vfs.OS(p), fsGate), "/src", vfs.BindAfter)
}
httpMode := *httpAddr != ""
var typeAnalysis, pointerAnalysis bool
if *analysisFlag != "" {
for _, a := range strings.Split(*analysisFlag, ",") {
switch a {
case "type":
typeAnalysis = true
case "pointer":
pointerAnalysis = true
default:
log.Fatalf("unknown analysis: %s", a)
}
}
}
corpus := godoc.NewCorpus(fs)
corpus.Verbose = *verbose
corpus.MaxResults = *maxResults
corpus.IndexEnabled = *indexEnabled && httpMode
if *maxResults == 0 {
corpus.IndexFullText = false
}
corpus.IndexFiles = *indexFiles
corpus.IndexDirectory = indexDirectoryDefault
corpus.IndexThrottle = *indexThrottle
corpus.IndexInterval = *indexInterval
if *writeIndex {
corpus.IndexThrottle = 1.0
corpus.IndexEnabled = true
}
if *writeIndex || httpMode || *urlFlag != "" {
if err := corpus.Init(); err != nil {
log.Fatal(err)
}
}
pres = godoc.NewPresentation(corpus)
pres.TabWidth = *tabWidth
pres.ShowTimestamps = *showTimestamps
pres.ShowPlayground = *showPlayground
pres.ShowExamples = *showExamples
pres.DeclLinks = *declLinks
pres.SrcMode = *srcMode
pres.HTMLMode = *html
if *notesRx != "" {
pres.NotesRx = regexp.MustCompile(*notesRx)
}
readTemplates(pres, httpMode || *urlFlag != "")
registerHandlers(pres)
if *writeIndex {
// Write search index and exit.
if *indexFiles == "" {
log.Fatal("no index file specified")
}
log.Println("initialize file systems")
*verbose = true // want to see what happens
//.........这里部分代码省略.........
开发者ID:2722,项目名称:lantern,代码行数:101,代码来源:main.go
示例18: mapFS
// mapFS creates a compatible vfs.FileSystem from a map.
func mapFS(m map[string]string) vfs.FileSystem { return prefixVFS{mapfs.New(m)} }
开发者ID:alexsaveliev,项目名称:vcsstore,代码行数:2,代码来源:tree_test.go
示例19: Example
func Example() {
walk := func(path string, fi os.FileInfo, err error) error {
if err != nil {
log.Printf("can't stat file %s: %v\n", path, err)
return nil
}
fmt.Println(path)
return nil
}
fs := httpfs.New(mapfs.New(map[string]string{
"zzz-last-file.txt": "It should be visited last.",
"a-file.txt": "It has stuff.",
"another-file.txt": "Also stuff.",
"some-file.html": "<html>and stuff</html>",
"folderA/entry-A.txt": "Alpha.",
"folderA/entry-B.txt": "Beta.",
"folderA/main.go": "package main\n",
"folderA/folder-to-skip/many.txt": "Entire folder can be skipped.",
"folderA/folder-to-skip/files.txt": "Entire folder can be skipped.",
"folder-to-skip": "This is a file, not a folder, and shouldn't be skipped.",
}))
ignore := func(fi os.FileInfo, _ string) bool {
return pathpkg.Ext(fi.Name()) == ".go" || pathpkg.Ext(fi.Name()) == ".html" ||
(fi.IsDir() && fi.Name() == "folder-to-skip")
}
fs = filter.NewIgnore(fs, ignore)
err := vfsutil.Walk(fs, "/", walk)
if err != nil {
panic(err)
}
fmt.Println()
// This file should be filtered out, even if accessed directly.
_, err = fs.Open("/folderA/main.go")
fmt.Println("os.IsNotExist(err):", os.IsNotExist(err))
fmt.Println(err)
fmt.Println()
// This folder should be filtered out, even if accessed directly.
_, err = fs.Open("/folderA/folder-to-skip")
fmt.Println("os.IsNotExist(err):", os.IsNotExist(err))
fmt.Println(err)
fmt.Println()
// This file should not be filtered out.
f, err := fs.Open("/folder-to-skip")
if err != nil {
panic(err)
}
io.Copy(os.Stdout, f)
f.Close()
// Output:
// /
// /a-file.txt
// /another-file.txt
// /folder-to-skip
// /folderA
// /folderA/entry-A.txt
// /folderA/entry-B.txt
// /zzz-last-file.txt
//
// os.IsNotExist(err): true
// open /folderA/main.go: file does not exist
//
// os.IsNotExist(err): true
// open /folderA/folder-to-skip: file does not exist
//
// This is a file, not a folder, and shouldn't be skipped.
}
开发者ID:slimsag,项目名称:httpfs,代码行数:77,代码来源:filter_test.go
示例20: MapSS
//MapSS is a convenience function to return a StaticServer based on a map
//mapping forward slash separated filepaths to strings. The paths cannot have
//a leading slash. This is implemented via a godoc virtual file system.
//Use errorHandlers to provide custom http.HandlerFunc to handle http.StatusNotFound
//and http.StatusInternalServerError or provide nil to use default implementation
//If a log.Logger is provided (ie. not nil), StaticServer does verbose logging
func MapSS(fs map[string]string, errorHandlers map[int]http.HandlerFunc, logger *log.Logger) StaticServer {
return VFSStaticServer(mapfs.New(fs), errorHandlers, logger)
}
开发者ID:srinathh,项目名称:staticserver,代码行数:9,代码来源:staticserver.go
注:本文中的golang.org/x/tools/godoc/vfs/mapfs.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论