Skip to content

Instantly share code, notes, and snippets.

Avatar

Joel Williams flowonyx

  • Eshowe, South Africa
View GitHub Profile
@flowonyx
flowonyx / filter.go
Last active May 13, 2016
Filter a slice based on any field in the element using reflection
View filter.go
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).