Skip to content

Commit

Permalink
move to postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
herrphon committed Nov 12, 2023
1 parent 92c54b3 commit 3caf192
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 419 deletions.
280 changes: 0 additions & 280 deletions get.go

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.21.3
require (
github.com/go-kit/kit v0.13.0
github.com/influxdata/influxdb-client-go/v2 v2.3.1-0.20210518120617-5d1fff431040
github.com/lib/pq v1.10.9
github.com/spf13/cobra v1.7.0
github.com/tgulacsi/go v0.27.1
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
Expand Down
30 changes: 12 additions & 18 deletions push.go → http.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

type solarAPIAccept struct {
influxClient
postgresClient
}

func (sa solarAPIAccept) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand All @@ -49,23 +49,17 @@ func (sa solarAPIAccept) ServeHTTP(w http.ResponseWriter, r *http.Request) {
level.Debug(sa.Logger).Log("msg", "decoded", "data", fmt.Sprintf("%#v", data))
w.WriteHeader(200)

if err := sa.influxClient.Put("fronius energy",
[]dataPoint{
{Name: "pac", Time: data.Head.Timestamp,
Unit: data.Body.Pac.Unit,
Value: data.Body.Pac.Values["1"]},
{Name: "day", Time: data.Head.Timestamp,
Unit: data.Body.Day.Unit,
Value: data.Body.Day.Values["1"]},
{Name: "year", Time: data.Head.Timestamp,
Unit: data.Body.Year.Unit,
Value: data.Body.Year.Values["1"]},
{Name: "total", Time: data.Head.Timestamp,
Unit: data.Body.Total.Unit,
Value: data.Body.Total.Values["1"]},
}...); err != nil {
level.Error(sa.Logger).Log("msg", "write batch to db", "error", err)
}
sa.postgresClient.Put(
data.Body.Pac.Values["1"],
data.Body.Pac.Unit,
data.Body.Day.Values["1"],
data.Body.Day.Unit,
data.Body.Year.Values["1"],
data.Body.Year.Unit,
data.Body.Total.Values["1"],
data.Body.Total.Unit,
)

}

type solarV1CurrentInverter struct {
Expand Down
Loading

0 comments on commit 3caf192

Please sign in to comment.