Skip to content

Commit

Permalink
refactor to a go modules
Browse files Browse the repository at this point in the history
	* remove glide files
	* update Dockerfile
	* github.com/edgexfoundry/edgex-go/pkg -> github.com/edgexfoundry/go-mod-core-contracts
	* models.DeviceObject -> models.DeviceResource

Signed-off-by: Jacob Blain Christen <[email protected]>
  • Loading branch information
Jacob Blain Christen committed Feb 22, 2019
1 parent ad88414 commit 80cd243
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 268 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignoring the go.sum file. There are checksum issues with
# different versions of Golang. Remove once all Go versions
# are in sync
go.sum
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
vendor/
cmd/device-mqtt
glide.lock
go.sum
28 changes: 14 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
#
# SPDX-License-Identifier: Apache-2.0

FROM golang:1.11.2-alpine3.7 AS builder
ARG ALPINE=golang:1.11-alpine
FROM ${ALPINE} AS builder
ARG ALPINE_PKG_BASE="build-base git openssh-client"
ARG ALPINE_PKG_EXTRA=""

ENV GOPATH=/go
ENV PATH=$GOPATH/bin:$PATH
# Replicate the APK repository override.
# If it is no longer necessary to avoid the CDN mirros we should consider dropping this as it is brittle.
RUN sed -e 's/dl-cdn[.]alpinelinux.org/nl.alpinelinux.org/g' -i~ /etc/apk/repositories
# Install our build time packages.
RUN apk add --no-cache ${ALPINE_PKG_BASE} ${ALPINE_PKG_EXTRA}

RUN echo http://nl.alpinelinux.org/alpine/v3.7/main > /etc/apk/repositories; \
echo http://nl.alpinelinux.org/alpine/v3.7/community >> /etc/apk/repositories

RUN apk update && apk add make && apk add bash
RUN apk add curl && apk add git && apk add openssh && apk add build-base

ADD getglide.sh .
RUN sh ./getglide.sh
# set the working directory
WORKDIR $GOPATH/src/github.com/edgexfoundry/device-mqtt-go

COPY . .

RUN make prepare
RUN make build
# To run tests in the build container:
# docker build --build-arg 'MAKE=build test' .
# This is handy of you do your Docker business on a Mac
ARG MAKE=build
RUN make $MAKE


FROM scratch
Expand Down
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: build test clean prepare update docker

GO=CGO_ENABLED=0 go
GO = CGO_ENABLED=0 GO111MODULE=on go

MICROSERVICES=cmd/device-mqtt

Expand All @@ -16,22 +16,18 @@ GIT_SHA=$(shell git rev-parse HEAD)
GOFLAGS=-ldflags "-X github.com/edgexfoundry/device-mqtt-go.Version=$(VERSION)"

build: $(MICROSERVICES)
go build ./...
$(GO) build ./...

cmd/device-mqtt:
$(GO) build $(GOFLAGS) -o $@ ./cmd

test:
go test ./... -cover
$(GO) test ./... -cover

clean:
rm -f $(MICROSERVICES)

prepare:
glide install

update:
glide update

run:
cd bin && ./edgex-launch.sh
Expand Down
187 changes: 0 additions & 187 deletions getglide.sh

This file was deleted.

13 changes: 0 additions & 13 deletions glide.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/edgexfoundry/device-mqtt-go

require (
github.com/BurntSushi/toml v0.3.1
github.com/eclipse/paho.mqtt.golang v1.1.1
github.com/edgexfoundry/device-sdk-go v0.0.0-20190220033957-9ab31b9a2564
github.com/edgexfoundry/go-mod-core-contracts v0.0.0-20190206111100-148998445693
github.com/go-stack/stack v1.8.0 // indirect
github.com/gorilla/mux v1.7.0 // indirect
github.com/hashicorp/consul v1.4.2 // indirect
github.com/hashicorp/serf v0.8.2 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/pkg/errors v0.8.1 // indirect
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd // indirect
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce
gopkg.in/yaml.v2 v2.2.2 // indirect
)
18 changes: 9 additions & 9 deletions internal/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

MQTT "github.com/eclipse/paho.mqtt.golang"
sdkModel "github.com/edgexfoundry/device-sdk-go/pkg/models"
"github.com/edgexfoundry/edgex-go/pkg/clients/logging"
"github.com/edgexfoundry/edgex-go/pkg/models"
logger "github.com/edgexfoundry/go-mod-core-contracts/clients/logging"
"github.com/edgexfoundry/go-mod-core-contracts/models"
"gopkg.in/mgo.v2/bson"
)

Expand Down Expand Up @@ -132,7 +132,7 @@ func (d *Driver) handleReadCommandRequest(deviceClient MQTT.Client, req sdkModel

var method = "get"
var cmdUuid = bson.NewObjectId().Hex()
var cmd = req.DeviceObject.Name
var cmd = req.DeviceResource.Name

data := make(map[string]interface{})
data["uuid"] = cmdUuid
Expand All @@ -159,13 +159,13 @@ func (d *Driver) handleReadCommandRequest(deviceClient MQTT.Client, req sdkModel

var response map[string]interface{}
json.Unmarshal([]byte(cmdResponse), &response)
reading, ok := response[req.DeviceObject.Name]
reading, ok := response[req.DeviceResource.Name]
if !ok {
err = fmt.Errorf("can not fetch command reading: method=%v cmd=%v", method, cmd)
return result, err
}

result, err = newResult(req.DeviceObject, req.RO, reading)
result, err = newResult(req.DeviceResource, req.RO, reading)
if err != nil {
return result, err
} else {
Expand Down Expand Up @@ -215,14 +215,14 @@ func (d *Driver) handleWriteCommandRequest(deviceClient MQTT.Client, req sdkMode

var method = "set"
var cmdUuid = bson.NewObjectId().Hex()
var cmd = req.DeviceObject.Name
var cmd = req.DeviceResource.Name

data := make(map[string]interface{})
data["uuid"] = cmdUuid
data["method"] = method
data["cmd"] = cmd

commandValue, err := newCommandValue(req.DeviceObject, param)
commandValue, err := newCommandValue(req.DeviceResource, param)
if err != nil {
return err
} else {
Expand Down Expand Up @@ -293,7 +293,7 @@ func createClient(clientID string, uri *url.URL, keepAlive int) (MQTT.Client, er
return client, nil
}

func newResult(deviceObject models.DeviceObject, ro models.ResourceOperation, reading interface{}) (*sdkModel.CommandValue, error) {
func newResult(deviceObject models.DeviceResource, ro models.ResourceOperation, reading interface{}) (*sdkModel.CommandValue, error) {
var result = &sdkModel.CommandValue{}
var err error
var resTime = time.Now().UnixNano() / int64(time.Millisecond)
Expand Down Expand Up @@ -367,7 +367,7 @@ func newResult(deviceObject models.DeviceObject, ro models.ResourceOperation, re
return result, err
}

func newCommandValue(deviceObject models.DeviceObject, param *sdkModel.CommandValue) (interface{}, error) {
func newCommandValue(deviceObject models.DeviceResource, param *sdkModel.CommandValue) (interface{}, error) {
var commandValue interface{}
var err error
switch strings.ToLower(deviceObject.Properties.Value.Type) {
Expand Down
Loading

0 comments on commit 80cd243

Please sign in to comment.