当前位置: 首页>>代码示例>>Golang>>正文


Golang GridFile.Name方法代码示例

本文整理汇总了Golang中labix/org/v2/mgo.GridFile.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang GridFile.Name方法的具体用法?Golang GridFile.Name怎么用?Golang GridFile.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在labix/org/v2/mgo.GridFile的用法示例。


在下文中一共展示了GridFile.Name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	flag.Parse()
	if *dirPath == "" {
		log.Fatal("Please specify directory path for uploaded files")
	}

	var s *Server = NewServer()
	s.Run()
	//For listing the available GridFS objects

	defer s.session.Close()

	var result *mgo.GridFile
	iter := s.gfs.Find(nil).Iter()

	for s.gfs.OpenNext(iter, &result) {
		fmt.Printf("Filename: %s\n", result.Name())
	}
	if iter.Err() != nil {
		panic(iter.Err())
	}
	//

	//http.HandleFunc("/", handleHome)
	/*addr := fmt.Sprintf(":%d", *port)
	if err := http.ListenAndServe(addr, nil); err != nil {
		log.Fatal("Failed to run server: ", err)
	}*/

}
开发者ID:kopparam,项目名称:pullprinting,代码行数:30,代码来源:main.go

示例2: Put

func (s *Storage) Put(filename string, contentType string, body io.Reader, attachment *tenpu.Attachment) (err error) {
	var f *mgo.GridFile
	s.database.DatabaseDo(func(db *mgo.Database) {
		f, err = db.GridFS("fs").Create(filename)
		defer f.Close()
		if err != nil {
			panic(err)
		}
		if attachment.Id != "" {
			f.SetId(bson.ObjectIdHex(attachment.Id))
		}
		f.SetContentType(contentType)
		_, err = io.Copy(f, body)
	})

	if err == io.ErrUnexpectedEOF {
		attId := f.Id().(bson.ObjectId)
		s.Delete(attId.Hex())
		return
	}

	if attachment.Id == "" {
		attachment.Id = f.Id().(bson.ObjectId).Hex()
		attachment.ContentLength = f.Size()
		attachment.ContentType = f.ContentType()
		attachment.Filename = f.Name()
		attachment.MD5 = f.MD5()
		if attachment.IsImage() {
			s.database.DatabaseDo(func(db *mgo.Database) {
				f, err := db.GridFS("fs").OpenId(bson.ObjectIdHex(attachment.Id))
				if err == nil {
					config, _, err := image.DecodeConfig(f)
					f.Close()
					if err == nil {
						attachment.Width = config.Width
						attachment.Height = config.Height
					}
				}
			})
		}
	}

	return
}
开发者ID:jmptrader,项目名称:tenpu,代码行数:44,代码来源:fs.go

示例3: Put

func (s *Storage) Put(filename string, contentType string, body io.Reader, attachment *tenpu.Attachment) (err error) {
	var f *mgo.GridFile

	s.database.DatabaseDo(func(db *mgo.Database) {
		f, err = db.GridFS("fs").Create(filename)
		defer f.Close()
		if err != nil {
			panic(err)
		}
		f.SetContentType(contentType)
		io.Copy(f, body)

	})

	attachment.Id = f.Id().(bson.ObjectId).Hex()
	attachment.ContentLength = f.Size()
	attachment.ContentType = f.ContentType()
	attachment.Filename = f.Name()
	attachment.MD5 = f.MD5()
	return
}
开发者ID:athom,项目名称:tenpu,代码行数:21,代码来源:fs.go

示例4: TestGridFSOpenNext

func (s *S) TestGridFSOpenNext(c *C) {
	session, err := mgo.Dial("localhost:40011")
	c.Assert(err, IsNil)
	defer session.Close()

	db := session.DB("mydb")

	gfs := db.GridFS("fs")

	file, err := gfs.Create("myfile1.txt")
	c.Assert(err, IsNil)
	file.Write([]byte{'1'})
	file.Close()

	file, err = gfs.Create("myfile2.txt")
	c.Assert(err, IsNil)
	file.Write([]byte{'2'})
	file.Close()

	var f *mgo.GridFile
	var b [1]byte

	iter := gfs.Find(nil).Sort("-filename").Iter()

	ok := gfs.OpenNext(iter, &f)
	c.Assert(ok, Equals, true)
	c.Check(f.Name(), Equals, "myfile2.txt")

	_, err = f.Read(b[:])
	c.Assert(err, IsNil)
	c.Assert(string(b[:]), Equals, "2")

	ok = gfs.OpenNext(iter, &f)
	c.Assert(ok, Equals, true)
	c.Check(f.Name(), Equals, "myfile1.txt")

	_, err = f.Read(b[:])
	c.Assert(err, IsNil)
	c.Assert(string(b[:]), Equals, "1")

	ok = gfs.OpenNext(iter, &f)
	c.Assert(ok, Equals, false)
	c.Assert(iter.Close(), IsNil)
	c.Assert(f, IsNil)

	// Do it again with a more restrictive query to make sure
	// it's actually taken into account.
	iter = gfs.Find(bson.M{"filename": "myfile1.txt"}).Iter()

	ok = gfs.OpenNext(iter, &f)
	c.Assert(ok, Equals, true)
	c.Check(f.Name(), Equals, "myfile1.txt")

	ok = gfs.OpenNext(iter, &f)
	c.Assert(ok, Equals, false)
	c.Assert(iter.Close(), IsNil)
	c.Assert(f, IsNil)
}
开发者ID:davidsoloman,项目名称:beats,代码行数:58,代码来源:gridfs_test.go

示例5: FindAllFiles

// 查找文件
func FindAllFiles() {
	gfs := db.GridFS("fs")
	iter := gfs.Find(nil).Iter()
	var f *mgo.GridFile
	for gfs.OpenNext(iter, &f) {
		fmt.Printf("Filename: %s, %v\n", f.Name(), f.Id())
		b := make([]byte, 512)
		w, err := os.Create("upload/" + f.Name())
		if err != nil {
			continue
		}
		for {
			n, _ := f.Read(b)
			if n == 0 {
				break
			}
			w.Write(b[0:n])
		}
		defer w.Close()
	}
	if iter.Err() != nil {
		panic(iter.Err())
	}
}
开发者ID:hyndio,项目名称:hyd.me,代码行数:25,代码来源:file.go

示例6: Cleanup

func (s *mongodbStorage) Cleanup(latest int) error {
	pids := s.getAllProblemIds()
	for _, v := range pids {
		s.doCleanup(v, latest)
	}

	pids = s.getAllGridPrefixes()
	iter := s.GridFS.Find(nil).Sort("filename").Iter()
	var f *mgo.GridFile
	for s.GridFS.OpenNext(iter, &f) {
		if !strings.HasPrefix(f.Name(), "problem/") {
			continue
		}
		if !hasAnyPrefix(f.Name(), pids) {
			fmt.Printf("Remove: %s\n", f.Name())
			s.GridFS.RemoveId(f.Id())
		}
	}
	return nil
}
开发者ID:petemoore,项目名称:runlib,代码行数:20,代码来源:mongodb.go


注:本文中的labix/org/v2/mgo.GridFile.Name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。