()
| 369 | } |
| 370 | |
| 371 | func (s *Server) startRESTHandlers() error { |
| 372 | |
| 373 | statusSvr := new(restful.WebService) |
| 374 | statusSvr.Path("/api/v1/status") |
| 375 | statusSvr.Route(statusSvr.GET("/").To(func(request *restful.Request, response *restful.Response) { |
| 376 | response.WriteHeader(http.StatusOK) |
| 377 | }). |
| 378 | Doc("Get the status of the Function Stream"). |
| 379 | Metadata(restfulspec.KeyOpenAPITags, []string{"status"}). |
| 380 | Operation("getStatus")) |
| 381 | |
| 382 | container := restful.NewContainer() |
| 383 | container.Add(s.makeFunctionService()) |
| 384 | container.Add(s.makeTubeService()) |
| 385 | container.Add(s.makeStateService()) |
| 386 | container.Add(s.makeHttpTubeService()) |
| 387 | container.Add(s.makeFunctionStoreService()) |
| 388 | container.Add(statusSvr) |
| 389 | |
| 390 | cors := restful.CrossOriginResourceSharing{ |
| 391 | AllowedHeaders: []string{"Content-Type", "Accept"}, |
| 392 | AllowedMethods: []string{"GET", "POST", "OPTIONS", "PUT", "DELETE"}, |
| 393 | CookiesAllowed: false, |
| 394 | Container: container} |
| 395 | container.Filter(cors.Filter) |
| 396 | container.Filter(container.OPTIONSFilter) |
| 397 | |
| 398 | config := restfulspec.Config{ |
| 399 | WebServices: container.RegisteredWebServices(), |
| 400 | APIPath: "/apidocs", |
| 401 | PostBuildSwaggerObjectHandler: enrichSwaggerObject} |
| 402 | container.Add(restfulspec.NewOpenAPIService(config)) |
| 403 | |
| 404 | httpSvr := &http.Server{ |
| 405 | Handler: container.ServeMux, |
| 406 | } |
| 407 | s.httpSvr.Store(httpSvr) |
| 408 | |
| 409 | if s.options.enableTls { |
| 410 | return httpSvr.ServeTLS(s.options.httpListener, s.options.tlsCertFile, s.options.tlsKeyFile) |
| 411 | } else { |
| 412 | return httpSvr.Serve(s.options.httpListener) |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | func enrichSwaggerObject(swo *spec.Swagger) { |
| 417 | swo.Info = &spec.Info{ |
no test coverage detected