summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--cf-r2-awsapi/main.go99
-rw-r--r--cf-r2/download.go66
-rw-r--r--cf-r2/main.go26
-rw-r--r--cf-r2/upload.go58
-rw-r--r--forgeConfig/Makefile4
-rw-r--r--forgeConfig/argv.go3
-rw-r--r--forgeConfig/main.go111
-rw-r--r--going2git/message.go23
9 files changed, 292 insertions, 101 deletions
diff --git a/.gitignore b/.gitignore
index 6c14895..c98bfb7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,3 +15,6 @@ go-clone-test/goclonetest
go-clone-test/goclonetesttest
going2git/going2git
blobby/blobby
+cf-r2/cf-r2
+cf-r2/download
+cf-r2/upload
diff --git a/cf-r2-awsapi/main.go b/cf-r2-awsapi/main.go
new file mode 100644
index 0000000..bea845d
--- /dev/null
+++ b/cf-r2-awsapi/main.go
@@ -0,0 +1,99 @@
+package main
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "os"
+
+ "github.com/aws/aws-sdk-go-v2/aws"
+ "github.com/aws/aws-sdk-go-v2/config"
+ "github.com/aws/aws-sdk-go-v2/service/s3"
+ "github.com/aws/aws-sdk-go-v2/service/s3/types"
+)
+
+const (
+ r2AccountID = "<your-account-id>" // Replace with your Cloudflare R2 Account ID
+ r2AccessKey = "<your-access-key-id>" // Replace with your Access Key ID
+ r2SecretKey = "<your-secret-access-key>" // Replace with your Secret Access Key
+ r2BucketName = "example-bucket" // Replace with your bucket name
+ r2Endpoint = "https://<account-id>.r2.cloudflarestorage.com" // Replace with your endpoint
+)
+
+func main() {
+ // Initialize the AWS Config for R2
+ cfg, err := config.LoadDefaultConfig(context.TODO(),
+ config.WithCredentialsProvider(aws.NewCredentialsCache(
+ aws.NewStaticCredentialsProvider(r2AccessKey, r2SecretKey, ""),
+ )),
+ config.WithEndpointResolver(aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
+ return aws.Endpoint{URL: r2Endpoint}, nil
+ })),
+ )
+ if err != nil {
+ log.Fatalf("Unable to load AWS config: %v", err)
+ }
+
+ // Create the S3 client
+ client := s3.NewFromConfig(cfg)
+
+ // Upload a file
+ err = uploadFile(client, "example.txt", "example.txt")
+ if err != nil {
+ log.Fatalf("Upload failed: %v", err)
+ }
+
+ // Download the file
+ err = downloadFile(client, "example.txt", "downloaded-example.txt")
+ if err != nil {
+ log.Fatalf("Download failed: %v", err)
+ }
+}
+
+// Upload a file to R2
+func uploadFile(client *s3.Client, objectKey, filePath string) error {
+ file, err := os.Open(filePath)
+ if err != nil {
+ return fmt.Errorf("failed to open file %s: %w", filePath, err)
+ }
+ defer file.Close()
+
+ _, err = client.PutObject(context.TODO(), &s3.PutObjectInput{
+ Bucket: aws.String(r2BucketName),
+ Key: aws.String(objectKey),
+ Body: file,
+ ACL: types.ObjectCannedACLPublicRead, // Optional: Make the file public
+ })
+ if err != nil {
+ return fmt.Errorf("failed to upload file to R2: %w", err)
+ }
+
+ fmt.Printf("File %s uploaded to R2 as %s\n", filePath, objectKey)
+ return nil
+}
+
+// Download a file from R2
+func downloadFile(client *s3.Client, objectKey, destPath string) error {
+ resp, err := client.GetObject(context.TODO(), &s3.GetObjectInput{
+ Bucket: aws.String(r2BucketName),
+ Key: aws.String(objectKey),
+ })
+ if err != nil {
+ return fmt.Errorf("failed to download file from R2: %w", err)
+ }
+ defer resp.Body.Close()
+
+ outFile, err := os.Create(destPath)
+ if err != nil {
+ return fmt.Errorf("failed to create file %s: %w", destPath, err)
+ }
+ defer outFile.Close()
+
+ _, err = outFile.ReadFrom(resp.Body)
+ if err != nil {
+ return fmt.Errorf("failed to write file to %s: %w", destPath, err)
+ }
+
+ fmt.Printf("File %s downloaded from R2 and saved as %s\n", objectKey, destPath)
+ return nil
+}
diff --git a/cf-r2/download.go b/cf-r2/download.go
new file mode 100644
index 0000000..b2f4184
--- /dev/null
+++ b/cf-r2/download.go
@@ -0,0 +1,66 @@
+package main
+
+import (
+ "context"
+ "fmt"
+ "log"
+
+ "github.com/minio/minio-go/v7"
+ "github.com/minio/minio-go/v7/pkg/credentials"
+)
+
+const (
+ r2Endpoint = "<account-id>.r2.cloudflarestorage.com" // Replace with your R2 endpoint
+ r2AccessKey = "<your-access-key>" // Replace with your Access Key
+ r2SecretKey = "<your-secret-key>" // Replace with your Secret Key
+ r2BucketName = "example-bucket" // Replace with your bucket name
+)
+
+func main() {
+ // Initialize MinIO client for Cloudflare R2
+ client, err := minio.New(r2Endpoint, &minio.Options{
+ Creds: credentials.NewStaticV4(r2AccessKey, r2SecretKey, ""),
+ Secure: true, // Use HTTPS
+ })
+ if err != nil {
+ log.Fatalf("Failed to initialize client: %v", err)
+ }
+
+ // Upload a file
+ err = uploadFile(client, "example.txt", "example.txt")
+ if err != nil {
+ log.Fatalf("Upload failed: %v", err)
+ }
+
+ // Download the file
+ err = downloadFile(client, "example.txt", "downloaded-example.txt")
+ if err != nil {
+ log.Fatalf("Download failed: %v", err)
+ }
+}
+
+// UploadFile uploads a file to the R2 bucket
+func uploadFile(client *minio.Client, objectName, filePath string) error {
+ ctx := context.Background()
+ _, err := client.FPutObject(ctx, r2BucketName, objectName, filePath, minio.PutObjectOptions{
+ ContentType: "application/octet-stream", // Adjust MIME type if needed
+ })
+ if err != nil {
+ return fmt.Errorf("failed to upload file: %w", err)
+ }
+
+ fmt.Printf("Successfully uploaded %s as %s\n", filePath, objectName)
+ return nil
+}
+
+// DownloadFile downloads a file from the R2 bucket
+func downloadFile(client *minio.Client, objectName, destPath string) error {
+ ctx := context.Background()
+ err := client.FGetObject(ctx, r2BucketName, objectName, destPath, minio.GetObjectOptions{})
+ if err != nil {
+ return fmt.Errorf("failed to download file: %w", err)
+ }
+
+ fmt.Printf("Successfully downloaded %s to %s\n", objectName, destPath)
+ return nil
+}
diff --git a/cf-r2/main.go b/cf-r2/main.go
new file mode 100644
index 0000000..ce3c910
--- /dev/null
+++ b/cf-r2/main.go
@@ -0,0 +1,26 @@
+package main
+
+import (
+ "log"
+
+ "github.com/minio/minio-go/v7"
+ "github.com/minio/minio-go/v7/pkg/credentials"
+)
+
+func main() {
+ endpoint := "play.min.io"
+ accessKeyID := "Q3AM3UQ867SPQQA43P2F"
+ secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
+ useSSL := true
+
+ // Initialize minio client object.
+ minioClient, err := minio.New(endpoint, &minio.Options{
+ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
+ Secure: useSSL,
+ })
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ log.Printf("%#v\n", minioClient) // minioClient is now set up
+}
diff --git a/cf-r2/upload.go b/cf-r2/upload.go
new file mode 100644
index 0000000..399276b
--- /dev/null
+++ b/cf-r2/upload.go
@@ -0,0 +1,58 @@
+// FileUploader.go MinIO example
+package main
+
+import (
+ "context"
+ "log"
+
+ "github.com/minio/minio-go/v7"
+ "github.com/minio/minio-go/v7/pkg/credentials"
+)
+
+func main() {
+ ctx := context.Background()
+ endpoint := "play.min.io"
+ accessKeyID := "Q3AM3UQ867SPQQA43P2F"
+ secretAccessKey := "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
+ useSSL := true
+
+ // Initialize minio client object.
+ minioClient, err := minio.New(endpoint, &minio.Options{
+ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
+ Secure: useSSL,
+ })
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ // Make a new bucket called testbucket.
+ bucketName := "testbucket"
+ location := "us-east-1"
+
+ err = minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location})
+ if err != nil {
+ // Check to see if we already own this bucket (which happens if you run this twice)
+ exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
+ if errBucketExists == nil && exists {
+ log.Printf("We already own %s\n", bucketName)
+ } else {
+ log.Fatalln(err)
+ }
+ } else {
+ log.Printf("Successfully created %s\n", bucketName)
+ }
+
+ // Upload the test file
+ // Change the value of filePath if the file is in another location
+ objectName := "testdata"
+ filePath := "/tmp/testdata"
+ contentType := "application/octet-stream"
+
+ // Upload the test file with FPutObject
+ info, err := minioClient.FPutObject(ctx, bucketName, objectName, filePath, minio.PutObjectOptions{ContentType: contentType})
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ log.Printf("Successfully uploaded %s of size %d\n", objectName, info.Size)
+}
diff --git a/forgeConfig/Makefile b/forgeConfig/Makefile
index 89ab023..b918330 100644
--- a/forgeConfig/Makefile
+++ b/forgeConfig/Makefile
@@ -1,7 +1,7 @@
VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%Y.%m.%d)
-build:
+build: goimports
GO111MODULE=off go build \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
@@ -10,7 +10,7 @@ test2:
FORGE_HOME=/tmp/forge ./forgeConfig
FORGE_HOME=/tmp/forge ./forgeConfig --list
-install:
+install: goimports
GO111MODULE=off go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
diff --git a/forgeConfig/argv.go b/forgeConfig/argv.go
index 635989f..a39509f 100644
--- a/forgeConfig/argv.go
+++ b/forgeConfig/argv.go
@@ -21,6 +21,9 @@ type args struct {
Favorite bool `arg:"--favorite" default:"false" help:"forge will always go-clone or git clone this"`
Private bool `arg:"--private" default:"false" help:"repo can not be published"`
Interesting bool `arg:"--interesting" default:"false" help:"something you decided was cool"`
+ Master string `arg:"--master" help:"the git 'master' or 'main' branch name"`
+ Devel string `arg:"--devel" help:"the git devel branch name"`
+ User string `arg:"--user" help:"the git user branch name"`
}
func (a args) Description() string {
diff --git a/forgeConfig/main.go b/forgeConfig/main.go
index 36b0b71..d6fabba 100644
--- a/forgeConfig/main.go
+++ b/forgeConfig/main.go
@@ -11,26 +11,29 @@ import (
var VERSION string
func main() {
- f := forgepb.Init()
+ var f *forgepb.Forge
+ f = forgepb.Init()
if argv.List {
f.ConfigPrintTable()
- loop := f.Config.SortByGoPath() // get the list of forge configs
- for loop.Scan() {
- r := loop.Next()
- log.Info("repo:", r.GoPath)
- }
+ /*
+ loop := f.Config.SortByGoPath() // get the list of forge configs
+ for loop.Scan() {
+ r := loop.Next()
+ log.Info("repo:", r.GoPath)
+ }
+ */
os.Exit(0)
}
// try to delete, then save config and exit
if argv.Delete {
- if f.Config.DeleteByGoPath(argv.GoPath) {
- log.Info("deleted", argv.GoPath, "did not exist. did nothing")
+ if deleteGoPath(f, argv.GoPath) {
+ log.Info("deleted", argv.GoPath, "ok")
+ f.ConfigSave()
os.Exit(0)
}
- log.Info("deleted", argv.GoPath, "ok")
- f.ConfigSave()
+ log.Info("deleted", argv.GoPath, "did not exist. did nothing")
os.Exit(0)
}
@@ -48,14 +51,18 @@ func main() {
// try to add, then save config and exit
if argv.Add {
log.Info("going to add a new repo", argv.GoPath)
+ deleteGoPath(f, argv.GoPath)
new1 := forgepb.ForgeConfig{
- GoPath: argv.GoPath,
- Writable: argv.Writable,
- ReadOnly: argv.ReadOnly,
- Private: argv.Private,
- Directory: argv.Directory,
- Favorite: argv.Favorite,
- Interesting: argv.Interesting,
+ GoPath: argv.GoPath,
+ Writable: argv.Writable,
+ ReadOnly: argv.ReadOnly,
+ Private: argv.Private,
+ Directory: argv.Directory,
+ Favorite: argv.Favorite,
+ Interesting: argv.Interesting,
+ MasterBranchName: argv.Master,
+ DevelBranchName: argv.Devel,
+ UserBranchName: argv.User,
}
if f.Config.Append(&new1) {
@@ -68,66 +75,18 @@ func main() {
os.Exit(0)
}
- // testMemoryCorruption(f)
- f.ConfigSave()
}
-/*
-// this fucks shit up
-func testMemoryCorruption(all *forgepb.Repos) *forgepb.Repos {
- new1 := new(forgepb.Repo)
- new1.Name = "bash1"
- new1.Version = "5.2.21"
- if all.Append(new1) {
- log.Info("added", new1.Name, "ok")
- } else {
- log.Info("added", new1.Name, "failed")
- }
-
- new1 = new(forgepb.Repo)
- new1.Name = "zookeeper1"
- new1.Debname = "zookeeper-go"
- if all.Append(new1) {
- log.Info("added", new1.Name, "ok")
- } else {
- log.Info("added", new1.Name, "failed")
- }
-
- new1 = new(forgepb.Repo)
- new1.Name = "wit-package"
- new1.Private = true
- if all.Append(new1) {
- log.Info("added", new1.Name, "ok")
- } else {
- log.Info("added", new1.Name, "failed")
- }
-
- new1 = new(forgepb.Repo)
- new1.Name = "networkQuality"
- new1.Debname = "networkquality"
- new1.Readonly = true
- if all.Append(new1) {
- log.Info("added", new1.Name, "ok")
- } else {
- log.Info("added", new1.Name, "failed")
- }
-
- new2 := new(forgepb.Repo)
- new2.Name = "go-clone"
- new2.Version = "0.6.8" // good version of the macos
- if all.Append(new2) {
- log.Info("added", new2.Name, "ok")
- } else {
- log.Info("added", new2.Name, "failed")
- }
-
- if all.Append(new2) {
- log.Info("added", new2.Name, "ok (this is bad)")
- } else {
- log.Info("added", new2.Name, "failed (but ok)")
+func deleteGoPath(f *forgepb.Forge, gopath string) bool {
+ var deleted bool = false
+ for {
+ if f.Config.DeleteByGoPath(gopath) {
+ log.Info("deleted ok", gopath)
+ deleted = true
+ } else {
+ log.Info("did not delete", gopath)
+ break
+ }
}
-
- fmt.Println("packages are:", len(all.Repos))
- return all
+ return deleted
}
-*/
diff --git a/going2git/message.go b/going2git/message.go
deleted file mode 100644
index 817b5f2..0000000
--- a/going2git/message.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package main
-
-import (
- "fmt"
-
- git "go.wit.com/lib/libgit2"
- "go.wit.com/log"
-)
-
-func main() {
- var input git.Trailer
-
- input.Key = "Co-authored-by"
- input.Value = "Alice <[email protected]>"
- /*
- git2go.Trailer
- git2go.Trailer{Key: "Signed-off-by", Value: "Bob <[email protected]>"}}
- */
-
- fmt.Printf("%s", input)
- actual, err := git.MessageTrailers(input.Key)
- log.Info("actual", actual, err)
-}