Skip to content
Open
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
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: path-pulse-iot-backend

on:
push:
tags:
- '*.*'
pull_request:
branches:
- main
- 'releases/**'
issues:
types:
- opened
- labeled

jobs:
config:
name: Configuration for ci
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.secret-name.outputs.demo_secret }}
version: ${{ steps.go-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: demo secret
id: secret-name
env:
demo_secret: ${{ secrets.MY_DEMO_SECRET }}
run: echo "demo_secret=${demo_secret:-nothing}">>$GITHUB_OUTPUT
- name: Extract Go Version
id: go-version
run: |
GO_VERSION=$(grep '^go ' go.mod | awk '{ print $2}')
echo "Extracted Go version: $GO_VERSION"
echo "version=${GO_VERSION:-1.20}" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: config
steps:
- name: Github Event Details
env:
event_context: ${{ toJSON(github.event) }}
run: echo github.event, "$event_context"
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ needs.config.outputs.version }}
- name: Echo Go version
env:
go_version: ${{ needs.config.outputs.version }}
run: |
echo "Using Go Version $go_version"
- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
mat:
name: matrix job
runs-on: ubuntu-latest
strategy:
matrix:
node:
- 12
- 14
steps:
- name: echo matrix node
env:
node: ${{ matrix.node }}
run: echo "$node"
29 changes: 29 additions & 0 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: manual testing
on:
workflow_dispatch:
inputs:
logLevel:
description: Debug Level
required: true
default: 'info'
type: choice
options:
- debug
- info
- warning
go-version:
description: Go Version
required: false
default: '1.21'
type: string
jobs:
build:
name: Build the project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ inputs.go-version }}
- name: Build
run: go build -v ./..
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.22.10

