diff --git a/app-service-template/go.mod b/app-service-template/go.mod index a59a0b78f..4bec3bb7c 100644 --- a/app-service-template/go.mod +++ b/app-service-template/go.mod @@ -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 @@ -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 @@ -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 diff --git a/app-service-template/go.sum b/app-service-template/go.sum index aa2791e97..4801ff591 100644 --- a/app-service-template/go.sum +++ b/app-service-template/go.sum @@ -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= @@ -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= diff --git a/internal/app/service.go b/internal/app/service.go index ea02089f3..7d92bf430 100644 --- a/internal/app/service.go +++ b/internal/app/service.go @@ -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) diff --git a/internal/app/service_test.go b/internal/app/service_test.go index ca6e753a8..75e15f1ab 100644 --- a/internal/app/service_test.go +++ b/internal/app/service_test.go @@ -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) diff --git a/internal/appfunction/context.go b/internal/appfunction/context.go index a64063f08..431d94ef2 100644 --- a/internal/appfunction/context.go +++ b/internal/appfunction/context.go @@ -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"); @@ -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) diff --git a/internal/appfunction/context_test.go b/internal/appfunction/context_test.go index 7c911028c..37ac19f86 100644 --- a/internal/appfunction/context_test.go +++ b/internal/appfunction/context_test.go @@ -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) diff --git a/pkg/interfaces/context.go b/pkg/interfaces/context.go index fc3fbfcc3..f76dda420 100644 --- a/pkg/interfaces/context.go +++ b/pkg/interfaces/context.go @@ -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"); @@ -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 diff --git a/pkg/interfaces/mocks/AppFunctionContext.go b/pkg/interfaces/mocks/AppFunctionContext.go index 95deba495..9e460e983 100644 --- a/pkg/interfaces/mocks/AppFunctionContext.go +++ b/pkg/interfaces/mocks/AppFunctionContext.go @@ -327,6 +327,22 @@ func (_m *AppFunctionContext) PublishWithTopic(topic string, data interface{}, c return r0 } +// ReadingClient provides a mock function with given fields: +func (_m *AppFunctionContext) ReadingClient() clientsinterfaces.ReadingClient { + ret := _m.Called() + + var r0 clientsinterfaces.ReadingClient + if rf, ok := ret.Get(0).(func() clientsinterfaces.ReadingClient); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(clientsinterfaces.ReadingClient) + } + } + + return r0 +} + // RemoveValue provides a mock function with given fields: key func (_m *AppFunctionContext) RemoveValue(key string) { _m.Called(key) diff --git a/pkg/interfaces/mocks/ApplicationService.go b/pkg/interfaces/mocks/ApplicationService.go index fe37fabaa..1626ca612 100644 --- a/pkg/interfaces/mocks/ApplicationService.go +++ b/pkg/interfaces/mocks/ApplicationService.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.27.1. DO NOT EDIT. +// Code generated by mockery v2.20.2. DO NOT EDIT. package mocks @@ -453,6 +453,22 @@ func (_m *ApplicationService) PublishWithTopic(topic string, data interface{}, c return r0 } +// ReadingClient provides a mock function with given fields: +func (_m *ApplicationService) ReadingClient() clientsinterfaces.ReadingClient { + ret := _m.Called() + + var r0 clientsinterfaces.ReadingClient + if rf, ok := ret.Get(0).(func() clientsinterfaces.ReadingClient); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(clientsinterfaces.ReadingClient) + } + } + + return r0 +} + // RegisterCustomStoreFactory provides a mock function with given fields: name, factory func (_m *ApplicationService) RegisterCustomStoreFactory(name string, factory func(config.Database, config.Credentials) (interfaces.StoreClient, error)) error { ret := _m.Called(name, factory) diff --git a/pkg/interfaces/service.go b/pkg/interfaces/service.go index 5e5f93e02..cf9fb7f04 100644 --- a/pkg/interfaces/service.go +++ b/pkg/interfaces/service.go @@ -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. @@ -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" @@ -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