-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfgParser.go
More file actions
52 lines (44 loc) · 1.11 KB
/
cfgParser.go
File metadata and controls
52 lines (44 loc) · 1.11 KB
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
44
45
46
47
48
49
50
51
52
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
// Config - config to drive this program
type Config struct {
MistAPIToken string `json:"mistAPIToken"`
SiteID string `json:"siteID"`
DeviceMac string `json:"deviceMAC"`
Coordinates Coordinates `json:"coordinates"`
Email Email `json:"email"`
}
// Coordinates represent geographic coordinates
type Coordinates struct {
Latitude float64 `json:"latitude,string"`
Longitude float64 `json:"longitude,string"`
}
// Email - the email details to be used
type Email struct {
From string `json:"from"`
To string `json:"to"`
Pwd string `json:"pass"`
SMTP string `json:"smtp"`
Port int `json:"port,string"`
Subject string `json:"subject"`
}
func cfgParser() (Config, error) {
var cfg Config
cfgFile, err := os.Open("config.json")
if err != nil {
fmt.Println(err)
}
defer cfgFile.Close()
bytes, _ := ioutil.ReadAll(cfgFile)
err = json.Unmarshal(bytes, &cfg)
if err != nil {
fmt.Printf("Have you constructed a valid `config.json` ? : %s\n", err)
return cfg, err
}
return cfg, nil
}