-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.gen.go
135 lines (111 loc) · 4.81 KB
/
server.gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Package apiv1 provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.9.0 DO NOT EDIT.
package apiv1
import (
"fmt"
"net/http"
"github.com/deepmap/oapi-codegen/pkg/runtime"
"github.com/labstack/echo/v4"
)
// ServerInterface represents all server handlers.
type ServerInterface interface {
// This handler create new data
// (POST /test)
PostHandler(ctx echo.Context) error
// This handler deletes data for requested ID
// (DELETE /test/{id})
DeleteHandler(ctx echo.Context, id int64, params DeleteHandlerParams) error
// This handler getting data for requested ID
// (GET /test/{id})
GetHandler(ctx echo.Context, id int64) error
// This handler put data to cache for requested ID
// (POST /test/{id})
PostToCacheHandler(ctx echo.Context, id int64) error
}
// ServerInterfaceWrapper converts echo contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
}
// PostHandler converts echo context to params.
func (w *ServerInterfaceWrapper) PostHandler(ctx echo.Context) error {
var err error
// Invoke the callback with all the unmarshalled arguments
err = w.Handler.PostHandler(ctx)
return err
}
// DeleteHandler converts echo context to params.
func (w *ServerInterfaceWrapper) DeleteHandler(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id int64
err = runtime.BindStyledParameterWithLocation("simple", false, "id", runtime.ParamLocationPath, ctx.Param("id"), &id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Parameter object where we will unmarshal all parameters from the context
var params DeleteHandlerParams
// ------------- Optional query parameter "hard" -------------
err = runtime.BindQueryParameter("form", true, false, "hard", ctx.QueryParams(), ¶ms.Hard)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter hard: %s", err))
}
// Invoke the callback with all the unmarshalled arguments
err = w.Handler.DeleteHandler(ctx, id, params)
return err
}
// GetHandler converts echo context to params.
func (w *ServerInterfaceWrapper) GetHandler(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id int64
err = runtime.BindStyledParameterWithLocation("simple", false, "id", runtime.ParamLocationPath, ctx.Param("id"), &id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshalled arguments
err = w.Handler.GetHandler(ctx, id)
return err
}
// PostToCacheHandler converts echo context to params.
func (w *ServerInterfaceWrapper) PostToCacheHandler(ctx echo.Context) error {
var err error
// ------------- Path parameter "id" -------------
var id int64
err = runtime.BindStyledParameterWithLocation("simple", false, "id", runtime.ParamLocationPath, ctx.Param("id"), &id)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
}
// Invoke the callback with all the unmarshalled arguments
err = w.Handler.PostToCacheHandler(ctx, id)
return err
}
// This is a simple interface which specifies echo.Route addition functions which
// are present on both echo.Echo and echo.Group, since we want to allow using
// either of them for path registration
type EchoRouter interface {
CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}
// RegisterHandlers adds each server route to the EchoRouter.
func RegisterHandlers(router EchoRouter, si ServerInterface) {
RegisterHandlersWithBaseURL(router, si, "")
}
// Registers handlers, and prepends BaseURL to the paths, so that the paths
// can be served under a prefix.
func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
wrapper := ServerInterfaceWrapper{
Handler: si,
}
router.POST(baseURL+"/test", wrapper.PostHandler)
router.DELETE(baseURL+"/test/:id", wrapper.DeleteHandler)
router.GET(baseURL+"/test/:id", wrapper.GetHandler)
router.POST(baseURL+"/test/:id", wrapper.PostToCacheHandler)
}