Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CreateAppByRestAPI = func(serviceAPI string, app *models.App, reqLogger logr.Logger) error { reqLogger.Info("Calling Service to POST app", "serviceAPI", serviceAPI, "App", app) appJSON, err := json.Marshal(app) if err != nil { reqLogger.Error(err, "Error to transform the app object in JSON", "App", app, "Error", err) return err } url := serviceAPI + "/apps" req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(string(appJSON))) req.Header.Set("Content-Type", "application/json") if err != nil { reqLogger.Error(err, "Unable to create POST request", "HTTPMethod", http.MethodPost, "url", url) return err } client := &http.Client{} response, err := client.Do(req) if err != nil || response == nil || 201 != response.StatusCode { if response != nil { reqLogger.Error(err, "Unable to execute GET request", "HTTPMethod", http.MethodGet, "url", url, "response.StatusCode", response.StatusCode) } reqLogger.Error(err, "Unable to execute GET request", "HTTPMethod", http.MethodGet, "url", url) return err } defer response.Body.Close() reqLogger.Info("Successfully created app ...", "App:", app) return nil }
CreateAppByRestAPI create the app object in the service var function declaration to allow for local test mocking
View Source
var DeleteAppFromServiceByRestAPI = func(serviceAPI string, id string, reqLogger logr.Logger) error { reqLogger.Info("Calling REST Service to DELETE app", "serviceAPI", serviceAPI, "App.id", id) url := serviceAPI + "/apps/" + id req, err := http.NewRequest(http.MethodDelete, url, nil) req.Header.Set("Content-Type", "application/json") if err != nil { reqLogger.Error(err, "Unable to create DELETE request", "HTTPMethod", http.MethodDelete, "url", url) return err } client := &http.Client{} response, err := client.Do(req) if err != nil || response == nil || 204 != response.StatusCode { if response != nil { reqLogger.Error(err, "Unable to execute GET request", "HTTPMethod", http.MethodGet, "url", url, "response.StatusCode", response.StatusCode) } reqLogger.Error(err, "Unable to execute GET request", "HTTPMethod", http.MethodGet, "url", url) return err } defer response.Body.Close() reqLogger.Info("Successfully deleted app ...", "App.Id:", id) return nil }
DeleteAppFromServiceByRestAPI delete the app object in the service var function declaration to allow for local test mocking
View Source
var UpdateAppNameByRestAPI = func(serviceAPI string, app *models.App, reqLogger logr.Logger) error { url := serviceAPI + "/apps/" + app.ID appJSON, err := json.Marshal(app) if err != nil { reqLogger.Error(err, "Error to transform the app object in JSON", "AppJSON", appJSON, "App", app, "Error", err) return err } req, err := http.NewRequest(http.MethodPatch, url, strings.NewReader(string(appJSON))) req.Header.Set("Content-Type", "application/json") if err != nil { reqLogger.Error(err, "Unable to create PATCH request to update app name", "HTTPMethod", http.MethodPatch, "url", url) return err } reqLogger.Info("Calling Service to update app name", "serviceAPI", serviceAPI, "App", app) client := &http.Client{} response, err := client.Do(req) if err != nil || response == nil || 204 != response.StatusCode { if response != nil { reqLogger.Error(err, "HTTP StatusCode not expected", "HTTPMethod", http.MethodPatch, "url", url, "response.StatusCode", response.StatusCode) } reqLogger.Error(err, "HTTP StatusCode not expected", "HTTPMethod", http.MethodPatch, "url", url) return err } defer response.Body.Close() reqLogger.Info("Successfully updated app name ...", "App", app) return nil }
UpdateAppNameByRestAPI will update name of the APP in the Service var function declaration to allow for local test mocking
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.