Esempio n. 1
0
File: Setup.go Progetto: ThingFu/hub
func loadRules(env api.Environment) {
	log.Println("[INFO] Dividing by Zero")
	rulesService := container.Instance().RulesManager()
	filepath.Walk(env.GetHome()+"/rules", func(path string, f os.FileInfo, err error) error {
		if !f.IsDir() {
			content, err := ioutil.ReadFile(path)
			if err != nil {
				panic(err)
			}

			var rule api.Rule
			err = json.Unmarshal(content, &rule)

			if err != nil {
				log.Printf("[ERROR] Parsing Rule %s\n", path)
				return nil
			}
			rule.Id = utils.RandomString(7)

			rule.Path = path[strings.LastIndex(path, "/")+1:]

			log.Printf("[INFO] Registering rule file: %s\n", rule.Name)

			rulesService.RegisterRule(rule)
		}
		return nil
	})
}
Esempio n. 2
0
File: Setup.go Progetto: ThingFu/hub
// Scans for defintions under home's /things subdirectory
// and it walks through the path.
// if the descriptor.json file is found, it is assumed that the
// directory it resides in contains a thing defintion
//
func loadThingTypes(env api.Environment) {
	log.Println("[INFO] Pressing the Any Key...")
	thingManager := container.Instance().ThingManager()
	home := env.GetHome()
	root := home + "/things"

	filepath.Walk(root, func(path string, f os.FileInfo, err error) error {
		if strings.HasSuffix(path, "descriptor.json") {
			content, err := ioutil.ReadFile(path)
			if err != nil {
				panic(err)
			}

			var thingType api.ThingType
			err = json.Unmarshal(content, &thingType)

			if err != nil {
				log.Println("error: ", err)
			}
			thingType.Path = strings.Replace(path, "/descriptor.json", "", -1)
			thingManager.RegisterThingType(thingType)
		}
		return nil
	})
}
Esempio n. 3
0
File: Setup.go Progetto: ThingFu/hub
func setupWebApplication(env api.Environment) {
	web.NewWebApplication(env.GetConfig().ServerPort)
}