mirror of
https://github.com/thegeeklab/drone-admin.git
synced 2024-11-15 04:00:40 +00:00
37 lines
630 B
Go
37 lines
630 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
|
|
}
|