func downloadFiles(container string, files []string, c swift.Connection) {
	wpauswiftcommons.CreatePublicContainer(container, c)
	names, err := c.ObjectNames(container, nil)

	if err != nil {
		println(err.Error())
		return
	}

	for _, name := range files {
		if !exists(names, name) {
			println("Object does not exists: " + name)
			continue
		}

		f, err := os.Create(name)
		if err != nil {
			println("Couldn't create file: " + name)
			continue
		}
		defer f.Close()

		_, err = c.ObjectGet(container, name, f, true, nil)
		if err != nil {
			println("Couldn't download file: " + name)
		} else {
			println("Downloaded file: " + name)
		}
	}
}
예제 #2
0
func get_objects(c swift.Connection, container string, prefix string) []string {
	opts := new(swift.ObjectsOpts)
	opts.Prefix = prefix
	names, err := c.ObjectNames(container, opts)
	if err != nil {
		panic(err)
	}
	return names
}
예제 #3
0
func GetHistory(ren render.Render, r *http.Request, cf *swift.Connection) {
	opts := swift.ObjectsOpts{}
	opts.Prefix = "cfpaste-"
	opts.Limit = 10
	objects, err := cf.ObjectNames("go-cfpaste", &opts)
	pastes := make([]string, 10)
	for i := range objects {
		object, headers, err := cf.Object("go-cfpaste", objects[i])
		PanicIf(err)
		log.Println(object.Name)
		pastes = append(pastes, headers["X-Object-Meta-Pasteid"])
	}
	PanicIf(err)
	ren.HTML(200, "history", pastes)
	return
}