From fccd21479a4836b4d56cb852f61909af5b2a893c Mon Sep 17 00:00:00 2001 From: fbuedding <100070891+fbuedding@users.noreply.github.com> Date: Mon, 18 Mar 2024 09:55:24 +0100 Subject: [PATCH] added IoTA creation func [NewIoTAgent] --- docker-compose.yml | 2 +- iota-sdk.go | 12 +++++++++++- iota-types.go | 8 +++++--- main_test.go | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c0b6c01..0ff00a6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: environment: - APP_ENV=test - TEST_HOST=iot-agent - - LOG_LEVEL=DEBUG + - LOG_LEVEL=FATAL - TZ:"Europe/Berlin" image: fbuedding/fiware-iot-agent-sdk-test ports: diff --git a/iota-sdk.go b/iota-sdk.go index 4c41ad1..aac9091 100644 --- a/iota-sdk.go +++ b/iota-sdk.go @@ -31,6 +31,16 @@ func init() { SetLogLevel(logLvl) } +func NewIoTAgent(host string, port int, timeout_ms int) *IoTA { + iota := IoTA{ + Host: host, + Port: port, + timeout_ms: time.Duration(timeout_ms) * time.Millisecond, + client: &http.Client{Timeout: time.Duration(timeout_ms) * time.Millisecond}, + } + return &iota +} + func SetLogLevel(ll string) { ll = strings.ToLower(ll) switch ll { @@ -96,7 +106,7 @@ func (i IoTA) GetAllServicePathsForService(service string) ([]string, error) { func (i IoTA) Client() *http.Client { if i.client == nil { log.Debug().Msg("Creating http client") - i.client = &http.Client{Timeout: 1 * time.Second} + i.client = &http.Client{Timeout: i.timeout_ms} } return i.client } diff --git a/iota-types.go b/iota-types.go index 4bd2fd5..babf9a0 100644 --- a/iota-types.go +++ b/iota-types.go @@ -2,14 +2,16 @@ package iotagentsdk import ( "net/http" + "time" "github.com/niemeyer/golang/src/pkg/container/vector" ) type IoTA struct { - Host string - Port int - client *http.Client + Host string + Port int + timeout_ms time.Duration + client *http.Client } type FiwareService struct { diff --git a/main_test.go b/main_test.go index 11b5298..645568f 100644 --- a/main_test.go +++ b/main_test.go @@ -34,7 +34,7 @@ func TestMain(m *testing.M) { host = os.Getenv("TEST_HOST") } log.Info().Msgf("Starting test with iot-agent host: %s", host) - iota = i.IoTA{Host: host, Port: 4061} + iota = *i.NewIoTAgent(host, 4061, 1000) fs = i.FiwareService{Service: service, ServicePath: servicePath} d = i.Device{Id: deviceId, EntityName: entityName} sg = i.ConfigGroup{