Compare commits

..

6 Commits
v0.0.4 ... main

Author SHA1 Message Date
7281b9b678 add new option "-v"
All checks were successful
Release Version / build (push) Successful in 5m25s
2024-09-29 13:40:49 +02:00
cdaf3d081e Merge branch 'main' of https://git.fluffy.pw/leafus/s3-client
All checks were successful
Release Version / build (push) Successful in 5m30s
2024-09-29 13:28:08 +02:00
425cf609cc Add -overwrite function 2024-09-29 13:28:06 +02:00
8bde3ccb90 Update .gitea/workflows/build.yaml
All checks were successful
Release Version / build (push) Successful in 5m33s
2024-09-29 13:02:55 +02:00
915245e9da Update .gitea/workflows/build.yaml
All checks were successful
Release Version / build (push) Successful in 8s
2024-09-29 13:01:03 +02:00
20c9b45561 Update .gitea/workflows/build.yaml
All checks were successful
Release Version / build (push) Successful in 7s
2024-09-29 13:00:48 +02:00
4 changed files with 59 additions and 19 deletions

View File

@ -19,60 +19,50 @@ jobs:
go-version: '1.23.1'
- name: Build Go binary for Linux
if: env.main_go_modified == 'true'
run: |
go mod tidy
go build -o s3-client_linux.x86_64
- name: Build Go binary for Linux (x86)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOARCH=386 go build -o s3-client_linux.x86
- name: Build Go binary for Linux (ARM64)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOARCH=arm64 go build -o s3-client_linux.arm64
- name: Build Go binary for Mac OS (x86_64)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOOS=darwin GOARCH=386 go build -o s3-client_darwin.x86_64.app
GOOS=darwin GOARCH=amd64 go build -o s3-client_darwin.x86_64.app
- name: Build Go binary for Mac OS (ARM64)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOOS=darwin GOARCH=arm64 go build -o s3-client_darwin.arm64.app
- name: Build Go binary for Linux (ARMv7)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOARCH=arm go build -o s3-client_linux.armv7
- name: Build Go binary for Linux (RISC-V)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOARCH=riscv64 go build -o s3-client_linux.riscv64
- name: Build Go binary for Windows
if: env.main_go_modified == 'true'
run: |
GOOS=windows GOARCH=amd64 go build -o s3-client_windows.x86_64.exe
- name: Build Go binary for Windows (x86)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOOS=windows GOARCH=386 go build -o s3-client_windows.x86.exe
- name: Build Go binary for Windows (ARM64)
if: env.main_go_modified == 'true'
run: |
go mod tidy
GOOS=windows GOARCH=arm64 go build -o s3-client_windows.arm64.exe
@ -113,7 +103,6 @@ jobs:
- name: Create Release
id: create_release
if: env.main_go_modified == 'true'
uses: actions/create-release@v1
with:
tag_name: ${{ env.new_version }}
@ -129,7 +118,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
- name: Upload Go binaries to release
if: env.main_go_modified == 'true'
uses: softprops/action-gh-release@v1
with:
files: |

10
go.mod
View File

@ -12,11 +12,12 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
@ -28,7 +29,8 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect

12
go.sum
View File

@ -22,8 +22,14 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
@ -31,6 +37,8 @@ github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
@ -66,6 +74,10 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

42
main.go
View File

@ -1,6 +1,7 @@
package main
import (
"bufio"
"flag"
"fmt"
"os"
@ -21,8 +22,21 @@ func main() {
directory := flag.String("directory", "", "Directory in the S3 bucket to upload the file to")
listFiles := flag.Bool("list", false, "List files in the S3 bucket")
deleteFile := flag.String("delete", "", "Path to the file to delete from the S3 bucket")
overwrite := flag.Bool("overwrite", false, "Overwrite the file if it already exists on S3")
verbose := flag.Bool("v", false, "Enable verbose output")
flag.Parse()
if *verbose {
fmt.Println("Debug Information:")
fmt.Printf("File Path: %s\n", *filePath)
fmt.Printf("Force Path Style: %t\n", *forcePathStyle)
fmt.Printf("Config Path: %s\n", *configPath)
fmt.Printf("Directory: %s\n", *directory)
fmt.Printf("List Files: %t\n", *listFiles)
fmt.Printf("Delete File: %s\n", *deleteFile)
fmt.Printf("Overwrite: %t\n", *overwrite)
}
if *configPath == "" {
homeDir, err := os.UserHomeDir()
if err != nil {
@ -113,17 +127,41 @@ func main() {
}
key = filepath.ToSlash(key)
_, err = svc.PutObject(&s3.PutObjectInput{
headObjectInput := &s3.HeadObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
}
_, err = svc.HeadObject(headObjectInput)
if err == nil && !*overwrite {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("The file with the same filename already exists on S3. Do you want to overwrite? [y/n] > ")
response, _ := reader.ReadString('\n')
response = strings.TrimSpace(response)
if strings.ToLower(response) != "y" {
fmt.Println("Upload cancelled.")
os.Exit(0)
}
}
putObjectInput := &s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
Body: file,
})
}
req, _ := svc.PutObjectRequest(putObjectInput)
err = req.Send()
if err != nil {
fmt.Printf("Error uploading file to S3: %s\n", err)
os.Exit(1)
}
if *verbose {
fmt.Printf("Uploaded file: %s\n", *filePath)
fmt.Printf("Endpoint: %s\n", endpoint)
fmt.Printf("HTTP Status Code: %d\n", req.HTTPResponse.StatusCode)
}
fullURL := fmt.Sprintf("%s/%s",
strings.TrimRight(returnurl, "/"),
strings.TrimLeft(key, "/"))