-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add support for go1.16's WalkDir
Add support for using the faster WalkDir method when building against go1.16.
- Loading branch information
1 parent
47b7c3d
commit 2e68f77
Showing
4 changed files
with
61 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:build go1.16 | ||
// +build go1.16 | ||
|
||
package sysfont | ||
|
||
import ( | ||
"io/fs" | ||
"path/filepath" | ||
) | ||
|
||
func findFonts(opts *FinderOpts, fn func(filename string) error) { | ||
walker := func(filename string, info fs.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.IsDir() { | ||
return nil | ||
} | ||
|
||
return fn(filename) | ||
} | ||
|
||
// Traverse OS font directories. | ||
for _, dir := range opts.SearchPaths { | ||
if err := filepath.WalkDir(dir, walker); err != nil { | ||
continue | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//go:build !go1.16 | ||
// +build !go1.16 | ||
|
||
package sysfont | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func findFonts(opts *FinderOpts, fn func(filename string) error) { | ||
walker := func(filename string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.IsDir() { | ||
return nil | ||
} | ||
|
||
return fn(filename) | ||
} | ||
|
||
// Traverse OS font directories. | ||
for _, dir := range opts.SearchPaths { | ||
if err := filepath.Walk(dir, walker); err != nil { | ||
continue | ||
} | ||
} | ||
} |