8000 Invert logic to remove layer of indentation · coder/coder@c15b046 · GitHub
[go: up one dir, main page]

Skip to content

Commit c15b046

Browse files
committed
Invert logic to remove layer of indentation
1 parent 750bec9 commit c15b046

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

nextrouter/nextrouter.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,32 @@ func buildRouter(rtr chi.Router, fileSystem fs.FS, options Options) {
7070
for _, file := range files {
7171
name := file.Name()
7272

73-
// ...if it's a directory, create a sub-route by
74-
// recursively calling `buildRouter`
75-
if file.IsDir() {
76-
sub, err := fs.Sub(fileSystem, name)
77-
if err != nil {
78-
options.Logger.Error(context.Background(), "Unable to call fs.Sub on directory", slog.F("directory_name", name))
79-
continue
80-
}
81-
82-
// In the special case where the folder is dynamic,
83-
// like `[org]`, we can convert to a chi-style dynamic route
84-
// (which uses `{` instead of `[`)
85-
routeName := name
86-
if isDynamicRoute(name) {
87-
routeName = "{dynamic}"
88-
}
89-
90-
options.Logger.Debug(context.Background(), "Adding route", slog.F("name", name), slog.F("routeName", routeName))
91-
rtr.Route("/"+routeName, func(r chi.Router) {
92-
buildRouter(r, sub, options)
93-
})
94-
} else {
95-
// ...otherwise, if it's a file - serve it up!
73+
// If we're working with a file - just serve it up
74+
if !file.IsDir() {
9675
serveFile(rtr, fileSystem, name, options)
76+
continue
77+
}
78+
79+
// ...otherwise, if it's a directory, create a sub-route by
80+
// recursively calling `buildRouter`
81+
sub, err := fs.Sub(fileSystem, name)
82+
if err != nil {
83+
options.Logger.Error(context.Background(), "Unable to call fs.Sub on directory", slog.F("directory_name", name))
84+
continue
85+
}
86+
87+
// In the special case where the folder is dynamic,
88+
// like `[org]`, we can convert to a chi-style dynamic route
89+
// (which uses `{` instead of `[`)
90+
routeName := name
91+
if isDynamicRoute(name) {
92+
routeName = "{dynamic}"
9793
}
94+
95+
options.Logger.Debug(context.Background(), "Adding route", slog.F("name", name), slog.F("routeName", routeName))
96+
rtr.Route("/"+routeName, func(r chi.Router) {
97+
buildRouter(r, sub, options)
98+
})
9899
}
99100
}
100101

0 commit comments

Comments
 (0)
0