networkd

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToContext

func AddToContext(ctx context.Context, d Details) context.Context

AddToContext adds the network details to the context.

func Decorator

func Decorator(inner auditrail.Logger, ipr IPResolver) auditrail.Logger

Decorator returns a new audit.Logger that appends client details to the log entry before logging it.

This decorator assumes that client data was previously added to the context using the AddToContext function.

If the IPResolver is provided (not nil), it will be used to enrich the client details with GeoIP information.

func EchoMiddleware

func EchoMiddleware(next echo.HandlerFunc) echo.HandlerFunc

EchoMiddleware is an Echo middleware that injects into request's context a networkd.Details object holding the client's IP address.

func GRPCStreamInterceptor

func GRPCStreamInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error

GRPCStreamInterceptor is a gRPC stream server interceptor that injects networkd.Details into the context.

func GRPCUnaryInterceptor

func GRPCUnaryInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

GRPCUnaryInterceptor is a gRPC unary call interceptor that injects networkd.Details into the context.

func GinMiddleware

func GinMiddleware(c *gin.Context)

GinMiddleware is a Gin middleware that injects into request's context a networkd.Details object holding the client's IP address.

Types

type AS

type AS struct {
	Domain string `json:"domain"`
	Name   string `json:"name"`
	Number string `json:"number"`
	Route  string `json:"route"`
	Type   string `json:"type"`
}

AS autonomous system details.

type CachedIPResolver

type CachedIPResolver struct {
	// contains filtered or unexported fields
}

CachedIPResolver is an IPResolver that caches the results of the inner IPResolver so that subsequent calls to Resolve for the same IP address are faster.

func NewCachedIPResolver

func NewCachedIPResolver(inner IPResolver, size int) (*CachedIPResolver, error)

NewCachedIPResolver returns a new IPResolver that caches the results of the inner IPResolver so that subsequent calls to Resolve are faster.

The size parameter specifies the maximum number of entries in the cache.

func (*CachedIPResolver) Contains

func (c *CachedIPResolver) Contains(ip string) bool

Contains returns true if the cache contains the given IP address.

func (*CachedIPResolver) Purge

func (c *CachedIPResolver) Purge()

Purge purges the cache.

func (*CachedIPResolver) Remove

func (c *CachedIPResolver) Remove(ip string)

Remove invalidates the cache for the given IP address.

func (*CachedIPResolver) Resolve

func (c *CachedIPResolver) Resolve(ip string) GeoIP

Resolve resolves the geoip information for the given IP address with cache support.

func (*CachedIPResolver) Size

func (c *CachedIPResolver) Size() int

Size returns the number of entries in the cache.

type City

type City struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

City represents the city from which the connection was originated.

type Client

type Client struct {
	IP    string `json:"ip"`
	GeoIP *GeoIP `json:"geoip,omitempty"`
}

Client capture details of the client connecting to the system.

type Continent

type Continent struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

Continent represents the continent from which the connection was originated.

type Country

type Country struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

Country represents the country from which the connection was originated.

type Details

type Details struct {
	Client Client `json:"client"`
}

Details represents the details of a network connection.

func FromContext

func FromContext(ctx context.Context) Details

FromContext extracts the network details from the context.

type GeoIP

type GeoIP struct {
	AS          AS          `json:"as"`
	Continent   Continent   `json:"continent"`
	Country     Country     `json:"country"`
	City        City        `json:"city"`
	Location    Location    `json:"location"`
	Subdivision Subdivision `json:"subdivision"`
	Timezone    string      `json:"timezone"`
}

GeoIP capture details of the location of the connection.

type IPResolver

type IPResolver interface {
	Resolve(ip string) GeoIP
}

IPResolver is capable of resolving geoip information from a given IP address.

Popular implementations may include Maxmind GeoIP and IP2Location.

NOTE: enriching GeoIP information is an expensive operation and should be used judiciously. It is recommended to only enrich the IP address and then use post-processing to enrich the log entries with GeoIP information. For example: https://www.elastic.co/guide/en/elasticsearch/reference/current/geoip-processor.html

type Location

type Location struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

Location represents GPS coordinates of the connection.

type Subdivision

type Subdivision struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

Subdivision represents a subdivision of a country.

Directories

Path Synopsis
geoip

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