Skip to content

Commit

Permalink
added custom route support and go mod tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Mar 28, 2021
1 parent ff31611 commit ce84355
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
29 changes: 29 additions & 0 deletions api/endpoints/custom_route.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package endpoints

import "strings"

// CustomRoute is APIRoute but custom for you
type CustomRoute struct {
APIRoute
}

// Compile returns a CompiledAPIRoute
func (r CustomRoute) Compile(args ...interface{}) CompiledAPIRoute {
return CompiledAPIRoute{
CompiledRoute: r.Route.Compile(args...),
method: r.method,
}
}

// NewCustomRoute generates a new custom route struct
func NewCustomRoute(method Method, url string) APIRoute {
urls := strings.SplitN(url, "/", 2)
return APIRoute{
Route: Route{
baseRoute: urls[0],
route: urls[1],
paramCount: countParams(url),
},
method: method,
}
}
5 changes: 1 addition & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g=
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.0 h1:nfhvjKcUMhBMVqbKHJlk5RPrrfYr/NMo3692g0dwfWU=
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
Expand Down

0 comments on commit ce84355

Please sign in to comment.