Exemple #1
0
func (gapp *GoatApp) initConfigScope() error {
	var fullmap map[string]interface{}
	json.ReadJSON(gapp.rootFilespace, ConfigJSONPath, fullmap)
	plainmap, err := plainmap.ToPlainMap(fullmap)
	if err != nil {
		return err
	}
	ds := &scope.DataScope{
		Data: plainmap,
	}
	gapp.configScope = scope.Scope{
		EventScope: scope.NewEventScope(),
		DataScope:  ds,
		Injector:   ds.Injector(app.ConfigTagName),
	}
	return nil
}
Exemple #2
0
func TestWriteAndRead(t *testing.T) {
	var writeObject, readObject TestObject
	// init
	fs, err := memfs.NewFilespace()
	if err != nil {
		t.Error(err)
	}
	// create test data
	path := "fyfile.json"
	writeObject = TestObject{
		Value1: "str1",
		Value2: "str2",
	}
	// write & read
	json.WriteJSON(fs, path, writeObject)
	json.ReadJSON(fs, path, &readObject)
	// test node type
	if !fs.IsFile(path) {
		t.Error("filesystem not conatin file adter write")
	}
	if writeObject.Value1 != readObject.Value1 || writeObject.Value2 != readObject.Value2 {
		t.Error("read date is wrong", writeObject, readObject)
	}
}