Ejemplo n.º 1
0
// Get a list of all supported image files in a directory
func getImages(imagePath string) []string {
	// Currently only supports .jpg's
	imageTypes := [...]string{".jpg"}
	dir, err := filetree.GetDir(imagePath)
	if err != nil {
		panic(err)
	}
	files, err := dir.GetFilePaths()
	if err != nil {
		panic(err)
	}
	return filterutils.HasSuffix(files, imageTypes[0])

	// XXX Commented code is not a good practice, but this was good learning material
	//allFiles := make([]string,0)
	//for _, imageType := range imageTypes {
	//    filtered := filterutils.HasSuffix(files, imageType)
	//    allFiles = append(
	//        allFiles[:len(allFiles)],
	//        append(
	//            make([]string,0),
	//            filtered[:len(filtered)]...
	//        )...
	//    )
	//}
}
Ejemplo n.º 2
0
func TestHasSuffix(t *testing.T) {
	var (
		a          = []string{"baz", "bar", "chaz", "champ"}
		suf string = "az"
		exp        = []string{"baz", "chaz"}
	)
	ret := filterutils.HasSuffix(a, suf)
	if !reflect.DeepEqual(ret, exp) {
		t.Errorf("Filter test has failed. Expected %s, Actual %s")
	}
}