upd(codegen): enable imports with requests
This commit is contained in:
@@ -6,18 +6,18 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/jmoiron/sqlx/types"
|
||||
"github.com/crusttech/crust/internal/rbac"
|
||||
"mime/multipart"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
{if !empty($imports)}{foreach ($imports as $import)}
|
||||
{import}{EOL}{/foreach}{/if}
|
||||
)
|
||||
|
||||
var _ = chi.URLParam
|
||||
var _ = types.JSONText{}
|
||||
var _ = multipart.FileHeader{}
|
||||
var _ = rbac.Operation{}
|
||||
|
||||
{foreach $calls as $call}
|
||||
// {name} {call.name} request parameters
|
||||
@@ -68,17 +68,17 @@ func ({self} *{name|expose}{call.name|capitalize}) Fill(r *http.Request) (err er
|
||||
{elseif substr($param.type, 0, 2) === '[]' && isset($parsers[$param.type])}
|
||||
{self}.{param.name|expose} = {$parsers[$param.type]}({if $method === "post"}r.Form["{param.name}"]{else}urlQuery["{param.name}"]{/if})
|
||||
{elseif $param.type === "*multipart.FileHeader"}
|
||||
if _, {self}.{param.name|expose}, err = r.FormFile("{$param.name}"); err != nil {
|
||||
return errors.Wrap(err, "error procesing uploaded file")
|
||||
}
|
||||
if _, {self}.{param.name|expose}, err = r.FormFile("{$param.name}"); err != nil {
|
||||
return errors.Wrap(err, "error procesing uploaded file")
|
||||
}
|
||||
{elseif substr($param.type, 0, 2) !== '[]'}
|
||||
if val, ok := {method|strtolower}["{param.name}"]; ok {
|
||||
{if $param.type === "types.JSONText"}
|
||||
if {self}.{param.name|expose}, err = {$parsers[$param.type]}(val); err != nil {
|
||||
return err
|
||||
}
|
||||
if val, ok := {method|strtolower}["{param.name}"]; ok {
|
||||
{if substr($parsers[$param.type], -7) === 'WithErr'}
|
||||
if {self}.{param.name|expose}, err = {$parsers[$param.type]}(val); err != nil {
|
||||
return err
|
||||
}
|
||||
{else}
|
||||
{self}.{param.name|expose} = {if ($param.type !== "string")}{$parsers[$param.type]}(val){else}val{/if}
|
||||
{self}.{param.name|expose} = {if ($param.type !== "string")}{$parsers[$param.type]}(val){else}val{/if}{EOL}
|
||||
{/if}
|
||||
}{/if}
|
||||
{/foreach}
|
||||
|
||||
@@ -5,8 +5,7 @@ package {package}
|
||||
{if !empty($imports)}
|
||||
import (
|
||||
{foreach ($imports as $import)}
|
||||
"{import}"
|
||||
{/foreach}
|
||||
{import}{EOL}{/foreach}
|
||||
)
|
||||
{/if}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user