/
pyo
/
auth
Обзор
Документация
Войти
/
pyo
/
auth
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
main
echo.tmpl
125 строк
3 KB
ilovepitsa
restore from another repo
16 июн 2025, 17:30
16 июн 2025, 17:30
fb9346f
Код
Авторство
О чём код?
type EchoBinder interface { BindPathParams(c echo.Context, i any) error BindQueryParams(c echo.Context, i any) error BindBody(c echo.Context, i any) error BindHeaders(c echo.Context, i any) error } type EchoBindError struct { Path error Query error Header error Body error } func (ebe EchoBindError) IsEmpty() bool { return ebe.Path == nil && ebe.Query == nil && ebe.Header == nil && ebe.Body == nil } func (ebe EchoBindError) Error() string { s := "EchoBindError: " if ebe.Path != nil { s += ebe.Path.Error() + "; " } if ebe.Query != nil { s += ebe.Query.Error() + "; " } if ebe.Header != nil { s += ebe.Header.Error() + "; " } if ebe.Body != nil { s += ebe.Body.Error() + "; " } return s } type EchoRouteInfo struct { OperationID string IsTx bool Bind func(echo.Context, EchoBinder) (any, error) } {{range .}}{{$opid := .OperationId}} {{if (len .PathParams | ne 0 )}} type Echo{{ .OperationId }}PathParams struct { {{- range .PathParams}} {{- .GoName}} {{.TypeDef}} `param:"{{.ParamName}}"` {{end -}} } {{end}} {{if (len .QueryParams | ne 0 )}} type Echo{{ .OperationId }}QueryParams struct { {{- range .QueryParams}} {{- .GoName}} {{.TypeDef}} `query:"{{.ParamName}}"` {{end -}} } {{end}} {{if (len .HeaderParams | ne 0 )}} type Echo{{ .OperationId }}HeaderParams struct { {{- range .HeaderParams}} {{- .GoName}} {{.TypeDef}} `header:"{{.ParamName}}"` {{end -}} } {{end}} type Echo{{ .OperationId }}Params struct { {{- if (len .PathParams | ne 0 ) -}} Path Echo{{ .OperationId }}PathParams {{end -}} {{- if (len .QueryParams | ne 0 ) -}} Query Echo{{ .OperationId }}QueryParams {{end -}} {{- if (len .HeaderParams | ne 0 ) -}} Header Echo{{ .OperationId }}HeaderParams {{end -}} {{- range .Bodies}} {{- if .IsSupported -}} {{- with .TypeDef $opid -}} Body {{.TypeName}} {{end}} {{break}} {{end}} {{end}} } func Echo{{ .OperationId }}Bind(ctx echo.Context, binder EchoBinder) (any, error) { var ( ebe EchoBindError params Echo{{ .OperationId }}Params ) _ = params {{- if (len .PathParams | ne 0 ) }} ebe.Path = binder.BindPathParams(ctx, ¶ms.Path) {{- end }} {{- if (len .QueryParams | ne 0 ) }} ebe.Query = binder.BindQueryParams(ctx, ¶ms.Query) {{- end }} {{- if (len .HeaderParams | ne 0 ) }} ebe.Header = binder.BindHeaders(ctx, ¶ms.Header) {{- end }} {{ range .Bodies}} {{- if .IsSupported -}} {{- with .TypeDef $opid -}} ebe.Body = binder.BindBody(ctx, ¶ms.Body) {{- end -}} {{- break -}} {{- end -}} {{- end }} if !ebe.IsEmpty() { return nil, ebe } return params, nil } {{end}} var EchoRoutes = map[string]EchoRouteInfo{ {{range .}} "{{.Method}};{{.Path | swaggerUriToEchoUri}}": { OperationID: "{{ .OperationId }}", Bind: Echo{{ .OperationId }}Bind, IsTx: {{ if index .Spec.Extensions "x-mws-tx" }}true{{ else }}false{{ end }}, }, {{end}} }