From b8ae6e364ad97379ee8b1c3a0206e3281f6fe466 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Fri, 6 Dec 2024 18:39:47 -0300 Subject: [PATCH] Starting implementation of the backup service. --- .../guestbooky-backup/guestbooky-backup.go | 17 ++++++++++++++++ src/Guestbooky-backup/go.mod | 3 +++ .../internal/compactor/compactor.go | 20 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/Guestbooky-backup/cmd/guestbooky-backup/guestbooky-backup.go create mode 100644 src/Guestbooky-backup/go.mod create mode 100644 src/Guestbooky-backup/internal/compactor/compactor.go 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 +}