mirror of
https://github.com/wneessen/logranger.git
synced 2024-11-25 14:20:49 +01:00
Winni Neessen
b6f6b6a664
Introduced an Actions interface for plugins in 'action.go' and implemented a corresponding registry in 'registry.go'. Additionally, adjusted rule related behavior in 'Server' to account for actions, with relevant new fields in Ruleset and Rule. This enables multiple actions on a log message based on defined rules and further modularises the codebase, paving the path for addition of more plugin actions.
39 lines
964 B
Go
39 lines
964 B
Go
// SPDX-FileCopyrightText: 2023 Winni Neessen <wn@neessen.dev>
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package logranger
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"math/rand"
|
|
"net"
|
|
)
|
|
|
|
// Connection represents a connection to a network resource.
|
|
type Connection struct {
|
|
conn net.Conn
|
|
id string
|
|
rb *bufio.Reader
|
|
wb *bufio.Writer
|
|
}
|
|
|
|
// NewConnection creates a new Connection object with the provided net.Conn.
|
|
// The Connection object holds a reference to the provided net.Conn, along with an ID string,
|
|
// bufio.Reader, and bufio.Writer. It returns a pointer to the created Connection object.
|
|
func NewConnection(nc net.Conn) *Connection {
|
|
c := &Connection{
|
|
conn: nc,
|
|
id: NewConnectionID(),
|
|
rb: bufio.NewReader(nc),
|
|
wb: bufio.NewWriter(nc),
|
|
}
|
|
return c
|
|
}
|
|
|
|
// NewConnectionID generates a new unique message ID using a random number generator
|
|
// and returns it as a hexadecimal string.
|
|
func NewConnectionID() string {
|
|
return fmt.Sprintf("%x", rand.Int63())
|
|
}
|