Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SyncFiles ¶
func SyncFiles(repoPath string, mappings []FileSyncMapping) error
SyncFiles synchronizes files from the repository to the local file system based on the provided mappings.
Types ¶
type FileSyncMapping ¶
FileSyncMapping defines a mapping of a file from its source location in the repository to a destination path in the local file system.
type Manager ¶
Manager manages Git operations and file synchronization.
Example:
package main
import (
"fmt" "log" "your-module-name/gitops"
)
func main() {
repoURL := "https://github.com/example-user/example-repo.git"
destination := "./example-repo"
// Initialize GitOpsManager with credentials
manager := gitops.NewGitOpsManager("your-username", "your-personal-access-token")
// Clone a repository
if err := manager.CloneRepository(repoURL, destination); err != nil {
log.Fatalf("Clone failed: %s", err)
}
fmt.Println("Repository cloned successfully.")
// Pull the repository
changes, err := manager.PullRepository(destination)
if err != nil {
log.Fatalf("Pull failed: %s", err)
}
if changes {
fmt.Println("Repository updated.")
} else {
fmt.Println("Repository already up to date.")
}
// Define file synchronization mappings
mappings := []gitops.FileSyncMapping{
{Source: "file1.txt", Destination: "/path/to/local/file1.txt"},
// Add more mappings as needed
}
// Check for changes and synchronize files
changes, err := manager.PullRepository(destination)
if err != nil {
log.Fatalf("Pull failed: %s", err)
}
if changes {
fmt.Println("Changes detected, synchronizing files...")
// Synchronize files
if err := manager.SyncFiles(destination, mappings); err != nil {
log.Fatalf("Sync failed: %s", err)
}
fmt.Println("Files synchronized successfully.")
} else {
fmt.Println("No changes detected.")
}
// Additional operations can be added here as needed
}
func NewGitOpsManager ¶
NewGitOpsManager creates a new instance of GitOpsManager with optional authentication.
func (*Manager) CloneRepository ¶
CloneRepository clones a Git repository into a given directory.
func (*Manager) PullRepository ¶
PullRepository updates the local copy of a Git repository and returns true if there were changes.
Click to show internal directories.
Click to hide internal directories.