Skip to content

Instantly share code, notes, and snippets.

View flowonyx's full-sized avatar

Joel Williams flowonyx

  • Eshowe, South Africa
View GitHub Profile
@flowonyx
flowonyx / filter.go
Last active May 13, 2016 19:29
Filter a slice based on any field in the element using reflection
import (
"errors"
"reflect"
"github.com/fatih/structs"
)
// Filter takes a slice of structs that have a field with the given fieldName
// and uses that to filter based on value. The parameter, keep, determines
// whether the filter process keeps only the items filtered (true) or removes
// them (false).