add: debian file, perform various fixes
This commit is contained in:
@@ -25,20 +25,23 @@ type Config struct {
|
||||
SensorRateMS int64 `yaml:"sensor_rate_ms"`
|
||||
}
|
||||
|
||||
func New(source []byte) (*Config, error) {
|
||||
func New(source []byte, name string) (*Config, error) {
|
||||
config := &Config{}
|
||||
if err := yaml.Unmarshal(source, config); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse config: %w", err)
|
||||
}
|
||||
config.CameraName = name
|
||||
return config, nil
|
||||
}
|
||||
|
||||
type Mod struct {
|
||||
filePath string
|
||||
namePath string
|
||||
}
|
||||
|
||||
func (m *Mod) RegisterFlags(fs *flag.FlagSet) {
|
||||
fs.StringVar(&m.filePath, "watcher_config", "", "path to the watcher configuration")
|
||||
fs.StringVar(&m.namePath, "watcher_name", "/var/lib/dbus/machine-id", "location of the file to pull name from")
|
||||
}
|
||||
|
||||
func (m *Mod) Get() (*Config, error) {
|
||||
@@ -47,7 +50,13 @@ func (m *Mod) Get() (*Config, error) {
|
||||
return nil, fmt.Errorf("failed to read file %q: %w", m.filePath, err)
|
||||
}
|
||||
|
||||
config, err := New(bytes)
|
||||
// Override name using a unique ID; we can let users name things in the app
|
||||
myID, err := os.ReadFile(m.namePath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read machine ID from %q", m.namePath)
|
||||
}
|
||||
|
||||
config, err := New(bytes, string(myID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user