diff --git a/src/Guestbooky-backup/cmd/guestbooky-backup/guestbooky-backup.go b/src/Guestbooky-backup/cmd/guestbooky-backup/guestbooky-backup.go new file mode 100644 index 0000000..864b7da --- /dev/null +++ b/src/Guestbooky-backup/cmd/guestbooky-backup/guestbooky-backup.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "os" + + "github.com/cotti/Guestbooky-backup/internal/compactor" +) + +func main() { + err := compactor.Compact(os.Args[1], os.Args[2]) + if err != nil { + fmt.Println("An error occurred while compacting:", err.Error()) + os.Exit(1) + } + os.Exit(0) +} diff --git a/src/Guestbooky-backup/go.mod b/src/Guestbooky-backup/go.mod new file mode 100644 index 0000000..8084f1f --- /dev/null +++ b/src/Guestbooky-backup/go.mod @@ -0,0 +1,3 @@ +module github.com/cotti/Guestbooky-backup + +go 1.23.1 diff --git a/src/Guestbooky-backup/internal/compactor/compactor.go b/src/Guestbooky-backup/internal/compactor/compactor.go new file mode 100644 index 0000000..ed662e7 --- /dev/null +++ b/src/Guestbooky-backup/internal/compactor/compactor.go @@ -0,0 +1,20 @@ +package compactor + +import ( + "errors" + "fmt" + "io/fs" + "os" +) + +func Compact(source, destination string) error { + fmt.Println( + "Compacting", source, "to", destination, + ) + + if _, err := os.Stat(source); errors.Is(err, fs.ErrNotExist) { + return errors.New("source file does not exist") + } + + return nil +}