From ce84355663855304bcda9adc30c8b112ffaa475c Mon Sep 17 00:00:00 2001 From: TopiSenpai Date: Sun, 28 Mar 2021 17:54:05 +0200 Subject: [PATCH] added custom route support and go mod tidy --- api/endpoints/custom_route.go | 29 +++++++++++++++++++++++++++++ go.sum | 5 +---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 api/endpoints/custom_route.go diff --git a/api/endpoints/custom_route.go b/api/endpoints/custom_route.go new file mode 100644 index 00000000..13d6a848 --- /dev/null +++ b/api/endpoints/custom_route.go @@ -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, + } +} diff --git a/go.sum b/go.sum index c9b51b38..42e8223b 100644 --- a/go.sum +++ b/go.sum @@ -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=