Esempio n. 1
0
func RegisterBackend(app *server.BroadcastServer) (server.Backend, error) {
	backend := new(DefaultBackend)
	app.RegisterCommand(server.Command{"PING", "Pings the server for a response", "", false}, backend.ping)
	app.RegisterCommand(server.Command{"ECHO", "Echos back a message sent", "ECHO \"hello world\"", false}, backend.echo)
	app.RegisterCommand(server.Command{"INFO", "Current server status and information", "", false}, backend.info)
	app.RegisterCommand(server.Command{"CMDS", "List of available commands supported by the server", "", false}, backend.help)
	backend.app = app
	return backend, nil
}
Esempio n. 2
0
func RegisterTermBackend(app *server.BroadcastServer, homeDir string) (server.Backend, error) {
	backend := new(TermBackend)
	backend.app = app

	// locate the resume content from the home directory
	if homeDir == "" {
		usr, _ := user.Current()
		homeDir = usr.HomeDir
	}
	backend.homeDir = homeDir

	app.RegisterCommand(server.Command{"cat", "Concatenate the contents of a file", "", false}, backend.CatFile)
	app.RegisterCommand(server.Command{"ls", "Lists the files in the directory", "", false}, backend.ListFiles)
	app.RegisterCommand(server.Command{"dir", "Lists the files in the directory", "", false}, backend.ListFiles)
	app.RegisterCommand(server.Command{"edit", "Edit the contents of a file", "", false}, backend.EditFile)
	app.RegisterCommand(server.Command{"save", "Saves the contents of a file", "", false}, backend.SaveFile)
	return backend, nil
}
Esempio n. 3
0
func RegisterBackend(app *server.BroadcastServer) (server.Backend, error) {
	backend := new(PubSubBackend)
	app.RegisterCommand(server.Command{"PUBLISH", "Publishes to a specified topic given the data/arguments", "PUBLISH topic message", true}, backend.publish)
	app.RegisterCommand(server.Command{"SUBSCRIBE", "Subscribes to a specified topic", "SUBSCRIBE topic [topic ...]", true}, backend.subscribe)
	app.RegisterCommand(server.Command{"UNSUBSCRIBE", "Unsubscribes from a specified topic", "UNSUBSCRIBE topic [topic ...]", true}, backend.unsubscribe)
	backend.app = app
	backend.topics = make(map[string]*TopicChannel)
	return backend, nil
}
Esempio n. 4
0
func RegisterBackend(app *server.BroadcastServer) (server.Backend, error) {
	backend := new(BGraphBackend)
	db, _ := NewMemoryGraphDb()
	backend.db = db

	app.RegisterCommand(server.Command{"=>", "Sets the directed edge weight", "=> weight from to [from to ...]", true}, backend.SetDEdge)
	app.RegisterCommand(server.Command{"+>", "Increments the directed edge weight", "+> weight from to [from to ...]", true}, backend.IncrDEdge)
	app.RegisterCommand(server.Command{"->", "Decrements the directed edge weight", "-> weight from to [from to ...]", true}, backend.DecrDEdge)
	app.RegisterCommand(server.Command{"<=>", "Sets the symmetric edge weight", "<=> weight from to [from to ...]", true}, backend.SetEdge)
	app.RegisterCommand(server.Command{"<+>", "Increments the symmetric edge weight", "<+> weight from to [from to ...]", true}, backend.IncrEdge)
	app.RegisterCommand(server.Command{"<->", "Decrements the symmetric edge weight", "<-> weight from to [from to ...]", true}, backend.DecrEdge)
	app.RegisterCommand(server.Command{"=", "Sets a given vertex's own weight", "= weight vertex [weight vertex ...]", true}, backend.SetVertex)
	app.RegisterCommand(server.Command{"+", "Increments a given vertex's own weight", "+ weight vertex [weight vertex ...]", true}, backend.IncrVertex)
	app.RegisterCommand(server.Command{"-", "Decrements a given vertex's own weight", "- weight vertex [weight vertex ...]", true}, backend.DecrVertex)
	app.RegisterCommand(server.Command{"*e", "Returns a list of all edges from the specified vertices", "*e vertex [vertex ...]", false}, backend.FindEdges)
	app.RegisterCommand(server.Command{"&e", "Returns the intersection of all edges between the set of vertices with the sum of the weights", "&e vertex [vertex ...]", false}, backend.IntersectEdges)
	backend.app = app

	return backend, nil
}
Esempio n. 5
0
func RegisterBackend(app *server.BroadcastServer) (server.Backend, error) {
	backend := new(StatsBackend)
	mem, err := NewMemoryBackend()
	if err != nil {
		return nil, err
	}

	backend.mem = mem

	app.RegisterCommand(server.Command{"COUNT", "Increments a key that resets itself to 0 on each flush routine.", "COUNT foo [124]", true}, backend.Count)
	app.RegisterCommand(server.Command{"COUNTERS", "Returns the list of active counters.", "", false}, backend.Counters)
	app.RegisterCommand(server.Command{"INCR", "Increments a key by the specified value or by default 1.", "INCR key [1]", false}, backend.Incr)
	app.RegisterCommand(server.Command{"DECR", "Decrements a key by the specified value or by default 1.", "DECR key [1]", false}, backend.Decr)
	app.RegisterCommand(server.Command{"DEL", "Deletes a key from the values or counters list or both.", "DEL key", false}, backend.Del)
	app.RegisterCommand(server.Command{"EXISTS", "Determines if the given key exists from the values.", "EXISTS key", false}, backend.Exists)
	app.RegisterCommand(server.Command{"GET", "Gets the specified key from the values.", "GET key", false}, backend.Get)
	app.RegisterCommand(server.Command{"SET", "Sets the specified key to the specified value in values.", "SET key 1234", false}, backend.Set)
	app.RegisterCommand(server.Command{"SETNX", "Sets the specified key to the given value only if the key is not already set.", "SETNX key 1234", false}, backend.SetNx)
	app.RegisterCommand(server.Command{"KEYS", "Returns the list of keys available or by pattern", "KEYS [pattern]", false}, backend.Keys)

	// set commands
	app.RegisterCommand(server.Command{"SADD", "Adds one or more members to a set", "SADD key member [member ...]", false}, backend.SAdd)
	app.RegisterCommand(server.Command{"SREM", "Removes one or more members from a set", "SREM key member [member ...]", false}, backend.SRem)
	app.RegisterCommand(server.Command{"SCARD", "Gets the number of members from a set", "SCARD key [key ...]", false}, backend.SCard)
	app.RegisterCommand(server.Command{"SMEMBERS", "Gets all the members in a set", "SMEMBERS key", false}, backend.SMembers)
	app.RegisterCommand(server.Command{"SDIFF", "Subtracts multiple sets", "SDIFF key [key ...]", false}, backend.SDiff)
	app.RegisterCommand(server.Command{"SISMEMBER", "Returns if member is a member of the set", "SISMEMBER key member [member ...]", false}, backend.SIsMember)
	app.RegisterCommand(server.Command{"SINTER", "Returns the members of the set resulting from the intersection of all the given sets", "SINTER key [key ...]", false}, backend.SInter)
	app.RegisterCommand(server.Command{"SUNION", "Returns the members of the set resulting from the union of all the given sets", "SINTER key [key ...]", false}, backend.SUnion)
	return backend, nil
}