require (
github.com/golang/protobuf v1.5.4
github.com/influxdata/influxdb-client-go/v2 v2.14.0
github.com/spf13/cobra v1.8.1
gomodules.xyz/pointer v0.1.0
google.golang.org/genproto v0.0.0-20250106144421-5f5ef82da422
Expand All @@ -14,7 +15,11 @@ require (
)

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/oapi-codegen/runtime v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
Expand Down
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
Expand All @@ -11,11 +18,25 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/influxdata/influxdb-client-go/v2 v2.14.0 h1:AjbBfJuq+QoaXNcrova8smSjwJdUHnwvfjMF71M1iI4=
github.com/influxdata/influxdb-client-go/v2 v2.14.0/go.mod h1:Ahpm3QXKMJslpXl3IftVLVezreAUtBOTZssDrjZEFHI=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7wlPfJLvMCdtV4zPulc4uCPrlywQOmbFOhgQNU=
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/oapi-codegen/runtime v1.0.0 h1:P4rqFX5fMFWqRzY9M/3YF9+aPSPPB06IzP2P7oOxrWo=
github.com/oapi-codegen/runtime v1.0.0/go.mod h1:LmCUMQuPB4M/nLXilQXhHw+BLZdDb18B34OO356yJ/A=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
Expand Down Expand Up @@ -43,4 +64,5 @@ google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7
google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU=
google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 2 additions & 0 deletions internal/config/influx/.env.influxdb2-admin-password
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VeryHardPass

1 change: 1 addition & 0 deletions internal/config/influx/.env.influxdb2-admin-token
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MyInitialAdminToken0==
1 change: 1 addition & 0 deletions internal/config/influx/.env.influxdb2-admin-username
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
admin
33 changes: 33 additions & 0 deletions internal/config/influx/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
influxdb2:
image: influxdb:2
ports:
- 8086:8086
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME_FILE: /run/secrets/influxdb2-admin-username
DOCKER_INFLUXDB_INIT_PASSWORD_FILE: /run/secrets/influxdb2-admin-password
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN_FILE: /run/secrets/influxdb2-admin-token
DOCKER_INFLUXDB_INIT_ORG: docs
DOCKER_INFLUXDB_INIT_BUCKET: home
secrets:
- influxdb2-admin-username
- influxdb2-admin-password
- influxdb2-admin-token
volumes:
- type: volume
source: influxdb2-data
target: /var/lib/influxdb2
- type: volume
source: influxdb2-config
target: /etc/influxdb2
secrets:
influxdb2-admin-username:
file: .env.influxdb2-admin-username
influxdb2-admin-password:
file: .env.influxdb2-admin-password
influxdb2-admin-token:
file: .env.influxdb2-admin-token
volumes:
influxdb2-data:
influxdb2-config:
101 changes: 101 additions & 0 deletions internal/db/influx/influx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package influx

import (
"context"
"fmt"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"time"
)

type InfluxDbClientBuilder struct {
url string
org string
token string
bucket string
}

type InfluxDBOptions struct {
Url string
Org string
Token string
Bucket string
}

func NewInfluxDbClientBuilder() *InfluxDbClientBuilder {
return &InfluxDbClientBuilder{}
}

func (i *InfluxDbClientBuilder) WithOrg(org string) *InfluxDbClientBuilder {
i.org = org
return i
}

func (i *InfluxDbClientBuilder) WithBucket(bk string) *InfluxDbClientBuilder {
i.bucket = bk
return i
}

func (i *InfluxDbClientBuilder) WithURL(url string) *InfluxDbClientBuilder {
i.url = url
return i
}

func (i *InfluxDbClientBuilder) WithToken(token string) *InfluxDbClientBuilder {
i.token = token
return i
}

func (i *InfluxDbClientBuilder) InfluxDbClient() influxdb2.Client {
return influxdb2.NewClient(i.url, i.token)

}

func InfluxDBClient() {
bucket := "example-bucket"
org := "example-org"
token := "MyInitialAdminToken0=="
// Store the URL of your InfluxDB instance
url := "http://localhost:8086"
client := influxdb2.NewClient(url, token)
writeAPI := client.WriteAPIBlocking(org, bucket)
p := influxdb2.NewPoint("stat",
map[string]string{"unit": "temperature"},
map[string]interface{}{"avg": 24.5, "max": 45},
time.Now())
writeAPI.WritePoint(context.Background(), p)
client.Close()
}

func query() {
bucket := "example-bucket"
org := "example-org"
token := "MyInitialAdminToken0=="
// Store the URL of your InfluxDB instance
url := "http://localhost:8086"
// Create client
client := influxdb2.NewClient(url, token)
// Get query client
queryAPI := client.QueryAPI(org)
// Get QueryTableResult
result, err := queryAPI.Query(context.Background(), fmt.Sprintf(`from(bucket:"%s")|> range(start: -1h) |> filter(fn: (r) => r._measurement == "stat")`, bucket))
if err == nil {
// Iterate over query response
for result.Next() {
// Notice when group key has changed
if result.TableChanged() {
fmt.Printf("table: %s\n", result.TableMetadata().String())
}
// Access data
fmt.Printf("value: %v\n", result.Record().Value())
}
// Check for an error
if result.Err() != nil {
fmt.Printf("query parsing error: %s\n", result.Err().Error())
}
} else {
panic(err)
}
// Ensures background processes finishes
client.Close()

}
26 changes: 17 additions & 9 deletions internal/models/tracker.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package models

type Position struct {
UID UserID `json:"uid,omitempty"`
Latitude float32 `json:"latitude,omitempty"`
Longitude float32 `json:"longitude,omitempty"`
}
type AlertType string

const (
Normal AlertType = "Normal"
LowPressure AlertType = "LowPressure"
HighPressure AlertType = "HighPressure"
)

type Checkpoint struct {
CID uint64 `json:"c_id,omitempty"`
UID UserID `json:"u_id,omitempty"`
Pos Position `json:"pos,omitempty"`
type Position struct {
UID UserID `json:"uid,omitempty"`
Latitude float32 `json:"latitude,omitempty"`
Longitude float32 `json:"longitude,omitempty"`
CheckPointID uint64 `json:"checkPointId,omitempty"`
}

type BloodPressure struct {
Expand All @@ -21,3 +24,8 @@ type BloodPressureWithUserID struct {
UserID UserID `json:"user_id,omitempty"`
BP BloodPressure `json:"bp,omitempty"`
}

type Alert struct {
Type AlertType `json:"type,omitempty"`
Message string `json:"message,omitempty"`
}
Loading
Loading