This repository has been archived by the owner on Oct 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
75 lines (65 loc) · 2.76 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2017 Fraunhofer Institute for Applied Information Technology FIT
package main
import (
"io/ioutil"
"encoding/json"
"log"
"os"
)
const SCRIPT_DIR = "/sensors/"
const THING_DIR = "/things/"
const CONFIG_DIR = "/conf/"
const DROPZONE = "/dropzone/"
const AGENT_DIR = "/agents/"
const EXAMPLES_DIR = "/TEST/agents/"
const TEST_DIR ="/TEST/"
const ARCHIVES_DIR ="/TEST/agentarchives/"
const VALIDATE_TIMER = 10
const CONFIG_FILE ="thing-publisher.json"
//
// Main configuration container
//
type LSTPConfig struct {
Id string `json:"id"`
Description string `json:"description"`
Broker string `json:"broker"`
ServiceCatalog string `json:"servicecatalog"`
ServiceRegistration bool `json:"serviceregistration"`
Prefix string `json:"prefix"`
ValidateTimer int `json:"validatetimer"`
UUIDGeneration bool `json:"uuidgeneration"`
UploadArchive bool `json:"uploadarchive"`
AddThingArchiveTOPIC string `json:"addthingarchive-topic"`
ListThingsTOPIC string `json:"listthings-topic"`
RemoveThingTOPIC string `json:"removething-topic"`
ThingStatusTOPIC string `json:"thingstatus-topic"`
}
func loadConfig(confPath string) LSTPConfig {
s, _ := os.Getwd()
log.Println("[loadConfig] Using config file: ",s+confPath+CONFIG_FILE)
content, err := ioutil.ReadFile(s+confPath+CONFIG_FILE)
if err != nil {
return LSTPConfig{}
}
var aConfig LSTPConfig
err = json.Unmarshal(content,&aConfig)
if err != nil{
log.Fatal("[loadConfig] Cannot unmarshal json")
os.Exit(1)
//return LSTPConfig{}
}
log.Println("[loadConfig] ID : ",aConfig.Id)
log.Println("[loadConfig] Description : ",aConfig.Description)
log.Println("[loadConfig] MQTT Broker URL : ",aConfig.Broker)
log.Println("[loadConfig] Service Catalog URL : ",aConfig.ServiceCatalog)
log.Println("[loadConfig] Service registration : ",aConfig.ServiceRegistration)
log.Println("[loadConfig] Prefix : ",aConfig.Prefix)
log.Println("[loadConfig] Validate timer : ",aConfig.ValidateTimer)
log.Println("[loadConfig] UUID generation : ",aConfig.UUIDGeneration)
log.Println("[loadConfig] Archive upload allowed : ",aConfig.UploadArchive)
log.Println("[loadConfig] Add Thing Archive (MQTT-API) : ",aConfig.AddThingArchiveTOPIC)
log.Println("[loadConfig] List Things (MQTT-API) : ",aConfig.ListThingsTOPIC)
log.Println("[loadConfig] Remove Thing (MQTT-API) : ",aConfig.RemoveThingTOPIC)
log.Println("[loadConfig] Thing Status (MQTT-API) : ",aConfig.ThingStatusTOPIC)
return aConfig
}