Merge pull request #19 from harshavardhana/pr_out_implement_ls

This commit is contained in:
Harshavardhana
2015-01-20 15:18:15 -08:00
2 changed files with 41 additions and 4 deletions
+36 -2
View File
@@ -17,12 +17,46 @@
package main
import (
"fmt"
"log"
"github.com/codegangsta/cli"
// "github.com/minio-io/mc/pkg/s3"
"github.com/minio-io/mc/pkg/s3"
)
func parseFsList(c *cli.Context) {
func printBuckets(v []*s3.Bucket) {
for _, b := range v {
fmt.Printf("%s %s\n", b.CreationDate, b.Name)
}
}
func printObjects(v []*s3.Item) {
for _, b := range v {
fmt.Printf("%s %s\n", b.LastModified, b.Key)
}
}
func doFsList(c *cli.Context) {
var err error
var auth *s3.Auth
var items []*s3.Item
auth, err = getAWSEnvironment()
if err != nil {
log.Fatal(err)
}
var buckets []*s3.Bucket
s3c := s3.NewS3Client(auth)
switch len(c.Args()) {
case 1:
items, err = s3c.GetBucket(c.Args().Get(0), "", s3.MAX_OBJECT_LIST)
if err != nil {
log.Fatal(err)
}
printObjects(items)
default:
buckets, err = s3c.Buckets()
printBuckets(buckets)
}
}
+5 -2
View File
@@ -157,8 +157,9 @@ func (c *Client) Put(bucket, key string, md5 hash.Hash, size int64, body io.Read
}
type Item struct {
Key string
Size int64
Key string
LastModified string
Size int64
}
type listBucketResults struct {
@@ -329,6 +330,7 @@ func (c *Client) GetPartial(bucket, key string, offset, length int64) (rc io.Rea
}
}
/* Not supporting Delete's
func (c *Client) Delete(bucket, key string) error {
req := newReq(c.keyURL(bucket, key))
req.Method = "DELETE"
@@ -346,6 +348,7 @@ func (c *Client) Delete(bucket, key string) error {
}
return fmt.Errorf("Amazon HTTP error on DELETE: %d", res.StatusCode)
}
*/
func NewAuth(accessKey, secretKey, hostname string) (auth *Auth) {
auth = &Auth{