Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/simple-filter-xml/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
var counter int

func main() {

// 1) First thing to do is to create an instance of the EdgeX SDK and initialize it.
edgexSdk := &appsdk.AppFunctionsSDK{ServiceKey: serviceKey}
if err := edgexSdk.Initialize(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.12
require (
bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690
github.com/eclipse/paho.mqtt.golang v1.2.0
github.com/edgexfoundry/go-mod-core-contracts v0.1.0
github.com/edgexfoundry/go-mod-core-contracts v0.1.14
github.com/edgexfoundry/go-mod-messaging v0.1.11
github.com/edgexfoundry/go-mod-registry v0.1.0
github.com/go-stack/stack v1.8.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ const (
ApiPingRoute = "/api/v1/ping"
LogDurationKey = "duration"
)

// SDKVersion indicates the version of the SDK - will be overwritten by build
var SDKVersion string = "0.0.0"

// ApplicationVersion indicates the version of the application itself, not the SDK - will be overwritten by build
var ApplicationVersion string = "0.0.0"
19 changes: 17 additions & 2 deletions internal/webserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
"fmt"
"net/http"

"github.com/edgexfoundry/app-functions-sdk-go/internal/telemetry"

"github.com/edgexfoundry/app-functions-sdk-go/internal"
"github.com/edgexfoundry/app-functions-sdk-go/internal/common"
"github.com/edgexfoundry/app-functions-sdk-go/internal/telemetry"
"github.com/edgexfoundry/go-mod-core-contracts/clients"
"github.com/edgexfoundry/go-mod-core-contracts/clients/logger"

Expand Down Expand Up @@ -68,6 +68,19 @@ func (webserver *WebServer) metricsHandler(writer http.ResponseWriter, _ *http.R

return
}
func (webserver *WebServer) versionHandler(writer http.ResponseWriter, _ *http.Request) {
type Version struct {
Version string `json:"version"`
SDKVersion string `json:"sdk_version"`
}
version := Version{
Version: internal.ApplicationVersion,
SDKVersion: internal.SDKVersion,
}
webserver.encode(version, writer)

return
}

// ConfigureStandardRoutes loads up some default routes
func (webserver *WebServer) ConfigureStandardRoutes() {
Expand All @@ -83,6 +96,8 @@ func (webserver *WebServer) ConfigureStandardRoutes() {
// Metrics
webserver.router.HandleFunc(clients.ApiMetricsRoute, webserver.metricsHandler).Methods(http.MethodGet)

// Version
webserver.router.HandleFunc(clients.ApiVersionRoute, webserver.versionHandler).Methods(http.MethodGet)
}

// SetupTriggerRoute adds a route to handle trigger pipeline from HTTP request
Expand Down
14 changes: 14 additions & 0 deletions internal/webserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,21 @@ func TestConfigureAndPingRoute(t *testing.T) {
assert.Equal(t, "pong", body)

}
func TestConfigureAndVersionRoute(t *testing.T) {

webserver := WebServer{
LoggingClient: logClient,
}
webserver.ConfigureStandardRoutes()

req, _ := http.NewRequest("GET", clients.ApiVersionRoute, nil)
rr := httptest.NewRecorder()
webserver.router.ServeHTTP(rr, req)

body := rr.Body.String()
assert.Equal(t, "{\"version\":\"0.0.0\",\"sdk_version\":\"0.0.0\"}\n", body)

}
func TestConfigureAndConfigRoute(t *testing.T) {

webserver := WebServer{
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MICROSERVICES=examples/simple-filter-xml/simple-filter-xml examples/simple-cbor-

VERSION=$(shell cat ./VERSION)

GOFLAGS=-ldflags "-X app-functions-sdk-go.Version=$(VERSION)"
GOFLAGS=-ldflags "-X github.com/edgexfoundry/app-functions-sdk-go/internal.SDKVersion=$(VERSION) -X github.com/edgexfoundry/app-functions-sdk-go/internal.ApplicationVersion=$(VERSION)"

GIT_SHA=$(shell git rev-parse HEAD)

Expand Down