Enhancements of REST-based E2 subscription interface
[ric-plt/xapp-frame.git] / pkg / restapi / configure_xapp_framework.go
1 // This file is safe to edit. Once it exists it will not be overwritten
2
3 package restapi
4
5 import (
6         "crypto/tls"
7         "net/http"
8
9         errors "github.com/go-openapi/errors"
10         runtime "github.com/go-openapi/runtime"
11         middleware "github.com/go-openapi/runtime/middleware"
12
13         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations"
14         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/common"
15         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/xapp"
16 )
17
18 //go:generate swagger generate server --target ../../pkg --name XappFramework --spec ../../api/xapp_rest_api.yaml --exclude-main
19
20 func configureFlags(api *operations.XappFrameworkAPI) {
21         // api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... }
22 }
23
24 func configureAPI(api *operations.XappFrameworkAPI) http.Handler {
25         // configure the api here
26         api.ServeError = errors.ServeError
27
28         // Set your custom logger if needed. Default one is log.Printf
29         // Expected interface func(string, ...interface{})
30         //
31         // Example:
32         // api.Logger = log.Printf
33
34         api.JSONConsumer = runtime.JSONConsumer()
35
36         api.JSONProducer = runtime.JSONProducer()
37
38         api.XMLProducer = runtime.XMLProducer()
39
40         if api.CommonSubscribeHandler == nil {
41                 api.CommonSubscribeHandler = common.SubscribeHandlerFunc(func(params common.SubscribeParams) middleware.Responder {
42                         return middleware.NotImplemented("operation common.Subscribe has not yet been implemented")
43                 })
44         }
45         if api.CommonUnsubscribeHandler == nil {
46                 api.CommonUnsubscribeHandler = common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder {
47                         return middleware.NotImplemented("operation common.Unsubscribe has not yet been implemented")
48                 })
49         }
50         if api.CommonGetAllSubscriptionsHandler == nil {
51                 api.CommonGetAllSubscriptionsHandler = common.GetAllSubscriptionsHandlerFunc(func(params common.GetAllSubscriptionsParams) middleware.Responder {
52                         return middleware.NotImplemented("operation common.GetAllSubscriptions has not yet been implemented")
53                 })
54         }
55         if api.XappGetXappConfigListHandler == nil {
56                 api.XappGetXappConfigListHandler = xapp.GetXappConfigListHandlerFunc(func(params xapp.GetXappConfigListParams) middleware.Responder {
57                         return middleware.NotImplemented("operation xapp.GetXappConfigList has not yet been implemented")
58                 })
59         }
60
61         api.ServerShutdown = func() {}
62
63         return setupGlobalMiddleware(api.Serve(setupMiddlewares))
64 }
65
66 // The TLS configuration before HTTPS server starts.
67 func configureTLS(tlsConfig *tls.Config) {
68         // Make all necessary changes to the TLS configuration here.
69 }
70
71 // As soon as server is initialized but not run yet, this function will be called.
72 // If you need to modify a config, store server instance to stop it individually later, this is the place.
73 // This function can be called multiple times, depending on the number of serving schemes.
74 // scheme value will be set accordingly: "http", "https" or "unix"
75 func configureServer(s *http.Server, scheme, addr string) {
76 }
77
78 // The middleware configuration is for the handler executors. These do not apply to the swagger.json document.
79 // The middleware executes after routing but before authentication, binding and validation
80 func setupMiddlewares(handler http.Handler) http.Handler {
81         return handler
82 }
83
84 // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
85 // So this is a good place to plug in a panic handling middleware, logging and metrics
86 func setupGlobalMiddleware(handler http.Handler) http.Handler {
87         return handler
88 }