Skip to content

Commit ce84355

Browse files
committed
added custom route support and go mod tidy
1 parent ff31611 commit ce84355

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

api/endpoints/custom_route.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package endpoints
2+
3+
import "strings"
4+
5+
// CustomRoute is APIRoute but custom for you
6+
type CustomRoute struct {
7+
APIRoute
8+
}
9+
10+
// Compile returns a CompiledAPIRoute
11+
func (r CustomRoute) Compile(args ...interface{}) CompiledAPIRoute {
12+
return CompiledAPIRoute{
13+
CompiledRoute: r.Route.Compile(args...),
14+
method: r.method,
15+
}
16+
}
17+
18+
// NewCustomRoute generates a new custom route struct
19+
func NewCustomRoute(method Method, url string) APIRoute {
20+
urls := strings.SplitN(url, "/", 2)
21+
return APIRoute{
22+
Route: Route{
23+
baseRoute: urls[0],
24+
route: urls[1],
25+
paramCount: countParams(url),
26+
},
27+
method: method,
28+
}
29+
}

go.sum

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
55
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
66
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
77
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
8-
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
9-
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
108
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
119
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12-
github.com/sirupsen/logrus v1.8.0 h1:nfhvjKcUMhBMVqbKHJlk5RPrrfYr/NMo3692g0dwfWU=
13-
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A=
10+
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
1411
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
1512
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1613
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=

0 commit comments

Comments
 (0)