mirror of
https://github.com/thegeeklab/drone-admin.git
synced 2024-11-24 21:20:42 +00:00
43 lines
636 B
Go
43 lines
636 B
Go
package util
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"os"
|
|
)
|
|
|
|
func Filter[T any](vs []T, f func(T) bool) []T {
|
|
filtered := make([]T, 0)
|
|
|
|
for _, v := range vs {
|
|
if f(v) {
|
|
filtered = append(filtered, v)
|
|
}
|
|
}
|
|
|
|
return filtered
|
|
}
|
|
|
|
func WriteGob(filePath string, object interface{}) error {
|
|
file, err := os.Create(filePath)
|
|
if err == nil {
|
|
encoder := gob.NewEncoder(file)
|
|
err = encoder.Encode(object)
|
|
}
|
|
|
|
file.Close()
|
|
|
|
return err
|
|
}
|
|
|
|
func ReadGob(filePath string, object interface{}) error {
|
|
file, err := os.Open(filePath)
|
|
if err == nil {
|
|
decoder := gob.NewDecoder(file)
|
|
err = decoder.Decode(object)
|
|
}
|
|
|
|
file.Close()
|
|
|
|
return err
|
|
}
|