-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from JacquesBeets:feature/sqlite-2
Feature/sqlite-2
- Loading branch information
Showing
18 changed files
with
671 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# /frontend | ||
/scripts/*.ps1 | ||
!scripts/test_notification.ps1 | ||
/data/** | ||
*.exe | ||
*.log | ||
*.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type Config struct { | ||
BrokerAddress string `json:"broker_address"` | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
ClientID string `json:"client_id"` | ||
Topic string `json:"topic"` | ||
LogLevel string `json:"log_level"` | ||
ScriptTimeout int `json:"script_timeout"` | ||
Commands map[string]ScriptConfig `json:"commands"` | ||
SensorConfig SensorConfig `json:"sensor_config"` | ||
} | ||
|
||
type ScriptConfig struct { | ||
ScriptPath string `json:"script_path"` | ||
RunAsUser bool `json:"run_as_user"` | ||
} | ||
type SensorConfig struct { | ||
Enabled bool `json:"enabled"` | ||
Interval int `json:"interval"` | ||
SensorTopic string `json:"sensor_topic"` | ||
ID int64 `json:"id"` | ||
BrokerAddress string `json:"broker_address"` | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
ClientID string `json:"client_id"` | ||
Topic string `json:"topic"` | ||
LogLevel string `json:"log_level"` | ||
ScriptTimeout int `json:"script_timeout"` | ||
SensorConfigEnabled bool `json:"sensor_config_enabled"` | ||
Commands map[string]ScriptConfig `json:"commands"` | ||
Sensors map[string]SensorConfig `json:"sensors"` | ||
} | ||
|
||
func (p *program) loadConfig() error { | ||
p.logger.Debug("Starting to load config...") | ||
exePath, err := os.Executable() | ||
if err != nil { | ||
p.logger.Error(fmt.Sprintf("Failed to get executable path: %v", err)) | ||
return fmt.Errorf("failed to get executable path: %v", err) | ||
} | ||
p.logger.Debug(fmt.Sprintf("Executable path: %s", exePath)) | ||
|
||
configPath := filepath.Join(filepath.Dir(exePath), "config.json") | ||
p.logger.Debug(fmt.Sprintf("Config path: %s", configPath)) | ||
|
||
file, err := os.Open(configPath) | ||
conf, err := p.db.GetConfig() | ||
if err != nil { | ||
p.logger.Error(fmt.Sprintf("Failed to open config file: %v", err)) | ||
return fmt.Errorf("failed to open config file: %v", err) | ||
p.logger.Error(fmt.Sprintf("Failed to get config: %v", err)) | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
decoder := json.NewDecoder(file) | ||
if err := decoder.Decode(&p.config); err != nil { | ||
p.logger.Error(fmt.Sprintf("Failed to decode config: %v", err)) | ||
return fmt.Errorf("failed to decode config: %v", err) | ||
} | ||
|
||
p.config = *conf | ||
p.logger.Debug("Config loaded successfully") | ||
return nil | ||
} |
Oops, something went wrong.