It would be useful to generalize an interface for an apiban store so as to facilitate more clients and intermediate caching and storage.
Proposing the following definitions:
// Store defines and interface for storing and retrieving entries in the APIBan database, local or remote
type Store interface {
// Add inserts the given Listing into the store. Listing may be sparse, requiring only the IP. Returned value will be fully populated.
Add(ip *Listing) (*Listing, error)
// Exists checks to see whether the given IP matches a Listing in the store, returning the first matching Listing, if one exists.
Exists(ip net.IP) (*Listing, error)
// List retrieves the contents of the store
List() ([]*Listing, error)
// ListFromTime retrieves the contents of the store from the given timestamp
ListFromTime(t time.Time) ([]*Listing, error)
// Remove deletes the given Listing from the store
Remove(ip *Listing) error
// Reset empties the store
Reset() error
}
// Listing is an individually-listed IP address or subnet
type Listing struct {
// ID is the unique identifier for this Listing
ID string
// Timestamp is the time at which this Listing was added to the apiban.org database
Timestamp time.Time
// IP is the IP address or IP network which is in the apiban.org database
IP net.IPNet
}
This will set us up to have a pluggable system of stores by which we can make an extensible, pluggable set of client functions.
It would be useful to generalize an interface for an apiban store so as to facilitate more clients and intermediate caching and storage.
Proposing the following definitions:
This will set us up to have a pluggable system of stores by which we can make an extensible, pluggable set of client functions.