-
Notifications
You must be signed in to change notification settings - Fork 22
/
config.go
36 lines (33 loc) · 824 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
package main
import (
"github.com/felixge/toml" // fork, see https://github.com/BurntSushi/toml/pull/14
"os"
"path/filepath"
"time"
)
// Config holds the user configuration for the GoDrone firmware.
type Config struct {
LogFile string
LogLevel string
ControlTimeout time.Duration
MaxAngle int
RollPID []float64
PitchPID []float64
YawPID []float64
HttpAddr string
NavboardTTY string
MotorboardTTY string
}
// LoadConfig loads the configuration from a toml file. Other file formats may
// be supported in the future as well.
func LoadConfig(file string, config *Config) error {
if string(file[0]) != "/" {
wd, err := os.Getwd()
if err != nil {
return err
}
file = filepath.Join(wd, file)
}
_, err := toml.DecodeFile(file, &config)
return err
}