Giter VIP home page Giter VIP logo

ipstore's Introduction

Package IPStore

Reliably log, store and count ingress IP addresses.

Logo

IPStore is a library for keeping track of IP addresses that make request to your service.

GitHub license

Features

  • Light-Weight
  • Fast Insert and Fetch Operations
  • Validation of inputs
  • Modular and extendable for any kind of storage

Example Code

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()
}

Installation

Use go get.

go get github.com/teezzan/ipstore

Then import IPstore library into your own code.

import "github.com/teezzan/ipstore"

Documentation

The doc for this library can be found on pkg.go.dev.

Architecture

Logo

The modular architecture allows for implementation of the same system using another storage.

Testing

Run make tests to run tests.

Benchmark Results

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

Contributing

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.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.