Skip to content

Commit

Permalink
feat: Add new ReadingClient API to service and context (#1482)
Browse files Browse the repository at this point in the history
* feat: Add new ReadingClient API to service and context

closes #1476

Signed-off-by: Leonard Goodell <leonard.goodell@intel.com>
  • Loading branch information
Lenny Goodell authored Sep 20, 2023
1 parent 12e75c5 commit 94620e0
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 23 deletions.
12 changes: 6 additions & 6 deletions app-service-template/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ replace github.com/edgexfoundry/app-functions-sdk-go/v3 => ../

require (
github.com/edgexfoundry/app-functions-sdk-go/v3 v3.0.0
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.12
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.15
github.com/google/uuid v1.3.1
github.com/labstack/echo/v4 v4.11.1
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
Expand All @@ -26,10 +26,10 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/diegoholiveira/jsonlogic/v3 v3.3.0 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.3 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.36 // indirect
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.5 // indirect
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.20 // indirect
github.com/edgexfoundry/go-mod-registry/v3 v3.1.0-dev.5 // indirect
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.40 // indirect
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.6 // indirect
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.21 // indirect
github.com/edgexfoundry/go-mod-registry/v3 v3.1.0-dev.6 // indirect
github.com/edgexfoundry/go-mod-secrets/v3 v3.1.0-dev.6 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fxamacker/cbor/v2 v2.5.0 // indirect
Expand All @@ -39,7 +39,7 @@ require (
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.1 // indirect
github.com/go-playground/validator/v10 v10.15.4 // indirect
github.com/go-redis/redis/v7 v7.3.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.5.2 // indirect
Expand Down
24 changes: 12 additions & 12 deletions app-service-template/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ github.com/diegoholiveira/jsonlogic/v3 v3.3.0 h1:XdIxQ+ICFcQB9tVf46cmiCkc5K9MN8S
github.com/diegoholiveira/jsonlogic/v3 v3.3.0/go.mod h1:9oE8z9G+0OMxOoLHF3fhek3KuqD5CBqM0B6XFL08MSg=
github.com/eclipse/paho.mqtt.golang v1.4.3 h1:2kwcUGn8seMUfWndX0hGbvH8r7crgcJguQNCyp70xik=
github.com/eclipse/paho.mqtt.golang v1.4.3/go.mod h1:CSYvoAlsMkhYOXh/oKyxa8EcBci6dVkLCbo5tTC1RIE=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.36 h1:zCdZFPSArKhTKGHWDpDPzLLRIpDfTPA1N3NsE/gjKTU=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.36/go.mod h1:k/dJYGezHt13V2IUvuX9uubgsz+zyFITLQ/3Hs+rs+w=
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.5 h1:wTs2qOG/RHeizCHcPp8KOQcSzGrvNOhVQnK+JdAHJNs=
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.5/go.mod h1:mZyBGQ7eX+K63b46/K/OdiWSHtYbl/TK2GTfc0eOM6Q=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.12 h1:LtfT+2/GdNIEXNVIRppHcEIL7rwXfpStso1XIXuSqlI=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.12/go.mod h1:MztlrH+8hPRX6XNZrbdvbV0RNgkoAN1etcvAtgSHeuQ=
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.20 h1:iKhaDrfN0plO95MjPmrOEhfiUrE9gMD9Os7odtOrM10=
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.20/go.mod h1:cD3WRffguDrR/G7dIyzYewfoOk44VlJfGSkgbuUzvYM=
github.com/edgexfoundry/go-mod-registry/v3 v3.1.0-dev.5 h1:Xu1Jxk8gjMGMROqOf2C5pLY6lx1nWNYSDife2d623UE=
github.com/edgexfoundry/go-mod-registry/v3 v3.1.0-dev.5/go.mod h1:4kYwOIuu5SPx5g9ayQXSSpE3m4aEB58x0iXS+m6MnzA=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.40 h1:EPERY7NeYvHAgv/M302kb13qXAtsIV4fjJzUjiARHR0=
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.1.0-dev.40/go.mod h1:/QPYSj3l+BhaBTC2qvnhf8jqKlXfMwWPBuKD5+RpTPQ=
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.6 h1:TW6IrTV5DuWMM2J0Y8gBpi4iSc2dHZiZuo4WEulgYwY=
github.com/edgexfoundry/go-mod-configuration/v3 v3.1.0-dev.6/go.mod h1:5knpeLSwjXrptQy2FgLN/lWrBQxcnRBYz1CXxupTN18=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.15 h1:hqsrrSwouLoA9zmvwlgb/h6AB1tIXx3u6WFRFTwC8GA=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.1.0-dev.15/go.mod h1:EEqaNIvDs3c0KWtcbAF0ynrKWQb3ifocGW6xBzJTvaM=
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.21 h1:RnABQFBuoUogQibrWpwGTX8Ws+jbrcFyMb00ZkHRkcw=
github.com/edgexfoundry/go-mod-messaging/v3 v3.1.0-dev.21/go.mod h1:Br4En+hE/pDMHyqifAOt6EJ/QROLMGIBx+cPoS2cqns=
github.com/edgexfoundry/go-mod-registry/v3 v3.1.0-dev.6 h1:xzXLE902+Xre1mV8VLImJ1LTI7FKRv7sHpleP1pW/PQ=
github.com/edgexfoundry/go-mod-registry/v3 v3.1.0-dev.6/go.mod h1:F1ctOQrRKrD/aZDzbUhjuE9fJGCRP7IVAJ5kaKocXy4=
github.com/edgexfoundry/go-mod-secrets/v3 v3.1.0-dev.6 h1:1mmrSNG7bsOhlSqC1F9L6eZwCirDPzzreivPOkp06i4=
github.com/edgexfoundry/go-mod-secrets/v3 v3.1.0-dev.6/go.mod h1:3STtpFY9MJA3gWkpoFhT3zPhFom1+OXPuklU68i5uDk=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
Expand Down Expand Up @@ -66,8 +66,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.15.1 h1:BSe8uhN+xQ4r5guV/ywQI4gO59C2raYcGffYWZEjZzM=
github.com/go-playground/validator/v10 v10.15.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-playground/validator/v10 v10.15.4 h1:zMXza4EpOdooxPel5xDqXEdXG5r+WggpvnAKMsalBjs=
github.com/go-playground/validator/v10 v10.15.4/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-redis/redis/v7 v7.3.0 h1:3oHqd0W7f/VLKBxeYTEpqdMUsmMectngjM9OtoRoIgg=
github.com/go-redis/redis/v7 v7.3.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
Expand Down
5 changes: 5 additions & 0 deletions internal/app/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,11 @@ func (svc *Service) EventClient() clientInterfaces.EventClient {
return bootstrapContainer.EventClientFrom(svc.dic.Get)
}

// ReadingClient returns the Reading client, which may be nil, from the dependency injection container
func (svc *Service) ReadingClient() clientInterfaces.ReadingClient {
return bootstrapContainer.ReadingClientFrom(svc.dic.Get)
}

// CommandClient returns the Command client, which may be nil, from the dependency injection container
func (svc *Service) CommandClient() clientInterfaces.CommandClient {
return bootstrapContainer.CommandClientFrom(svc.dic.Get)
Expand Down
14 changes: 14 additions & 0 deletions internal/app/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,20 @@ func TestService_EventClient(t *testing.T) {
assert.NotNil(t, actual)
}

func TestService_ReadingClient(t *testing.T) {
actual := target.ReadingClient()
assert.Nil(t, actual)

dic.Update(di.ServiceConstructorMap{
bootstrapContainer.ReadingClientName: func(get di.Get) interface{} {
return clients.NewReadingClient(baseUrl+"59880", nil, false)
},
})

actual = target.ReadingClient()
assert.NotNil(t, actual)
}

func TestService_CommandClient(t *testing.T) {
actual := target.CommandClient()
assert.Nil(t, actual)
Expand Down
7 changes: 6 additions & 1 deletion internal/appfunction/context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2021 Intel Corporation
// Copyright (c) 2023 Intel Corporation
// Copyright (c) 2021 One Track Consulting
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -164,6 +164,11 @@ func (appContext *Context) EventClient() clients.EventClient {
return bootstrapContainer.EventClientFrom(appContext.Dic.Get)
}

// ReadingClient returns the Reading client, which may be nil, from the dependency injection container
func (appContext *Context) ReadingClient() clients.ReadingClient {
return bootstrapContainer.ReadingClientFrom(appContext.Dic.Get)
}

// CommandClient returns the Command client, which may be nil, from the dependency injection container
func (appContext *Context) CommandClient() clients.CommandClient {
return bootstrapContainer.CommandClientFrom(appContext.Dic.Get)
Expand Down
14 changes: 14 additions & 0 deletions internal/appfunction/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ func TestContext_EventClient(t *testing.T) {
assert.NotNil(t, actual)
}

func TestContext_ReadingClient(t *testing.T) {
actual := target.ReadingClient()
assert.Nil(t, actual)

dic.Update(di.ServiceConstructorMap{
bootstrapContainer.ReadingClientName: func(get di.Get) interface{} {
return clients.NewReadingClient(baseUrl+"59880", nil, false)
},
})

actual = target.ReadingClient()
assert.NotNil(t, actual)
}

func TestContext_CommandClient(t *testing.T) {
actual := target.CommandClient()
assert.Nil(t, actual)
Expand Down
5 changes: 4 additions & 1 deletion pkg/interfaces/context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2021 Intel Corporation
// Copyright (c) 2023 Intel Corporation
// Copyright (c) 2021 One Track Consulting
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -69,6 +69,9 @@ type AppFunctionContext interface {
// EventClient returns the Event client. Note if Core Data is not specified in the Clients configuration,
// this will return nil.
EventClient() interfaces.EventClient
// ReadingClient returns the Reading client. Note if Core Data is not specified in the Clients configuration,
// this will return nil.
ReadingClient() interfaces.ReadingClient
// CommandClient returns the Command client. Note if Core Command is not specified in the Clients configuration,
// this will return nil.
CommandClient() interfaces.CommandClient
Expand Down
16 changes: 16 additions & 0 deletions pkg/interfaces/mocks/AppFunctionContext.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion pkg/interfaces/mocks/ApplicationService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions pkg/interfaces/service.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2021 Intel Corporation
// Copyright (c) 2023 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,10 +17,11 @@ package interfaces

import (
"context"
"github.com/labstack/echo/v4"
"net/http"
"time"

"github.com/labstack/echo/v4"

"github.com/edgexfoundry/go-mod-bootstrap/v3/config"
gometrics "github.com/rcrowley/go-metrics"

Expand Down Expand Up @@ -151,6 +152,9 @@ type ApplicationService interface {
// EventClient returns the Event client. Note if Core Data is not specified in the Clients configuration,
// this will return nil.
EventClient() interfaces.EventClient
// ReadingClient returns the Reading client. Note if Core Data is not specified in the Clients configuration,
// this will return nil.
ReadingClient() interfaces.ReadingClient
// CommandClient returns the Command client. Note if Core Command is not specified in the Clients configuration,
// this will return nil.
CommandClient() interfaces.CommandClient
Expand Down

0 comments on commit 94620e0

Please sign in to comment.