Code Monkey home page Code Monkey logo

go-cidr's Introduction

Go-CIDR

Go Reference Go Report Card


Description

The purpose of that library is checked an IP inside from a CIDR.


Project structure

The project structure explained what contains what.

├── cmd
│   ├── bootstrap
│   │   └── bootstrap.go // point where init the service
│   └── main.go // entrypoint of the service
├── pkg
│   ├── config
│   │   └── config.go // config structs, methods and functions
│   ├── ip
│   │   ├── ip.go // logic to create the hosts from cirds
│   │   └── ip_test.go // test file for ip pkg
│   └── store
│       └── memory
│           └── memory.go // storage in memory
└── README.md // Readme

Example

Using storage in memory:

package main

import (
	"time"
	"log"

	b "github.com/jrmanes/go-cidr/cmd/bootstrap"
	m "github.com/jrmanes/go-cidr/pkg/store/memory"
)

func main() {
	// load configuration
	cidr := []string{"10.251.0.0/16", "172.18.0.0/16", "192.168.0.0/16"}

	// Run the process in order to load the hosts inside the cidr
	b.Run(cidr)

	now := time.Now()
	log.Println("---------FROM MEMORY------------")
	ip2CheckInMemory := "12.251.0.162"
	existsInMemory := m.CheckIfIpExistsInMemory(ip2CheckInMemory)
	if existsInMemory {
		log.Println("IP found ip2CheckInMemory (", ip2CheckInMemory, ")", existsInMemory)
	} else {
		log.Println("IP NOT found ip2CheckInMemory (", ip2CheckInMemory, ")", existsInMemory)
	}
	log.Println("elapse using storage memory:", time.Since(now))
	log.Println("-----------------------------")
}

TODO

  • Change project structure
    • Release 2.0.0
  • Add more test

Jose Ramón Mañes


go-cidr's People

Contributors

tty47 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.