File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
1010 "strings"
1111 "os"
1212 "bufio"
13+ "encoding/gob"
1314 "time"
1415 "github.com/c-robinson/iplib"
1516)
@@ -384,6 +385,23 @@ func BoolCheck(boolean interface{}) bool {
384385 return false
385386}
386387
388+ // Unified serializer/deserializer for structs - logic is based on whether a .gob file already exists
389+ func Serializer (gobpath string , obj interface {}){
390+ if (Exists (gobpath )){
391+ gobfile , err := os .Open (gobpath )
392+ Check (err )
393+ decoder := gob .NewDecoder (gobfile )
394+ decoder .Decode (obj )
395+ gobfile .Close ()
396+ } else {
397+ gobfile , err := os .Create (gobpath )
398+ Check (err )
399+ encoder := gob .NewEncoder (gobfile )
400+ encoder .Encode (obj )
401+ gobfile .Close ()
402+ }
403+ }
404+
387405// Removes values from generics that do noe pass a truthcheck of f()
388406/*func Decimator[T any](s []T, f func(T) bool) []T {
389407 var r []T
You can’t perform that action at this time.
0 commit comments