IPStore is a library for keeping track of IP addresses that make request to your service.
- Light-Weight
- Fast Insert and Fetch Operations
- Validation of inputs
- Modular and extendable for any kind of storage
Using this library is as simple as running the following
package main
import "github.com/teezzan/ipstore"
func main() {
// Stores the IP Address 192.34.56.321 in the memory storage
ipstore.RequestHandled("192.34.56.321")
// Increments the IP Address 192.54.56.333 count by 1.
ipstore.RequestHandled("192.34.56.321")
// Fetch the top 100 frequent IP addresses
top100 := ipstore.Top100()
// Removes all stored IP addresses.
ipstore.Clear()
}
Use go get.
go get github.com/teezzan/ipstore
Then import IPstore library into your own code.
import "github.com/teezzan/ipstore"
The doc for this library can be found on pkg.go.dev.
The modular architecture allows for implementation of the same system using another storage.
Run make tests
to run tests.
Ensure you have considerable memory before running the benchmark tests with make benchmark
. You can also tweak the number of IP addresses to choose from by editing the variable ipLookupSize
(defaults to a billion) in ./benchmark_test.go
.
Below is the result of such benchmark with a billion unique ip addresses.
goos: linux
goarch: amd64
pkg: github.com/teezzan/ipstore
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
BenchmarkRequestHandled-8 1509050 778.6 ns/op
BenchmarkTop100-8 629430 2316 ns/op
PASS
ok github.com/teezzan/ipstore 90.634s
Issues and pull requests are welcome at IPstore. This project is intended to be safe, welcoming, and open for collaboration. Users are expected to adhere to the Contributor Covenant code of conduct. We are all human.
This project is licensed under the MIT License - see the LICENSE.md file for details.