-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from kube-tarian/use-git-default-apps
use default applist from template repo
- Loading branch information
Showing
13 changed files
with
180 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package fileutil | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func CreateFolderIfNotExist(folderPath string) error { | ||
if _, err := os.Stat(folderPath); os.IsNotExist(err) { | ||
err := os.MkdirAll(folderPath, 0755) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func SyncFiles(sourceFolder, destinationFolder string) error { | ||
files, err := os.ReadDir(sourceFolder) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, file := range files { | ||
sourceFilePath := filepath.Join(sourceFolder, file.Name()) | ||
destinationFilePath := filepath.Join(destinationFolder, file.Name()) | ||
|
||
if _, err := os.Stat(destinationFilePath); os.IsNotExist(err) { | ||
if err := copyFile(sourceFilePath, destinationFilePath); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func copyFile(src, dst string) error { | ||
srcFile, err := os.Open(src) | ||
if err != nil { | ||
return err | ||
} | ||
defer srcFile.Close() | ||
|
||
dstFile, err := os.Create(dst) | ||
if err != nil { | ||
return err | ||
} | ||
defer dstFile.Close() | ||
|
||
_, err = io.Copy(dstFile, srcFile) | ||
return err | ||
} | ||
|
||
func applyTemplate(templateString string, data map[string]string) (string, error) { | ||
tmpl, err := template.New("local").Parse(templateString) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
var outputBuffer bytes.Buffer | ||
if err := tmpl.Execute(&outputBuffer, data); err != nil { | ||
return "", err | ||
} | ||
|
||
return outputBuffer.String(), nil | ||
} | ||
|
||
func UpdateFilesInFolderWithTempaltes(folderPath string, data map[string]string) error { | ||
files, err := os.ReadDir(folderPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, file := range files { | ||
filePath := filepath.Join(folderPath, file.Name()) | ||
|
||
content, err := os.ReadFile(filePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
newContent, err := applyTemplate(string(content), data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := os.WriteFile(filePath, []byte(newContent), os.ModePerm); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.