-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.gen.go
521 lines (436 loc) · 19.4 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.13.4 DO NOT EDIT.
package api
import (
"bytes"
"compress/gzip"
"encoding/base64"
"fmt"
"net/http"
"net/url"
"path"
"strings"
"github.com/deepmap/oapi-codegen/pkg/runtime"
"github.com/getkin/kin-openapi/openapi3"
. "github.com/gibalmeida/mailservermngr/internal/adapter/http/api/model"
"github.com/labstack/echo/v4"
)
// ServerInterface represents all server handlers.
type ServerInterface interface {
// Get a list of all email accounts
// (GET /accounts)
GetAccounts(ctx echo.Context) error
// Add a new email account
// (POST /accounts)
CreateAccount(ctx echo.Context) error
// Change account password
// (POST /accounts/changePassword)
UpdateAccountPassword(ctx echo.Context) error
// List of email accounts for a domain
// (GET /accounts/filterByDomain/{domain})
GetAccountsByDomain(ctx echo.Context, domain string) error
// Remove an email account
// (DELETE /accounts/{emailAddress})
DeleteAccount(ctx echo.Context, emailAddress EmailAddress) error
// Get data from an email account
// (GET /accounts/{emailAddress})
GetAccount(ctx echo.Context, emailAddress EmailAddress) error
// Get all email aliases
// (GET /addresses-aliases)
GetAddressAliases(ctx echo.Context) error
// Create an email alias
// (POST /addresses-aliases)
CreateAddressAlias(ctx echo.Context) error
// Get all email aliases
// (GET /addresses-aliases/filterByDomain/{domain})
GetAddressAliasesByDomain(ctx echo.Context, domain string) error
// Deletes an email alias
// (DELETE /addresses-aliases/{alias})
DeleteAddressAlias(ctx echo.Context, alias string) error
// Update an email alias
// (PUT /addresses-aliases/{alias})
UpdateAddressAlias(ctx echo.Context, alias string) error
// Get all email server domains
// (GET /domains)
GetDomains(ctx echo.Context) error
// Add a new domain to the server
// (POST /domains)
CreateDomain(ctx echo.Context) error
// List of domain aliases
// (GET /domains-aliases)
GetDomainsAliases(ctx echo.Context) error
// Adds a new domain alias
// (POST /domains-aliases)
CreateDomainAlias(ctx echo.Context) error
// Get Domains Aliases filtered by Domain
// (GET /domains-aliases/filterByDomain/{domain})
GetDomainsAliasesByDomain(ctx echo.Context, domain string) error
// Deletes a domain alias
// (DELETE /domains-aliases/{domain_alias})
DeleteDomainAlias(ctx echo.Context, domainAlias string) error
// Delete a domain
// (DELETE /domains/{domain})
DeleteDomain(ctx echo.Context, domain string) error
// User Authentication
// (POST /getToken)
GetToken(ctx echo.Context) error
}
// ServerInterfaceWrapper converts echo contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
}
// GetAccounts converts echo context to params.
func (w *ServerInterfaceWrapper) GetAccounts(ctx echo.Context) error {
var err error
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetAccounts(ctx)
return err
}
// CreateAccount converts echo context to params.
func (w *ServerInterfaceWrapper) CreateAccount(ctx echo.Context) error {
var err error
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.CreateAccount(ctx)
return err
}
// UpdateAccountPassword converts echo context to params.
func (w *ServerInterfaceWrapper) UpdateAccountPassword(ctx echo.Context) error {
var err error
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.UpdateAccountPassword(ctx)
return err
}
// GetAccountsByDomain converts echo context to params.
func (w *ServerInterfaceWrapper) GetAccountsByDomain(ctx echo.Context) error {
var err error
// ------------- Path parameter "domain" -------------
var domain string
err = runtime.BindStyledParameterWithLocation("simple", false, "domain", runtime.ParamLocationPath, ctx.Param("domain"), &domain)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter domain: %s", err))
}
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetAccountsByDomain(ctx, domain)
return err
}
// DeleteAccount converts echo context to params.
func (w *ServerInterfaceWrapper) DeleteAccount(ctx echo.Context) error {
var err error
// ------------- Path parameter "emailAddress" -------------
var emailAddress EmailAddress
err = runtime.BindStyledParameterWithLocation("simple", false, "emailAddress", runtime.ParamLocationPath, ctx.Param("emailAddress"), &emailAddress)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter emailAddress: %s", err))
}
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.DeleteAccount(ctx, emailAddress)
return err
}
// GetAccount converts echo context to params.
func (w *ServerInterfaceWrapper) GetAccount(ctx echo.Context) error {
var err error
// ------------- Path parameter "emailAddress" -------------
var emailAddress EmailAddress
err = runtime.BindStyledParameterWithLocation("simple", false, "emailAddress", runtime.ParamLocationPath, ctx.Param("emailAddress"), &emailAddress)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter emailAddress: %s", err))
}
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetAccount(ctx, emailAddress)
return err
}
// GetAddressAliases converts echo context to params.
func (w *ServerInterfaceWrapper) GetAddressAliases(ctx echo.Context) error {
var err error
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetAddressAliases(ctx)
return err
}
// CreateAddressAlias converts echo context to params.
func (w *ServerInterfaceWrapper) CreateAddressAlias(ctx echo.Context) error {
var err error
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.CreateAddressAlias(ctx)
return err
}
// GetAddressAliasesByDomain converts echo context to params.
func (w *ServerInterfaceWrapper) GetAddressAliasesByDomain(ctx echo.Context) error {
var err error
// ------------- Path parameter "domain" -------------
var domain string
err = runtime.BindStyledParameterWithLocation("simple", false, "domain", runtime.ParamLocationPath, ctx.Param("domain"), &domain)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter domain: %s", err))
}
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetAddressAliasesByDomain(ctx, domain)
return err
}
// DeleteAddressAlias converts echo context to params.
func (w *ServerInterfaceWrapper) DeleteAddressAlias(ctx echo.Context) error {
var err error
// ------------- Path parameter "alias" -------------
var alias string
err = runtime.BindStyledParameterWithLocation("simple", false, "alias", runtime.ParamLocationPath, ctx.Param("alias"), &alias)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter alias: %s", err))
}
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.DeleteAddressAlias(ctx, alias)
return err
}
// UpdateAddressAlias converts echo context to params.
func (w *ServerInterfaceWrapper) UpdateAddressAlias(ctx echo.Context) error {
var err error
// ------------- Path parameter "alias" -------------
var alias string
err = runtime.BindStyledParameterWithLocation("simple", false, "alias", runtime.ParamLocationPath, ctx.Param("alias"), &alias)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter alias: %s", err))
}
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.UpdateAddressAlias(ctx, alias)
return err
}
// GetDomains converts echo context to params.
func (w *ServerInterfaceWrapper) GetDomains(ctx echo.Context) error {
var err error
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetDomains(ctx)
return err
}
// CreateDomain converts echo context to params.
func (w *ServerInterfaceWrapper) CreateDomain(ctx echo.Context) error {
var err error
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.CreateDomain(ctx)
return err
}
// GetDomainsAliases converts echo context to params.
func (w *ServerInterfaceWrapper) GetDomainsAliases(ctx echo.Context) error {
var err error
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetDomainsAliases(ctx)
return err
}
// CreateDomainAlias converts echo context to params.
func (w *ServerInterfaceWrapper) CreateDomainAlias(ctx echo.Context) error {
var err error
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.CreateDomainAlias(ctx)
return err
}
// GetDomainsAliasesByDomain converts echo context to params.
func (w *ServerInterfaceWrapper) GetDomainsAliasesByDomain(ctx echo.Context) error {
var err error
// ------------- Path parameter "domain" -------------
var domain string
err = runtime.BindStyledParameterWithLocation("simple", false, "domain", runtime.ParamLocationPath, ctx.Param("domain"), &domain)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter domain: %s", err))
}
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetDomainsAliasesByDomain(ctx, domain)
return err
}
// DeleteDomainAlias converts echo context to params.
func (w *ServerInterfaceWrapper) DeleteDomainAlias(ctx echo.Context) error {
var err error
// ------------- Path parameter "domain_alias" -------------
var domainAlias string
err = runtime.BindStyledParameterWithLocation("simple", false, "domain_alias", runtime.ParamLocationPath, ctx.Param("domain_alias"), &domainAlias)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter domain_alias: %s", err))
}
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.DeleteDomainAlias(ctx, domainAlias)
return err
}
// DeleteDomain converts echo context to params.
func (w *ServerInterfaceWrapper) DeleteDomain(ctx echo.Context) error {
var err error
// ------------- Path parameter "domain" -------------
var domain string
err = runtime.BindStyledParameterWithLocation("simple", false, "domain", runtime.ParamLocationPath, ctx.Param("domain"), &domain)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter domain: %s", err))
}
ctx.Set(BearerAuthScopes, []string{})
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.DeleteDomain(ctx, domain)
return err
}
// GetToken converts echo context to params.
func (w *ServerInterfaceWrapper) GetToken(ctx echo.Context) error {
var err error
// Invoke the callback with all the unmarshaled arguments
err = w.Handler.GetToken(ctx)
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.GET(baseURL+"/accounts", wrapper.GetAccounts)
router.POST(baseURL+"/accounts", wrapper.CreateAccount)
router.POST(baseURL+"/accounts/changePassword", wrapper.UpdateAccountPassword)
router.GET(baseURL+"/accounts/filterByDomain/:domain", wrapper.GetAccountsByDomain)
router.DELETE(baseURL+"/accounts/:emailAddress", wrapper.DeleteAccount)
router.GET(baseURL+"/accounts/:emailAddress", wrapper.GetAccount)
router.GET(baseURL+"/addresses-aliases", wrapper.GetAddressAliases)
router.POST(baseURL+"/addresses-aliases", wrapper.CreateAddressAlias)
router.GET(baseURL+"/addresses-aliases/filterByDomain/:domain", wrapper.GetAddressAliasesByDomain)
router.DELETE(baseURL+"/addresses-aliases/:alias", wrapper.DeleteAddressAlias)
router.PUT(baseURL+"/addresses-aliases/:alias", wrapper.UpdateAddressAlias)
router.GET(baseURL+"/domains", wrapper.GetDomains)
router.POST(baseURL+"/domains", wrapper.CreateDomain)
router.GET(baseURL+"/domains-aliases", wrapper.GetDomainsAliases)
router.POST(baseURL+"/domains-aliases", wrapper.CreateDomainAlias)
router.GET(baseURL+"/domains-aliases/filterByDomain/:domain", wrapper.GetDomainsAliasesByDomain)
router.DELETE(baseURL+"/domains-aliases/:domain_alias", wrapper.DeleteDomainAlias)
router.DELETE(baseURL+"/domains/:domain", wrapper.DeleteDomain)
router.POST(baseURL+"/getToken", wrapper.GetToken)
}
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
"H4sIAAAAAAAC/9xb627juPV/FUL/+aOTRnGySXaB+lM8m2wxg902mM1igMbugJaObe5KpEpS8biBH6lP",
"0RcreJNFiZbtXDzJfJMlXs7lx985PKTvo4TlBaNApYj695FIZpBj/ThIElZSqR4LzgrgkoD+kLIcE6qe",
"4AvOiwyivnvqJSyP4kguCvVSSE7oNFrGEcU5+B2mJBsDl6zdehlHHP5VEg5p1L81XWM36ahqzsa/QyLV",
"4IM05SDEICNGcF9abL6aH6v5JbmoyRwjSU6bL84ufK0KLCVwGvWjf94Oh59Gf357OxzOD4fDo97/jw4v",
"1A/1PDocDnu3g6N/4KN/j+5P4/OlaR3ff2efDrbueWA6vAnZFDt9V0qlUPR8xRpim7FPjv5y+Ll3NDq8",
"eNs7PHiz0QVmprhmyqAbSjnT8ACRcFJIwtSc6i1QSRKsXqCEQ6p+4kwN6HuqwELMGU99nUoBvPoSMIP6",
"3oZX9XaTbrWG1Swh7X6cYToFuyaua5L6OkCOSWYBGQb8470TRxTmdRFyQn8GOlXm/2GTvp6A/kghtS+r",
"te671bxHbIIwRXpMZNGB3kJv2kN1NQ9ark7XD/vf/1CiWGFLbmmo10ETRuSKJRowVa/RhPGVPmaopjoU",
"ZFudwFKstQ95cGcO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xBtiZ9dkfNMFNiNmW8BLaHbIf4+aGrvj9fvr/mT/l0fPSvcffh0g8z9byRVH72nSHCW",
"6c3KjAhtE5LAnwQaXL8P1lPcFfRnqfmVcrbmMF3J7P+FZ3/pX+uKfkDE1iX9ZRydn5wF7+SpRilQsuer",
"JoE9h73lHvVvR14tUABH/v+n6pVA5aXRsjGAf0H+dqSWq+3R/c+sWmFauz8Oc45ocopY3xStNqJ+l0G1",
"1QtXzWs3wp1Mq+vWrS5Hpo+ti7YnbZVMl6Pl/wIAAP//4wQb9fc4AAA=",
}
// GetSwagger returns the content of the embedded swagger specification file
// or error if failed to decode
func decodeSpec() ([]byte, error) {
zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
if err != nil {
return nil, fmt.Errorf("error base64 decoding spec: %w", err)
}
zr, err := gzip.NewReader(bytes.NewReader(zipped))
if err != nil {
return nil, fmt.Errorf("error decompressing spec: %w", err)
}
var buf bytes.Buffer
_, err = buf.ReadFrom(zr)
if err != nil {
return nil, fmt.Errorf("error decompressing spec: %w", err)
}
return buf.Bytes(), nil
}
var rawSpec = decodeSpecCached()
// a naive cached of a decoded swagger spec
func decodeSpecCached() func() ([]byte, error) {
data, err := decodeSpec()
return func() ([]byte, error) {
return data, err
}
}
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
res := make(map[string]func() ([]byte, error))
if len(pathToFile) > 0 {
res[pathToFile] = rawSpec
}
return res
}
// GetSwagger returns the Swagger specification corresponding to the generated code
// in this file. The external references of Swagger specification are resolved.
// The logic of resolving external references is tightly connected to "import-mapping" feature.
// Externally referenced files must be embedded in the corresponding golang packages.
// Urls can be supported but this task was out of the scope.
func GetSwagger() (swagger *openapi3.T, err error) {
resolvePath := PathToRawSpec("")
loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
pathToFile := url.String()
pathToFile = path.Clean(pathToFile)
getSpec, ok := resolvePath[pathToFile]
if !ok {
err1 := fmt.Errorf("path not found: %s", pathToFile)
return nil, err1
}
return getSpec()
}
var specData []byte
specData, err = rawSpec()
if err != nil {
return
}
swagger, err = loader.LoadFromData(specData)
if err != nil {
return
}
return
}