del.go 623 Bytes
Newer Older
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
package command

import (
	"log"

	"git.autistici.org/ale/ipsetd/ipset"
	"github.com/goraft/raft"
)

// Delete an entry in a set.
type DelCommand struct {
	SetName string `json:"set"`
	Entry   string `json:"entry"`
}

func NewDelCommand(setName, entry string) *DelCommand {
	return &DelCommand{
		SetName: setName,
		Entry:   entry,
	}
}

func (c *DelCommand) CommandName() string {
	return "del"
}

func (c *DelCommand) Apply(server raft.Server) (interface{}, error) {
	log.Printf("Apply(del, '%s', '%s')", c.SetName, c.Entry)
	ips := server.Context().(*ipset.IPSet)
	ips.Run("del", c.SetName, c.Entry)
	return nil, nil
}