Update module github.com/influxdata/influxdb-client-go/v2 to v2.12.3 #15
38
config.go
Normal file
38
config.go
Normal file
@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func parseEnvironmentVariables() (err error) {
|
||||
for _, line := range os.Environ() {
|
||||
if strings.HasPrefix(line, "LINKY2INFLUX_") {
|
||||
err := parseConfigLine(line)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error in environment (%q): %w", line, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func parseConfigLine(line string) (err error) {
|
||||
fields := strings.SplitN(line, "=", 2)
|
||||
orig_key := strings.TrimSpace(fields[0])
|
||||
value := strings.TrimSpace(fields[1])
|
||||
|
||||
if len(value) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
key := strings.TrimPrefix(orig_key, "LINKY2INFLUX_")
|
||||
key = strings.Replace(key, "_", "-", -1)
|
||||
key = strings.ToLower(key)
|
||||
|
||||
err = flag.Set(key, value)
|
||||
|
||||
return
|
||||
}
|
2
main.go
2
main.go
@ -180,6 +180,8 @@ type TICWriter interface {
|
||||
}
|
||||
|
||||
func main() {
|
||||
parseEnvironmentVariables()
|
||||
|
||||
var legacyMode = flag.Bool("legacy-mode", false, "Assume teleinformation in legacy mode")
|
||||
var pushFrequency = flag.Bool("push-frequency", false, "Also fetch data about the grid frequency")
|
||||
flag.Parse()
|
||||
|
Loading…
x
Reference in New Issue
Block a user