Skip to content

Commit 775592f

Browse files
committedMar 9, 2016
Switch to dimfeld/httptreemux to allow for overlapping path definitions
1 parent 13eb2ec commit 775592f

File tree

9 files changed

+31
-15
lines changed

9 files changed

+31
-15
lines changed
 

‎Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ DEPEND=\
2222
github.com/goadesign/goa-cellar \
2323
github.com/goadesign/middleware \
2424
github.com/golang/lint/golint \
25-
github.com/julienschmidt/httprouter \
25+
github.com/dimfeld/httptreemux \
2626
github.com/manveru/faker \
2727
github.com/on99/gocyclo \
2828
github.com/onsi/ginkgo \

‎design/apidsl/action.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func Action(name string, dsl func()) {
6464

6565
// Routing lists the action route. Each route is defined with a function named after the HTTP method.
6666
// The route function takes the path as argument. Route paths may use wildcards as described in the
67-
// [httprouter](https://godoc.org/github.com/julienschmidt/httprouter) package documentation. These
67+
// [httptreemux](https://godoc.org/github.com/dimfeld/httptreemux) package documentation. These
6868
// wildcards define parameters using the `:name` or `*name` syntax where `:name` matches a path
6969
// segment and `*name` is a catch-all that matches the path until the end.
7070
func Routing(routes ...*design.RouteDefinition) {

‎design/apidsl/test/runner_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ var _ = Resource(resourceName, func() {
2828

2929
var _ = Type(typeName, func() {
3030
Description(typeDescription)
31+
Attribute("bar")
3132
})
3233

3334
var _ = MediaType(mediaTypeIdentifier, func() {
3435
Description(mediaTypeDescription)
36+
Attributes(func() { Attribute("foo") })
37+
View("default", func() { Attribute("foo") })
3538
})
3639

3740
func init() {

‎design/apidsl/test/test_suite_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package test_test
2+
3+
import (
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
6+
7+
"testing"
8+
)
9+
10+
func TestTest(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "Test Suite")
13+
}

‎design/definitions.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"sort"
88
"strings"
99

10+
"github.com/dimfeld/httppath"
1011
"github.com/goadesign/goa/dslengine"
11-
"github.com/julienschmidt/httprouter"
1212
)
1313

1414
type (
@@ -631,7 +631,7 @@ func (r *ResourceDefinition) FullPath() string {
631631
} else {
632632
basePath = Design.BasePath
633633
}
634-
return httprouter.CleanPath(path.Join(basePath, r.BasePath))
634+
return httppath.Clean(path.Join(basePath, r.BasePath))
635635
}
636636

637637
// Parent returns the parent resource if any, nil otherwise.
@@ -1203,13 +1203,13 @@ func (r *RouteDefinition) Params() []string {
12031203
// with the action specific path.
12041204
func (r *RouteDefinition) FullPath() string {
12051205
if r.IsAbsolute() {
1206-
return httprouter.CleanPath(r.Path[1:])
1206+
return httppath.Clean(r.Path[1:])
12071207
}
12081208
var base string
12091209
if r.Parent != nil && r.Parent.Parent != nil {
12101210
base = r.Parent.Parent.FullPath()
12111211
}
1212-
return httprouter.CleanPath(path.Join(base, r.Path))
1212+
return httppath.Clean(path.Join(base, r.Path))
12131213
}
12141214

12151215
// IsAbsolute returns true if the action path should not be concatenated to the resource and API

‎goagen/gen_app/writers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type (
108108

109109
// IsPathParam returns true if the given parameter name corresponds to a path parameter for all
110110
// the context action routes. Such parameter is required but does not need to be validated as
111-
// httprouter takes care of that.
111+
// httptreemux takes care of that.
112112
func (c *ContextTemplateData) IsPathParam(param string) bool {
113113
params := c.Params
114114
pp := false

‎goagen/gen_js/generator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (g *Generator) generateExample(api *design.APIDefinition) error {
181181
}
182182
imports := []*codegen.ImportSpec{
183183
codegen.SimpleImport("net/http"),
184-
codegen.SimpleImport("github.com/julienschmidt/httprouter"),
184+
codegen.SimpleImport("github.com/dimfeld/httptreemux"),
185185
codegen.SimpleImport("github.com/goadesign/goa"),
186186
}
187187
if err := file.WriteHeader(fmt.Sprintf("%s JavaScript Client Example", api.Name), "js", imports); err != nil {

‎goagen/gen_schema/generator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (g *Generator) Generate(api *design.APIDefinition) (_ []string, err error)
7272
return
7373
}
7474
imports := []*codegen.ImportSpec{
75-
codegen.SimpleImport("github.com/julienschmidt/httprouter"),
75+
codegen.SimpleImport("github.com/dimfeld/httptreemux"),
7676
codegen.SimpleImport("github.com/goadesign/goa"),
7777
}
7878
g.genfiles = append(g.genfiles, controllerFile)

‎mux.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"net/http"
55
"net/url"
66

7-
"github.com/julienschmidt/httprouter"
7+
"github.com/dimfeld/httptreemux"
88
)
99

1010
type (
@@ -30,25 +30,25 @@ type (
3030

3131
// mux is the default ServeMux implementation.
3232
mux struct {
33-
router *httprouter.Router
33+
router *httptreemux.TreeMux
3434
handles map[string]MuxHandler
3535
}
3636
)
3737

3838
// NewMux returns a Mux.
3939
func NewMux() ServeMux {
4040
return &mux{
41-
router: httprouter.New(),
41+
router: httptreemux.New(),
4242
handles: make(map[string]MuxHandler),
4343
}
4444
}
4545

4646
// Handle sets the handler for the given verb and path.
4747
func (m *mux) Handle(method, path string, handle MuxHandler) {
48-
hthandle := func(rw http.ResponseWriter, req *http.Request, htparams httprouter.Params) {
48+
hthandle := func(rw http.ResponseWriter, req *http.Request, htparams map[string]string) {
4949
params := req.URL.Query()
50-
for _, p := range htparams {
51-
params.Set(p.Key, p.Value)
50+
for n, p := range htparams {
51+
params.Set(n, p)
5252
}
5353
handle(rw, req, params)
5454
}

0 commit comments

Comments
 (0)
Please sign in to comment.