forked from TheCacophonyProject/thermal-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
43 lines (36 loc) · 877 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2017 The Cacophony Project. All rights reserved.
// Use of this source code is governed by the Apache License Version 2.0;
// see the LICENSE file for further details.
package main
import (
"io"
"os"
"github.com/BurntSushi/toml"
)
type Config struct {
SPISpeed int64 `toml:"spi-speed"`
PowerPin string `toml:"power-pin"`
OutputDir string `toml:"output-dir"`
MinSecs int `toml:"min-secs"`
}
var defaultConfig = Config{
SPISpeed: 30000000,
PowerPin: "GPIO23",
OutputDir: ".",
MinSecs: 10,
}
func ConfigFromFile(filename string) (*Config, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
return ConfigFromReader(f)
}
func ConfigFromReader(r io.Reader) (*Config, error) {
conf := defaultConfig
if _, err := toml.DecodeReader(r, &conf); err != nil {
return nil, err
}
return &conf, nil
}