network

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 3 Imported by: 10

Documentation

Overview

Provides several types that represent common network concepts, such as IP addresses, network blocks, or autonomous systems.

These types can be used to store and manipulate network-related data in Go programs.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutonomousSystem

type AutonomousSystem struct {
	// Number is the autonomous system number (AS).
	Number int `json:"number"`
}

AutonomousSystem represents an autonomous system.

Example
as := AutonomousSystem{
	Number: 64496,
}

fmt.Println(as.Number == 64496)
Output:

true

func (AutonomousSystem) AssetType

func (a AutonomousSystem) AssetType() model.AssetType

AssetType returns the asset type.

func (AutonomousSystem) JSON

func (a AutonomousSystem) JSON() ([]byte, error)

JSON returns the JSON encoding of the struct.

type IPAddress

type IPAddress struct {
	// Address is the IP address value, stored as a netip.Addr type.
	// It should be a valid IP address, such as "192.0.2.1" (IPv4)
	// or "2001:db8::1" (IPv6).
	Address netip.Addr `json:"address"`

	// Type is the type of IP address, such as "IPv4" or "IPv6".
	Type string `json:"type"`
}

IPAddress represents an IP address.

Example
ip, _ := netip.ParseAddr("192.168.1.1")

ipAdress := IPAddress{
	Address: ip,
	Type:    "IPv4",
}

fmt.Println(ipAdress.Address == ip)
fmt.Println(ipAdress.Type == "IPv4")
Output:

true
true

func (IPAddress) AssetType

func (i IPAddress) AssetType() model.AssetType

AssetType returns the asset type.

func (IPAddress) JSON

func (i IPAddress) JSON() ([]byte, error)

JSON returns the JSON encoding of the struct.

type Netblock

type Netblock struct {
	// Cidr is the CIDR notation of the IP address block,
	// such as "198.51.100.0/24" (IPv4) or "2001:db8::/32" (IPv6).
	Cidr netip.Prefix `json:"cidr"`

	// Type is the type of the IP address block,
	// such as "IPv4" or "IPv6".
	Type string `json:"type"`
}

Netblock represents a block of IP addresses in a network. It is often used to specify a range of IP addresses that are assigned to a particular organization or network.

Example
cidr, _ := netip.ParsePrefix("198.51.100.0/24")

netblock := Netblock{
	Cidr: cidr,
	Type: "IPv4",
}

fmt.Println(netblock.Cidr == cidr)
fmt.Println(netblock.Type == "IPv4")
Output:

true
true

func (Netblock) AssetType

func (n Netblock) AssetType() model.AssetType

AssetType returns the asset type.

func (Netblock) JSON

func (n Netblock) JSON() ([]byte, error)

JSON returns the JSON encoding of the struct.

type RIROrganization

type RIROrganization struct {
	// Name of the RIR organization, such as "Google LLC".
	Name string `json:"name"`

	// RIRId is the unique identifier of the RIR organization,
	// such as "GOGL". Leave empty if unknown.
	RIRId string `json:"rir_id"`

	// RIR is the name of the RIR that this organization belongs to.
	// It should be one of "AFRINIC", "APNIC", "ARIN", "LACNIC", "RIPE".
	// Leave empty if unknown.
	RIR string `json:"rir"`
}

RIROrganization represents an organization that is a member of a Regional Internet Registry (RIR). An RIR is an organization that manages the allocation and registration of IP addresses and AS numbers within a specific region of the world.

Example
riro := RIROrganization{
	Name:  "Google LLC",
	RIRId: "GOGL",
	RIR:   "ARIN",
}

fmt.Println(riro.Name == "Google LLC")
fmt.Println(riro.RIRId == "GOGL")
fmt.Println(riro.RIR == "ARIN")
Output:

true
true
true

func (RIROrganization) AssetType

func (r RIROrganization) AssetType() model.AssetType

AssetType returns the asset type.

func (RIROrganization) JSON

func (r RIROrganization) JSON() ([]byte, error)

JSON returns the JSON encoding of the struct.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL