support url params
This commit is contained in:
@@ -2,8 +2,11 @@ package {package}
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
var _ = chi.URLParam
|
||||
|
||||
{foreach $calls as $call}
|
||||
// {name} {call.name} request parameters
|
||||
type {name|lcfirst}{call.name|ucfirst}Request struct {
|
||||
@@ -31,7 +34,9 @@ func ({self} *{name|lcfirst}{call.name|ucfirst}Request) Fill(r *http.Request) er
|
||||
}
|
||||
{foreach $call.parameters as $method => $params}
|
||||
{foreach $params as $param}
|
||||
{if substr($param.type, 0, 2) !== '[]'}
|
||||
{if strtolower($method) === "path"}
|
||||
{self}.{param.name} = chi.URLParam(r, "{param.name}")
|
||||
{elseif substr($param.type, 0, 2) !== '[]'}
|
||||
{self}.{param.name} = {if $param.type !== "string"}{$parsers[$param.type]}({method|strtolower}["{param.name}"]){else}{method|strtolower}["{param.name}"]{/if}{newline}
|
||||
{/if}
|
||||
{/foreach}
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
|
||||
func MountRoutes(r chi.Router) {
|
||||
{foreach $apis as $api}
|
||||
{api.entrypoint|strtolower} := {api.entrypoint|ucfirst}Handlers{}.new()
|
||||
{api.interface|strtolower} := {api.interface|ucfirst}Handlers{}.new()
|
||||
{/foreach}
|
||||
{foreach $apis as $api}
|
||||
r.Route("{api.path}", func(r chi.Router) {
|
||||
{foreach $api.apis as $call}
|
||||
r.{eval echo ucfirst(strtolower($call.method))}("{call.path}", {api.entrypoint|strtolower}.{call.name|ucfirst})
|
||||
r.{eval echo ucfirst(strtolower($call.method))}("{call.path}", {api.interface|strtolower}.{call.name|ucfirst})
|
||||
{/foreach}
|
||||
})
|
||||
{/foreach}
|
||||
|
||||
Reference in New Issue
Block a user