Skip to content

Commit

Permalink
Renamed package
Browse files Browse the repository at this point in the history
  • Loading branch information
rjtokenring committed Sep 17, 2024
1 parent 19f348f commit 690558d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/importer/importer.go → app/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to [email protected].

package importer
package exporter

import (
"context"
Expand All @@ -28,7 +28,7 @@ import (
"github.com/sirupsen/logrus"
)

func StartImport(ctx context.Context, logger *logrus.Entry, key, secret, orgid string, tagsF *string, resolution, timeWindowMinutes int, destinationS3Bucket string, aggregationStat string, compress bool) error {
func StartExporter(ctx context.Context, logger *logrus.Entry, key, secret, orgid string, tagsF *string, resolution, timeWindowMinutes int, destinationS3Bucket string, aggregationStat string, compress bool) error {

// Init client
iotcl, err := iot.NewClient(key, secret, orgid)
Expand Down
14 changes: 11 additions & 3 deletions business/tsextractor/tsextractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package tsextractor

import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -309,7 +310,7 @@ func (a *TsExtractor) populateStringTSDataIntoS3(
if value == nil {
continue
}
samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, interfaceToString(value), ""))
samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, a.interfaceToString(value), ""))
}
}

Expand Down Expand Up @@ -369,7 +370,7 @@ func (a *TsExtractor) populateRawTSDataIntoS3(
if value == nil {
continue
}
samples = append(samples, composeRawRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, interfaceToString(value)))
samples = append(samples, composeRawRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, a.interfaceToString(value)))
}
}

Expand All @@ -384,7 +385,7 @@ func (a *TsExtractor) populateRawTSDataIntoS3(
return nil
}

func interfaceToString(value interface{}) string {
func (a *TsExtractor) interfaceToString(value interface{}) string {
switch v := value.(type) {
case string:
return v
Expand All @@ -394,6 +395,13 @@ func interfaceToString(value interface{}) string {
return strconv.FormatFloat(v, 'f', -1, 64)
case bool:
return strconv.FormatBool(v)
case map[string]any:
encoded, err := json.Marshal(v)
if err != nil {
a.logger.Error("Error encoding map to json: ", err)
return fmt.Sprintf("%v", v)
}
return string(encoded)
default:
return fmt.Sprintf("%v", v)
}
Expand Down
4 changes: 2 additions & 2 deletions lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"errors"
"os"

"github.com/arduino/aws-s3-integration/app/importer"
"github.com/arduino/aws-s3-integration/app/exporter"
"github.com/arduino/aws-s3-integration/internal/parameters"
"github.com/aws/aws-lambda-go/lambda"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -177,7 +177,7 @@ func HandleRequest(ctx context.Context, event *AWSS3ImportTrigger) (*string, err
logger.Infoln("data extraction time windows:", extractionWindowMinutes, "minutes")
logger.Infoln("file compression enabled:", enabledCompression)

err = importer.StartImport(ctx, logger, *apikey, *apiSecret, organizationId, tags, *resolution, *extractionWindowMinutes, *destinationS3Bucket, *aggregationStat, enabledCompression)
err = exporter.StartExporter(ctx, logger, *apikey, *apiSecret, organizationId, tags, *resolution, *extractionWindowMinutes, *destinationS3Bucket, *aggregationStat, enabledCompression)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions resources/test/localexecution.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"os"

"github.com/arduino/aws-s3-integration/app/importer"
"github.com/arduino/aws-s3-integration/app/exporter"
"github.com/arduino/aws-s3-integration/internal/parameters"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -89,7 +89,7 @@ func HandleRequest(ctx context.Context, dev bool) (*string, error) {
logger.Infoln("tags:", *tags)
}

err = importer.StartImport(ctx, logger, *apikey, *apiSecret, organizationId, tags, *resolution, TimeExtractionWindowMinutes, *destinationS3Bucket, "MAX", true)
err = exporter.StartExporter(ctx, logger, *apikey, *apiSecret, organizationId, tags, *resolution, TimeExtractionWindowMinutes, *destinationS3Bucket, "MAX", true)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 690558d

Please sign in to comment.