add.go 621 Bytes
Newer Older
ale's avatar
ale committed
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
package command

import (
	"log"

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

// Adds an entry to a set.
type AddCommand struct {
	SetName string `json:"set"`
	Entry   string `json:"entry"`
}

func NewAddCommand(setName, entry string) *AddCommand {
	return &AddCommand{
		SetName: setName,
		Entry:   entry,
	}
}

func (c *AddCommand) CommandName() string {
	return "add"
}

func (c *AddCommand) Apply(server raft.Server) (interface{}, error) {
	log.Printf("Apply(add, '%s', '%s')", c.SetName, c.Entry)
29 30
	ips := server.Context().(*ipset.IPSet)
	ips.Run("add", c.SetName, c.Entry)
ale's avatar
ale committed
31 32
	return nil, nil
}