-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated code for upload and download
- Loading branch information
1 parent
f4a2e1f
commit 93ab7c4
Showing
3 changed files
with
80 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
// "io" | ||
"os" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/thanos-io/objstore" | ||
"github.com/thanos-io/objstore/client" | ||
"gopkg.in/alecthomas/kingpin.v2" | ||
) | ||
|
||
type Store struct { | ||
TsdbPath string | ||
ObjectKey string | ||
ObjectConfig string | ||
} | ||
|
||
func newstore() *Store { | ||
return &Store{ | ||
TsdbPath: "", | ||
ObjectKey: "", | ||
ObjectConfig: "", | ||
} | ||
} | ||
|
||
func (c *Store) upload(*kingpin.ParseContext) error { | ||
config := c.ObjectConfig | ||
configBytes, err := os.ReadFile(config) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to read config file: %v", err)) | ||
} | ||
commitDir := c.ObjectKey | ||
|
||
bucket, err := client.NewBucket(log.NewNopLogger(), configBytes, "example") | ||
if err != nil { | ||
panic(err) | ||
} | ||
exists, err := bucket.Exists(context.Background(), "example") | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(exists) | ||
|
||
err = objstore.UploadDir(context.Background(), log.NewNopLogger(), bucket, c.TsdbPath, commitDir) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return nil | ||
} | ||
|
||
func (c *Store) download(*kingpin.ParseContext) error { | ||
config := c.ObjectConfig | ||
configBytes, err := os.ReadFile(config) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to read config file: %v", err)) | ||
} | ||
commitDir := c.ObjectKey | ||
bucket, err := client.NewBucket(log.NewNopLogger(), configBytes, "example") | ||
if err != nil { | ||
panic(err) | ||
} | ||
exists, err := bucket.Exists(context.Background(), "example") | ||
if err != nil { | ||
return fmt.Errorf("failed to create bucket: %v", err) | ||
} | ||
fmt.Println(exists) | ||
|
||
err = objstore.DownloadDir(context.Background(), log.NewNopLogger(), bucket, "dir/", commitDir, c.TsdbPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to download directory: %v", err) | ||
} | ||
return nil | ||
} |