Пример #1
0
func (b *BGraphBackend) FindEdges(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 1 {
		client.WriteError(errors.New("*e takes at least 1 parameter (*e vertex [vertex ...])"))
		client.Flush()
		return nil
	}

	vertexEdges := make(map[string]map[string]float64)
	for _, k := range d {
		key := string(k)
		edges := b.db.findEdges(key)
		if edges != nil {
			vertexEdges[key] = edges
		}
	}

	if len(vertexEdges) > 0 {
		client.WriteJson(vertexEdges)
		client.Flush()
	} else {
		client.WriteNull()
		client.Flush()
	}
	return nil
}
Пример #2
0
func (stats *StatsBackend) Counters(data interface{}, client server.ProtocolClient) error {
	results, err := stats.mem.Counters()
	if err != nil {
		client.WriteError(err)
		client.Flush()
		return nil
	}

	client.WriteJson(results)
	client.Flush()
	return nil
}
Пример #3
0
func (t *TermBackend) EditFile(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) > 0 {
		fileName := string(d[0])
		content, err := ioutil.ReadFile(path.Join(t.homeDir, fileName))
		if err == nil {
			fileMap := make(map[string]string)
			fileMap["filename"] = fileName
			fileMap["contents"] = string(content)
			client.WriteJson(fileMap)
			client.Flush()
		} else {
			fileMap := make(map[string]string)
			fileMap["filename"] = fileName
			fileMap["contents"] = ""
			client.WriteJson(fileMap)
			client.Flush()
		}
	}

	return nil
}
Пример #4
0
func (b *BGraphBackend) IntersectEdges(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 2 {
		client.WriteError(errors.New("&e takes at least 2 parameters (&e vertex [vertex ...])"))
		client.Flush()
		return nil
	}

	keys := make([]string, len(d))
	for i, k := range d {
		keys[i] = string(k)
	}

	results := b.db.sumIntersectEdges(keys)
	if results != nil && len(results) > 0 {
		client.WriteJson(results)
		client.Flush()
	} else {
		client.WriteNull()
		client.Flush()
	}

	return nil
}
Пример #5
0
func (b *DefaultBackend) help(data interface{}, client server.ProtocolClient) error {
	help, _ := b.app.Help()
	client.WriteJson(help)
	client.Flush()
	return nil
}
Пример #6
0
func (b *DefaultBackend) info(data interface{}, client server.ProtocolClient) error {
	status, _ := b.app.Status()
	client.WriteJson(status)
	client.Flush()
	return nil
}