Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2014 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package routes |
| 18 | |
| 19 | import ( |
| 20 | "net/http" |
| 21 | |
| 22 | assetfs "github.com/elazarl/go-bindata-assetfs" |
| 23 | |
| 24 | "k8s.io/apiserver/pkg/server/mux" |
| 25 | "k8s.io/apiserver/pkg/server/routes/data/swagger" |
| 26 | ) |
| 27 | |
| 28 | // SwaggerUI exposes files in third_party/swagger-ui/ under /swagger-ui. |
| 29 | type SwaggerUI struct{} |
| 30 | |
| 31 | // Install adds the SwaggerUI webservice to the given mux. |
| 32 | func (l SwaggerUI) Install(c *mux.PathRecorderMux) { |
| 33 | fileServer := http.FileServer(&assetfs.AssetFS{ |
| 34 | Asset: swagger.Asset, |
| 35 | AssetDir: swagger.AssetDir, |
| 36 | Prefix: "third_party/swagger-ui", |
| 37 | }) |
| 38 | prefix := "/swagger-ui/" |
| 39 | c.HandlePrefix(prefix, http.StripPrefix(prefix, fileServer)) |
| 40 | } |