* Improve API4 initialization

- Refactored openGraphDataCache to be inside app layer.
- Moved the cache instance from global variable to be inside server.
- Moved out the app instantiation from the global commands package
to be instantiated on every call. Only the server instance is passed.
- Moved InitLocal to be called from inside Init.

```release-note
NONE
```

* Remove commented line

```release-note
NONE
```
Этот коммит содержится в:
Agniva De Sarker
2021-10-15 19:57:05 +05:30
коммит произвёл GitHub
родитель 43a99a5783
Коммит c27814393d
18 изменённых файлов: 139 добавлений и 122 удалений

Просмотреть файл

@@ -135,18 +135,18 @@ type Routes struct {
}
type API struct {
app app.AppIface
srv *app.Server
BaseRoutes *Routes
}
func Init(a app.AppIface, root *mux.Router) *API {
func Init(srv *app.Server) *API {
api := &API{
app: a,
srv: srv,
BaseRoutes: &Routes{},
}
api.BaseRoutes.Root = root
api.BaseRoutes.APIRoot = root.PathPrefix(model.APIURLSuffix).Subrouter()
api.BaseRoutes.Root = srv.Router
api.BaseRoutes.APIRoot = srv.Router.PathPrefix(model.APIURLSuffix).Subrouter()
api.BaseRoutes.Users = api.BaseRoutes.APIRoot.PathPrefix("/users").Subrouter()
api.BaseRoutes.User = api.BaseRoutes.APIRoot.PathPrefix("/users/{user_id:[A-Za-z0-9]+}").Subrouter()
@@ -293,19 +293,21 @@ func Init(a app.AppIface, root *mux.Router) *API {
api.InitPermissions()
api.InitExport()
root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))
srv.Router.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))
InitLocal(srv)
return api
}
func InitLocal(a app.AppIface, root *mux.Router) *API {
func InitLocal(srv *app.Server) *API {
api := &API{
app: a,
srv: srv,
BaseRoutes: &Routes{},
}
api.BaseRoutes.Root = root
api.BaseRoutes.APIRoot = root.PathPrefix(model.APIURLSuffix).Subrouter()
api.BaseRoutes.Root = srv.LocalRouter
api.BaseRoutes.APIRoot = srv.LocalRouter.PathPrefix(model.APIURLSuffix).Subrouter()
api.BaseRoutes.Users = api.BaseRoutes.APIRoot.PathPrefix("/users").Subrouter()
api.BaseRoutes.User = api.BaseRoutes.Users.PathPrefix("/{user_id:[A-Za-z0-9]+}").Subrouter()
@@ -386,13 +388,14 @@ func InitLocal(a app.AppIface, root *mux.Router) *API {
api.InitJobLocal()
api.InitSamlLocal()
root.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))
srv.LocalRouter.Handle("/api/v4/{anything:.*}", http.HandlerFunc(api.Handle404))
return api
}
func (api *API) Handle404(w http.ResponseWriter, r *http.Request) {
web.Handle404(api.app, w, r)
app := app.New(app.ServerConnector(api.srv.Channels()))
web.Handle404(app, w, r)
}
var ReturnStatusOK = web.ReturnStatusOK