Skip to content

Commit

Permalink
added IoTA creation func [NewIoTAgent]
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuedding committed Mar 18, 2024
1 parent 64405e5 commit fccd214
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 11 additions & 1 deletion iota-sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
8 changes: 5 additions & 3 deletions iota-types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit fccd214

Please sign in to comment.