Skip to content

Commit b2cf624

Browse files
committed
refactor project structure by moving non business logic related code to adapters
1 parent 3601b98 commit b2cf624

21 files changed

+37
-27
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

pkg/http/docs/docs.go adapters/http/docs/docs.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
22
// This file was generated by swaggo/swag at
3-
// 2020-02-21 11:58:17.562006 +0300 +03 m=+3.916537146
3+
// 2020-02-21 13:07:52.524624 +0300 +03 m=+3.952617600
44

55
package docs
66

@@ -171,10 +171,7 @@ var doc = `{
171171
"in": "body",
172172
"required": true,
173173
"schema": {
174-
"type": "array",
175-
"items": {
176-
"$ref": "#/definitions/ingestion.DecimalMetricValue"
177-
}
174+
"$ref": "#/definitions/ingestion.DecimalMetricValueList"
178175
}
179176
}
180177
],
@@ -246,6 +243,12 @@ var doc = `{
246243
}
247244
}
248245
},
246+
"ingestion.DecimalMetricValueList": {
247+
"type": "array",
248+
"items": {
249+
"$ref": "#/definitions/ingestion.DecimalMetricValue"
250+
}
251+
},
249252
"registry.Device": {
250253
"type": "object",
251254
"properties": {

pkg/http/docs/swagger.json adapters/http/docs/swagger.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,7 @@
156156
"in": "body",
157157
"required": true,
158158
"schema": {
159-
"type": "array",
160-
"items": {
161-
"$ref": "#/definitions/ingestion.DecimalMetricValue"
162-
}
159+
"$ref": "#/definitions/ingestion.DecimalMetricValueList"
163160
}
164161
}
165162
],
@@ -231,6 +228,12 @@
231228
}
232229
}
233230
},
231+
"ingestion.DecimalMetricValueList": {
232+
"type": "array",
233+
"items": {
234+
"$ref": "#/definitions/ingestion.DecimalMetricValue"
235+
}
236+
},
234237
"registry.Device": {
235238
"type": "object",
236239
"properties": {

pkg/http/docs/swagger.yaml adapters/http/docs/swagger.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ definitions:
2525
value:
2626
type: number
2727
type: object
28+
ingestion.DecimalMetricValueList:
29+
items:
30+
$ref: '#/definitions/ingestion.DecimalMetricValue'
31+
type: array
2832
registry.Device:
2933
properties:
3034
firmware_version:
@@ -137,9 +141,7 @@ paths:
137141
name: metrics
138142
required: true
139143
schema:
140-
items:
141-
$ref: '#/definitions/ingestion.DecimalMetricValue'
142-
type: array
144+
$ref: '#/definitions/ingestion.DecimalMetricValueList'
143145
produces:
144146
- application/json
145147
responses:
File renamed without changes.
File renamed without changes.
File renamed without changes.

pkg/http/metrics/temperature.go adapters/http/metrics/temperature.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// @Tags metric
1313
// @Accept json
1414
// @Produce json
15-
// @Param metrics body []ingestion.DecimalMetricValue true "metrics to insert"
15+
// @Param metrics body ingestion.DecimalMetricValueList true "metrics to insert"
1616
// @Success 201 {string} string "inserted the temperature metrics"
1717
// @Failure 400 {string} string "invalid request parameters"
1818
// @Failure 401 {string} string "no device token supplied"

pkg/http/server.go adapters/http/server.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"github.com/gin-gonic/gin"
77
"github.com/swaggo/gin-swagger"
88
"github.com/swaggo/gin-swagger/swaggerFiles"
9+
http_device "iot-demo/adapters/http/device"
10+
"iot-demo/adapters/http/docs"
11+
http_health "iot-demo/adapters/http/health"
12+
http_metrics "iot-demo/adapters/http/metrics"
913
add_device "iot-demo/pkg/device/add-device"
10-
http_device "iot-demo/pkg/http/device"
11-
"iot-demo/pkg/http/docs"
12-
http_health "iot-demo/pkg/http/health"
13-
http_metrics "iot-demo/pkg/http/metrics"
1414
add_metrics "iot-demo/pkg/metrics/add-metrics"
1515
query_metrics "iot-demo/pkg/metrics/query-metrics"
1616
"log"
File renamed without changes.

pkg/jwt/jwt.go adapters/jwt/jwt.go

File renamed without changes.
File renamed without changes.
File renamed without changes.

cmd/server/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package main
22

33
import (
44
"context"
5-
"iot-demo/pkg/config"
6-
http_server "iot-demo/pkg/http"
5+
"iot-demo/adapters/config"
6+
http_server "iot-demo/adapters/http"
77
"log"
88
"net/http"
99
"os"

cmd/server/wire.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ package main
44

55
import (
66
"github.com/google/wire"
7-
"iot-demo/pkg/config"
7+
"iot-demo/adapters/config"
8+
http_server "iot-demo/adapters/http"
9+
"iot-demo/adapters/jwt"
10+
"iot-demo/adapters/storage/memory"
811
add_device "iot-demo/pkg/device/add-device"
912
"iot-demo/pkg/device/registry"
10-
http_server "iot-demo/pkg/http"
11-
"iot-demo/pkg/jwt"
1213
add_metrics "iot-demo/pkg/metrics/add-metrics"
1314
"iot-demo/pkg/metrics/ingestion"
1415
query_metrics "iot-demo/pkg/metrics/query-metrics"
15-
"iot-demo/pkg/storage/memory"
1616
)
1717

1818
func NewJWTConfig(cfg config.Static) jwt.Config {

cmd/server/wire_gen.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/metrics/ingestion/metric.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ingestion
22

3+
type DecimalMetricValueList []*DecimalMetricValue
4+
35
type DecimalMetricValue struct {
46
Value float64 `json:"value"`
57
// Epoch timestamp in seconds

0 commit comments

Comments
 (0)