46 lines
891 B
Go
46 lines
891 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
"os"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// ZorgConfig is the configuration of Zorg.
|
||
|
var ZorgConfig struct {
|
||
|
ZorgServer string `json:"ZorgServer"`
|
||
|
ZorgClientID string `json:"ZorgClientID"`
|
||
|
ZorgClientSecret string `json:"ZorgClientSecret"`
|
||
|
ZorgUname string `json:"ZorgUname"`
|
||
|
ZorgPass string `json:"ZorgPass"`
|
||
|
ZorgInterval int `json:"ZorgInterval"`
|
||
|
}
|
||
|
|
||
|
// Zint is the poll time
|
||
|
var Zint time.Duration
|
||
|
|
||
|
func init() {
|
||
|
|
||
|
//reading json file
|
||
|
file, err := ioutil.ReadFile("zorg.conf")
|
||
|
|
||
|
if err != nil {
|
||
|
log.Println("Cannot open config file", err.Error())
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
|
||
|
err = json.Unmarshal([]byte(file), &ZorgConfig)
|
||
|
|
||
|
if err != nil {
|
||
|
log.Println("Cannot marshal json: ", err.Error())
|
||
|
os.Exit(1)
|
||
|
}
|
||
|
|
||
|
Zint = time.Duration(time.Duration(ZorgConfig.ZorgInterval) * time.Second)
|
||
|
|
||
|
log.Println("Inizialized ZORG")
|
||
|
|
||
|
}
|