init: init

This commit is contained in:
2026-03-13 21:56:45 +05:30
commit 3a00b9504d
11 changed files with 245 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
package main
import "fmt"
func _copy(m interface{}) error {
data, ok := m.(map[string]interface{})
if !ok {
return fmt.Errorf("expected map[string]interface{}, got %T", m)
}
fmt.Printf("[COPY] src: %s - dest: %s\n", data["src"], data["dest"])
return nil
}
+13
View File
@@ -0,0 +1,13 @@
package main
import "fmt"
func _move(m interface{}) error {
data, ok := m.(map[string]interface{})
if !ok {
return fmt.Errorf("expected map[string]interface{}, got %T", m)
}
fmt.Printf("[COPY] src: %s - dest: %s\n", data["src"], data["dest"])
return nil
}
+75
View File
@@ -0,0 +1,75 @@
package main
import ("fmt"
"os"
)
func checkFileExists(path string) bool {
_, err := os.Open(path)
if err != nil {
return false
}
return true
}
func createFile(path string) bool {
f, err := os.Create(path)
if err != nil {
return false;
}
defer f.Close()
fmt.Printf("[FILE] created `%s`\n", f.Name())
return true;
}
func removeFile(path string) bool {
err := os.Remove(path)
if err != nil {
// panic(err)
return false;
}
fmt.Printf("[FILE] removed `%s`\n", path)
return true
}
func file(m interface{}) error {
data, ok := m.(map[string]interface{})
if !ok {
return fmt.Errorf("expected map[string]interface{}, got %T", m)
}
shouldPresent := false
if data["state"] == "absent" {
shouldPresent = false
} else if data["state"] == "present"{
shouldPresent = true
}
path := data["path"]
if checkFileExists(path.(string)){
if shouldPresent {
// Skip
fmt.Printf("[FILE] %s exists SKIPPING\n", path)
} else {
// Remove File
removeFile(path.(string))
}
} else {
if shouldPresent {
// Create File
createFile(path.(string))
} else {
// Skip
fmt.Printf("[FILE] %s doesn't exist SKIPPING\n", path)
}
}
return nil
}