-
Notifications
You must be signed in to change notification settings - Fork 1
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 #2 from WoodProgrammer/backup-only-mode
Backup only mode
- Loading branch information
Showing
6 changed files
with
112 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"encoding/gob" | ||
"fmt" | ||
"log" | ||
"os" | ||
) | ||
|
||
func dump(filename string, value []HelmRelease) { | ||
file, _ := os.Create(filename) | ||
|
||
enc := gob.NewEncoder(file) | ||
|
||
if err := enc.Encode(value); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func encodedBackup(filename string) []byte { | ||
file, err := os.Open(filename) | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
defer file.Close() | ||
|
||
stats, statsErr := file.Stat() | ||
if statsErr != nil { | ||
fmt.Println(statsErr) | ||
} | ||
|
||
var size int64 = stats.Size() | ||
bytes := make([]byte, size) | ||
|
||
bufr := bufio.NewReader(file) | ||
_, err = bufr.Read(bytes) | ||
|
||
return bytes | ||
} | ||
|
||
func decodeFromBackup(filename string) error { | ||
|
||
data := encodedBackup(filename) | ||
|
||
buf := bytes.NewBuffer(data) | ||
dec := gob.NewDecoder(buf) | ||
|
||
m := []HelmRelease{} | ||
|
||
if err := dec.Decode(&m); err != nil { | ||
log.Fatal(err) | ||
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 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package main | ||
|
||
type HelmRelease struct { | ||
name string | ||
version string | ||
status string | ||
content string | ||
Name string | ||
Version string | ||
Status string | ||
Content string | ||
} |