X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Frestapi%2Fconfigure_xapp_framework.go;fp=pkg%2Frestapi%2Fconfigure_xapp_framework.go;h=d49741872103f9dfbf6fdb5500acee9a33c7c25d;hb=3895a8c8775ef96652e6473414fdd7366c59f404;hp=0000000000000000000000000000000000000000;hpb=5120ec103eead26427b977f4b2456c2ce57b36ac;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/restapi/configure_xapp_framework.go b/pkg/restapi/configure_xapp_framework.go new file mode 100644 index 0000000..d497418 --- /dev/null +++ b/pkg/restapi/configure_xapp_framework.go @@ -0,0 +1,88 @@ +// This file is safe to edit. Once it exists it will not be overwritten + +package restapi + +import ( + "crypto/tls" + "net/http" + + errors "github.com/go-openapi/errors" + runtime "github.com/go-openapi/runtime" + middleware "github.com/go-openapi/runtime/middleware" + + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/common" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/control" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/policy" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/report" +) + +//go:generate swagger generate server --target ../../pkg --name XappFramework --spec ../../api/xapp_rest_api.yaml --exclude-main + +func configureFlags(api *operations.XappFrameworkAPI) { + // api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... } +} + +func configureAPI(api *operations.XappFrameworkAPI) http.Handler { + // configure the api here + api.ServeError = errors.ServeError + + // Set your custom logger if needed. Default one is log.Printf + // Expected interface func(string, ...interface{}) + // + // Example: + // api.Logger = log.Printf + + api.JSONConsumer = runtime.JSONConsumer() + + api.JSONProducer = runtime.JSONProducer() + + if api.CommonUnsubscribeHandler == nil { + api.CommonUnsubscribeHandler = common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder { + return middleware.NotImplemented("operation common.Unsubscribe has not yet been implemented") + }) + } + if api.ControlSubscribeControlHandler == nil { + api.ControlSubscribeControlHandler = control.SubscribeControlHandlerFunc(func(params control.SubscribeControlParams) middleware.Responder { + return middleware.NotImplemented("operation control.SubscribeControl has not yet been implemented") + }) + } + if api.PolicySubscribePolicyHandler == nil { + api.PolicySubscribePolicyHandler = policy.SubscribePolicyHandlerFunc(func(params policy.SubscribePolicyParams) middleware.Responder { + return middleware.NotImplemented("operation policy.SubscribePolicy has not yet been implemented") + }) + } + if api.ReportSubscribeReportHandler == nil { + api.ReportSubscribeReportHandler = report.SubscribeReportHandlerFunc(func(params report.SubscribeReportParams) middleware.Responder { + return middleware.NotImplemented("operation report.SubscribeReport has not yet been implemented") + }) + } + + api.ServerShutdown = func() {} + + return setupGlobalMiddleware(api.Serve(setupMiddlewares)) +} + +// The TLS configuration before HTTPS server starts. +func configureTLS(tlsConfig *tls.Config) { + // Make all necessary changes to the TLS configuration here. +} + +// As soon as server is initialized but not run yet, this function will be called. +// If you need to modify a config, store server instance to stop it individually later, this is the place. +// This function can be called multiple times, depending on the number of serving schemes. +// scheme value will be set accordingly: "http", "https" or "unix" +func configureServer(s *http.Server, scheme, addr string) { +} + +// The middleware configuration is for the handler executors. These do not apply to the swagger.json document. +// The middleware executes after routing but before authentication, binding and validation +func setupMiddlewares(handler http.Handler) http.Handler { + return handler +} + +// The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document. +// So this is a good place to plug in a panic handling middleware, logging and metrics +func setupGlobalMiddleware(handler http.Handler) http.Handler { + return handler +}