Documentation
¶
Index ¶
- func AddToContext(ctx context.Context, d Details) context.Context
- func Decorator(inner auditrail.Logger, ipr IPResolver) auditrail.Logger
- func EchoMiddleware(next echo.HandlerFunc) echo.HandlerFunc
- func GRPCStreamInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, ...) error
- func GRPCUnaryInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func GinMiddleware(c *gin.Context)
- type AS
- type CachedIPResolver
- type City
- type Client
- type Continent
- type Country
- type Details
- type GeoIP
- type IPResolver
- type Location
- type Subdivision
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddToContext ¶
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 ¶
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) 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 Details ¶
type Details struct {
Client Client `json:"client"`
}
Details represents the details of a network connection.
func FromContext ¶
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 ¶
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 Subdivision ¶
Subdivision represents a subdivision of a country.