podman

Форк
0
62 строки · 1.9 Кб
1
// Copyright 2015 go-swagger maintainers
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//    http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
/*Package middleware provides the library with helper functions for serving swagger APIs.
16

17
Pseudo middleware handler
18

19
  import (
20
  	"net/http"
21

22
  	"github.com/go-openapi/errors"
23
  )
24

25
  func newCompleteMiddleware(ctx *Context) http.Handler {
26
  	return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
27
  		// use context to lookup routes
28
  		if matched, ok := ctx.RouteInfo(r); ok {
29

30
  			if matched.NeedsAuth() {
31
  				if _, err := ctx.Authorize(r, matched); err != nil {
32
  					ctx.Respond(rw, r, matched.Produces, matched, err)
33
  					return
34
  				}
35
  			}
36

37
  			bound, validation := ctx.BindAndValidate(r, matched)
38
  			if validation != nil {
39
  				ctx.Respond(rw, r, matched.Produces, matched, validation)
40
  				return
41
  			}
42

43
  			result, err := matched.Handler.Handle(bound)
44
  			if err != nil {
45
  				ctx.Respond(rw, r, matched.Produces, matched, err)
46
  				return
47
  			}
48

49
  			ctx.Respond(rw, r, matched.Produces, matched, result)
50
  			return
51
  		}
52

53
  		// Not found, check if it exists in the other methods first
54
  		if others := ctx.AllowedMethods(r); len(others) > 0 {
55
  			ctx.Respond(rw, r, ctx.spec.RequiredProduces(), nil, errors.MethodNotAllowed(r.Method, others))
56
  			return
57
  		}
58
  		ctx.Respond(rw, r, ctx.spec.RequiredProduces(), nil, errors.NotFound("path %s was not found", r.URL.Path))
59
  	})
60
  }
61
*/
62
package middleware
63

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.