Skip to content

Commit

Permalink
build with go 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
creativeprojects committed Oct 2, 2023
1 parent 7b87384 commit 120b766
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go_version: ['1.19', '1.20']
go_version: ['1.21']
os: [ubuntu-latest]

steps:
Expand Down
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project_name: hardware-events

builds:
- id: resticprofile_targz
- id: hardware-events_targz
env:
- CGO_ENABLED=0
goos:
Expand All @@ -22,7 +22,7 @@ builds:
archives:
- id: targz
builds:
- resticprofile_targz
- hardware-events_targz
format: tar.gz

checksum:
Expand Down
1 change: 1 addition & 0 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// Config from the file
type Config struct {
Simulation bool `yaml:"simulation"`
Seed int64 `yaml:"simulation_seed"`
DiskPowerStatus map[string]DiskPowerStatus `yaml:"disk_power_status"`
Sensors map[string]Task `yaml:"sensors"`
DiskPools map[string][]string `yaml:"disk_pools"`
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module github.com/creativeprojects/hardware-events

go 1.19
go 1.21

require (
github.com/coreos/go-systemd/v22 v22.5.0
github.com/creativeprojects/clog v0.13.0
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
golang.org/x/sys v0.5.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
golang.org/x/sys v0.12.0 // indirect
)
40 changes: 15 additions & 25 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,34 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creativeprojects/clog v0.13.0 h1:QVWO65Za2/XfCQeNnDvO4td9i7fwV2xuv8V5jzFIONk=
github.com/creativeprojects/clog v0.13.0/go.mod h1:4CBBbXkwjxTSIE/OyrC77aTrEEHj6daYGFEDrNjfOkU=
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/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
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/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
5 changes: 4 additions & 1 deletion lib/global.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lib

import (
"math/rand"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -89,11 +90,13 @@ func NewGlobal(config cfg.Config) (*Global, error) {
return global, err
}

simulationRand := rand.New(rand.NewSource(config.Seed))

// Temperature sensors
for sensorName, sensorCfg := range config.Sensors {
var sensor SensorGetter
if config.Simulation {
sensor, err = simulation.NewSensor(sensorName, sensorCfg)
sensor, err = simulation.NewSensor(sensorName, sensorCfg, simulationRand)
} else {
sensor, err = NewSensor(sensorName, sensorCfg, os.DirFS("/"))
}
Expand Down
22 changes: 12 additions & 10 deletions lib/simulation/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ import (

// Sensor simulates a hardware sensor
type Sensor struct {
config cfg.Task
mutex sync.Mutex
values map[string]float64
Name string
config cfg.Task
mutex sync.Mutex
values map[string]float64
randGenerator *rand.Rand
Name string
}

// NewSensor creates a new simulated sensor
func NewSensor(name string, config cfg.Task) (*Sensor, error) {
func NewSensor(name string, config cfg.Task, randGenerator *rand.Rand) (*Sensor, error) {
return &Sensor{
config: config,
mutex: sync.Mutex{},
values: make(map[string]float64),
Name: name,
config: config,
mutex: sync.Mutex{},
values: make(map[string]float64),
randGenerator: randGenerator,
Name: name,
}, nil
}

Expand All @@ -47,7 +49,7 @@ func (s *Sensor) Get(expandEnv func(string) string) (int, error) {
// but when it's above the middle, make it cool down faster
adjustMiddle = 6
}
value += rand.Float64()*10 - adjustMiddle
value += s.randGenerator.Float64()*10 - adjustMiddle
if value < constants.SimulationMinTemp {
value = constants.SimulationMinTemp
}
Expand Down
3 changes: 2 additions & 1 deletion lib/simulation/sensor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package simulation

import (
"math/rand"
"testing"

"github.com/creativeprojects/hardware-events/cfg"
Expand All @@ -10,7 +11,7 @@ import (
)

func TestDefaultValues(t *testing.T) {
sensor, err := NewSensor("name", cfg.Task{})
sensor, err := NewSensor("name", cfg.Task{}, rand.New(rand.NewSource(1)))
require.NoError(t, err)

testData := []func(string) string{
Expand Down
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"math/rand"
"os"
"os/signal"
"runtime"
Expand All @@ -26,7 +25,7 @@ func main() {
var exitCode = 0
var err error

// trick to run all defer functions before returning with an exit code
// run all defer functions before returning with an exit code
defer func() {
if exitCode != 0 {
os.Exit(exitCode)
Expand Down Expand Up @@ -57,7 +56,7 @@ func main() {
}
if config.Simulation {
clog.Warningf("running in simulation mode with seed = %d", flags.seed)
rand.Seed(flags.seed)
config.Seed = flags.seed
}

global, err := lib.NewGlobal(config)
Expand Down

0 comments on commit 120b766

Please sign in to comment.