Tidy
This commit is contained in:
parent
73041e6581
commit
e2c3d199ae
|
@ -11,6 +11,7 @@ import (
|
|||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
// Config contains the main program configuration
|
||||
type Config struct {
|
||||
wwwDir string
|
||||
bindAddr string
|
||||
|
@ -21,13 +22,14 @@ var config Config
|
|||
var mqtt MQTTReceiver
|
||||
var devices map[string]Location
|
||||
|
||||
// SetDefaults sets the configuration defaults
|
||||
func (c *Config) SetDefaults() {
|
||||
c.wwwDir = "./www"
|
||||
c.bindAddr = "127.0.0.1:8090"
|
||||
c.mqttRemote = "127.0.0.1"
|
||||
}
|
||||
|
||||
func mqtt_recv(id string, loc Location) {
|
||||
func mqttRecv(id string, loc Location) {
|
||||
if !loc.IsPlausible() { // Ignore stupid locations
|
||||
return
|
||||
}
|
||||
|
@ -70,7 +72,7 @@ func parseProgramArguments() error {
|
|||
i++
|
||||
config.bindAddr = args[i]
|
||||
} else {
|
||||
return fmt.Errorf("Invalid argument: %s\n", arg)
|
||||
return fmt.Errorf("invalid argument: %s", arg)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -87,7 +89,7 @@ func main() {
|
|||
fmt.Fprintf(os.Stderr, "No mqtt remote set\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
mqtt.Received = mqtt_recv
|
||||
mqtt.Received = mqttRecv
|
||||
if err := mqtt.Connect(config.mqttRemote, "owntracks/#", "", "", "ot-browser"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "mqtt error: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
@ -104,6 +106,7 @@ func main() {
|
|||
log.Fatal(http.ListenAndServe(config.bindAddr, nil))
|
||||
}
|
||||
|
||||
// ReadFile reads a configuration file
|
||||
func (c *Config) ReadFile(filename string) error {
|
||||
cfg, err := ini.InsensitiveLoad(filename)
|
||||
if err != nil {
|
||||
|
@ -147,8 +150,8 @@ func handlerLocations(w http.ResponseWriter, r *http.Request) {
|
|||
point.Properties["name"] = dev
|
||||
point.Properties["id"] = dev
|
||||
point.Properties["time"] = fmt.Sprintf("%d", loc.Timestamp)
|
||||
point.Properties["altitude"] = fmt.Sprintf("%d", loc.Alt)
|
||||
point.Properties["accuracy"] = fmt.Sprintf("%d", loc.Acc)
|
||||
point.Properties["altitude"] = fmt.Sprintf("%f", loc.Alt)
|
||||
point.Properties["accuracy"] = fmt.Sprintf("%f", loc.Acc)
|
||||
locations = append(locations, point)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue