Skip to content

Commit

Permalink
- Update deps
Browse files Browse the repository at this point in the history
- rewrite interface{} to any
- JSON output cleanups for b749228 commit
  • Loading branch information
dkorunic committed Jun 13, 2023
1 parent b749228 commit 9850551
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 155 deletions.
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/dkorunic/iSMC

go 1.19
go 1.20

require (
github.com/fvbommel/sortorder v1.0.2
github.com/fvbommel/sortorder v1.1.0
github.com/json-iterator/go v1.1.12
github.com/panotza/gosmc v1.0.0
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.7.0
)

require (
Expand All @@ -19,10 +19,10 @@ require (

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jedib0t/go-pretty/v6 v6.4.4
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.1
golang.org/x/sys v0.4.0 // indirect
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.9.0 // indirect
)
29 changes: 13 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
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/fvbommel/sortorder v1.0.2 h1:mV4o8B2hKboCdkJm+a7uX/SIpZob4JzUpc5GGnM45eo=
github.com/fvbommel/sortorder v1.0.2/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/fvbommel/sortorder v1.1.0 h1:fUmoe+HLsBTctBDoaBwpQo5N+nrCp8g/BjKb/6ZQmYw=
github.com/fvbommel/sortorder v1.1.0/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.4.4 h1:N+gz6UngBPF4M288kiMURPHELDMIhF/Em35aYuKrsSc=
github.com/jedib0t/go-pretty/v6 v6.4.4/go.mod h1:MgmISkTWDSFu0xOqiZ0mKNntMQ2mDgOcwOkwBEkMDJI=
github.com/jedib0t/go-pretty/v6 v6.4.6 h1:v6aG9h6Uby3IusSSEjHaZNXpHFhzqMmjXcPq1Rjl9Jw=
github.com/jedib0t/go-pretty/v6 v6.4.6/go.mod h1:Ndk3ase2CkQbXLLNf5QDHoYb6J9WtVfmHZu9n8rk2xs=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
Expand All @@ -26,25 +25,23 @@ github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdL
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/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
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/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.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
10 changes: 5 additions & 5 deletions hid/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ import (
)

// GetAll returns all detected HID sensor results.
func GetAll() map[string]interface{} {
sensors := make(map[string]interface{})
func GetAll() map[string]any {
sensors := make(map[string]any)

sensors["Current"] = GetCurrent()
sensors["Temperature"] = GetTemperature()
Expand All @@ -203,23 +203,23 @@ func GetAll() map[string]interface{} {
}

// GetCurrent returns detected HID current sensor results.
func GetCurrent() map[string]interface{} {
func GetCurrent() map[string]any {
cStr := C.getCurrents()
defer C.free(unsafe.Pointer(cStr))

return getGeneric("A", cStr)
}

// GetVoltage returns detected HID voltage sensor results.
func GetVoltage() map[string]interface{} {
func GetVoltage() map[string]any {
cStr := C.getVoltages()
defer C.free(unsafe.Pointer(cStr))

return getGeneric("V", cStr)
}

// GetTemp returns detected HID temperature sensor results.
func GetTemperature() map[string]interface{} {
func GetTemperature() map[string]any {
cStr := C.getThermals()
defer C.free(unsafe.Pointer(cStr))

Expand Down
10 changes: 5 additions & 5 deletions output/influxoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (io InfluxOutput) All() {

for _, key := range keys {
value := all[key]
if smcdata, ok := value.(map[string]interface{}); ok {
if smcdata, ok := value.(map[string]any); ok {
io.print(key, smcdata)
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func (io InfluxOutput) Voltage() {
}

func influx_string_convert(s string) string {
s = strings.Replace(s, " ", "_", -1)
s = strings.ReplaceAll(s, " ", "_")
s = strings.ToLower(s)
return s
}
Expand All @@ -94,15 +94,15 @@ func influx_get_unit(s string) string {
s = strings.Trim(s, "value=")
if len(strings.Split(s, " ")) > 1 {
s = strings.Split(s, " ")[1]
s = strings.Replace(s, "°", "", -1)
s = strings.ReplaceAll(s, "°", "")
s = strings.ToLower(s)
} else {
s = "none"
}
return s
}

func (io InfluxOutput) print(name string, smcdata map[string]interface{}) {
func (io InfluxOutput) print(name string, smcdata map[string]any) {
if len(smcdata) != 0 {
ct := time.Now().UnixNano()

Expand All @@ -113,7 +113,7 @@ func (io InfluxOutput) print(name string, smcdata map[string]interface{}) {

for _, k := range keys {
v := smcdata[k]
if value, ok := v.(map[string]interface{}); ok {
if value, ok := v.(map[string]any); ok {
key := fmt.Sprint(value["key"])
if len(key) > 0 {
key = influx_string_convert(fmt.Sprintf(",key=%s", value["key"]))
Expand Down
52 changes: 28 additions & 24 deletions output/jsonoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package output

import (
"encoding/json"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -47,59 +46,63 @@ type newstruct struct {
}

func format(d any) (any, error) {
v := d.(map[string]any)
var err error
v, ok := d.(map[string]any)
if !ok {
return v, fmt.Errorf("not a map")
}

json := jsoniter.ConfigCompatibleWithStandardLibrary

for key, entry := range v {
t := make([]byte, 0)
buf := new(newstruct)
s := make([]string, 0)
t, err = json.Marshal(entry)
t, err := json.Marshal(entry)
if err != nil {
fmt.Println("json.Marshal error:", err)
break
return v, err
}
err = json.Unmarshal(t, buf)

buf := newstruct{}
err = json.Unmarshal(t, &buf)
if err != nil {
fmt.Println("json.Unmarshal error:", err)
break
return v, err
}

// Process only string values
switch buf.Value.(type) {
case string:
if !strings.Contains(buf.Value.(string), " ") {
continue
}
s = strings.Split(buf.Value.(string), " ")
s := strings.Split(buf.Value.(string), " ")
switch buf.Type {
case "flt", "sp78", "sp87":
case "flt", "sp78", "sp87", "hid":
f, err := strconv.ParseFloat(s[0], 64)
if err != nil {
break
return v, err
}

buf.Quantity = f
buf.Unit = s[1]
}
}

v[key] = buf
}
return v, err

return v, nil
}

func (jo JSONOutput) All() {
var err error
data := make(map[string]any)
data = GetAll()
data := GetAll()
for key, d := range data {
if data[key], err = format(d); err != nil {
fmt.Printf("Convert error:%v\n", err)
jo.print(GetAll())
return
}
}

json := jsoniter.ConfigCompatibleWithStandardLibrary
out, _ := json.MarshalIndent(data, "", " ")
fmt.Fprint(jo.writer, string(out))
out, _ := json.Marshal(data)
fmt.Println(string(out))
}

func (jo JSONOutput) Battery() {
Expand Down Expand Up @@ -129,10 +132,11 @@ func (jo JSONOutput) Voltage() {
func (jo JSONOutput) print(v any) {
data, err := format(v)
if err != nil {
fmt.Println("Convert error:", v)
fmt.Printf("could not format data: %v\n", err)
return
}

json := jsoniter.ConfigCompatibleWithStandardLibrary
out, _ := json.MarshalIndent(data, "", " ")
fmt.Fprint(jo.writer, string(out))
out, _ := json.Marshal(data)
fmt.Println(string(out))
}
22 changes: 11 additions & 11 deletions output/jsonoutput_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ func TestJSONOutput(t *testing.T) {
{
"All sensors",
func() {
GetAll = func() map[string]interface{} {
return map[string]interface{}{
"sensor-1": map[string]interface{}{
GetAll = func() map[string]any {
return map[string]any{
"sensor-1": map[string]any{
"key": "key",
"value": "string",
"type": "type",
},
"sensor-2": map[string]interface{}{
"sensor-2": map[string]any{
"key": "key",
"value": true,
"type": "type",
},
"sensor-3": map[string]interface{}{
"sensor-3": map[string]any{
"key": "key",
"value": 99,
"type": "type",
Expand All @@ -62,7 +62,7 @@ func TestJSONOutput(t *testing.T) {
{
"Battery sensor",
func() {
GetBattery = func() map[string]interface{} {
GetBattery = func() map[string]any {
return getMapForSensor("battery")
}
},
Expand All @@ -74,7 +74,7 @@ func TestJSONOutput(t *testing.T) {
{
"Current sensor",
func() {
GetCurrent = func() map[string]interface{} {
GetCurrent = func() map[string]any {
return getMapForSensor("current")
}
},
Expand All @@ -86,7 +86,7 @@ func TestJSONOutput(t *testing.T) {
{
"Fans sensor",
func() {
GetFans = func() map[string]interface{} {
GetFans = func() map[string]any {
return getMapForSensor("fans")
}
},
Expand All @@ -98,7 +98,7 @@ func TestJSONOutput(t *testing.T) {
{
"Power sensor",
func() {
GetPower = func() map[string]interface{} {
GetPower = func() map[string]any {
return getMapForSensor("power")
}
},
Expand All @@ -110,7 +110,7 @@ func TestJSONOutput(t *testing.T) {
{
"Temperature sensor",
func() {
GetTemperature = func() map[string]interface{} {
GetTemperature = func() map[string]any {
return getMapForSensor("temperature")
}
},
Expand All @@ -122,7 +122,7 @@ func TestJSONOutput(t *testing.T) {
{
"Voltage sensor",
func() {
GetVoltage = func() map[string]interface{} {
GetVoltage = func() map[string]any {
return getMapForSensor("voltage")
}
},
Expand Down
Loading

0 comments on commit 9850551

Please sign in to comment.