Skip to content

Commit

Permalink
Filter out empty path components (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
nehzata authored Apr 21, 2023
1 parent e2a0ba3 commit c8cbe20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cmd/happy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,12 @@ func (t *tree) String() string {

func (t *tree) Write(w *codewriter.Writer, earlyExit string, visitor func(w *codewriter.Writer, endpoint endpoint)) {
w.Import("strings")
w.L(`parts := strings.Split(r.URL.Path, "/")`)
w.L(`parts := []string{}`)
w.L(`for i, p := range strings.Split(r.URL.Path, "/") {`)
w.L(` if i == 0 || p != "" {`)
w.L(` parts = append(parts, p)`)
w.L(` }`)
w.L(`}`)
w.L(`var params []string`)
w.L(`_ = params`)
w.L(`switch parts[0] {`)
Expand Down
14 changes: 12 additions & 2 deletions testdata/main_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c8cbe20

Please sign in to comment.