Skip to content

Commit

Permalink
[126] Refactor to use fewer fmt.Sprintf() calls.
Browse files Browse the repository at this point in the history
Signed-off-by: Dimiter Georgiev <[email protected]>
  • Loading branch information
Dimiter Georgiev committed Nov 25, 2022
1 parent 341b819 commit c469893
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions integration/c2e-setup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func main() {
assertFlag(policyID, "policy id")
}

registryAPI := fmt.Sprintf("%s/v1", strings.TrimSuffix(c2eCfg.DeviceRegistryAPIAddress, "/"))
devicePath := fmt.Sprintf("%s/%s", tenantID, deviceID)
registryAPI := strings.TrimSuffix(c2eCfg.DeviceRegistryAPIAddress, "/") + "/v1"
devicePath := tenantID + "/" + deviceID

resources := make([]*resource, 0, 4)
deviceResource := &resource{url: registryAPI + "/" + devices + devicePath, method: http.MethodPost,
Expand Down Expand Up @@ -363,9 +363,7 @@ func findDeviceRegistryDevicesVia(viaDeviceID string) []string {
return false
}

deviceRegistryAPI := fmt.Sprintf(
"%s/v1/%s%s/", strings.TrimSuffix(c2eCfg.DeviceRegistryAPIAddress, "/"), devices, tenantID)
devicesJSON, err := sendDeviceRegistryRequest(http.MethodGet, deviceRegistryAPI)
devicesJSON, err := sendDeviceRegistryRequest(http.MethodGet, getTenantURL())
if err != nil {
fmt.Println(err)
} else {
Expand Down Expand Up @@ -402,10 +400,9 @@ func deleteDigitalTwinAPIThings(relations []string) {
func deleteDeviceRegistryDevices(relations []string) {
// Delete related Device Registry devices
fmt.Println("deleting automatically created devices in the device registry...")
deviceRegistryAPI := fmt.Sprintf(
"%s/v1/%s%s/", strings.TrimSuffix(c2eCfg.DeviceRegistryAPIAddress, "/"), devices, tenantID)
tenantURL := getTenantURL()
for _, device := range relations {
url := deviceRegistryAPI + device
url := tenantURL + device
if _, err := sendDeviceRegistryRequest(http.MethodDelete, url); err != nil {
fmt.Printf("error deleting device: %v\n", err)
} else {
Expand Down Expand Up @@ -519,3 +516,8 @@ func copyFile(src, dst string) error {
mode := getFileModeOrDefault(dst, configDefaultMode)
return ioutil.WriteFile(dst, data, mode)
}

func getTenantURL() string {
return fmt.Sprintf(
"%s/v1/%s%s/", strings.TrimSuffix(c2eCfg.DeviceRegistryAPIAddress, "/"), devices, tenantID)
}

0 comments on commit c469893

Please sign in to comment.