mirror of
https://github.com/wneessen/logranger.git
synced 2024-11-25 22:25:09 +01:00
Winni Neessen
80e30c6bda
The changes involved refactor and clean-up of variable names. This encompasses making the names more descriptive and meaningful to enhance the readability of the code. Accuracy of variable names in conveying their usage and purpose has been greatly improved. The changes span across multiple files, touching crucial components like the server, rulesets, connection, and configuration handling.
39 lines
1,002 B
Go
39 lines
1,002 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(netConn net.Conn) *Connection {
|
|
connection := &Connection{
|
|
conn: netConn,
|
|
id: NewConnectionID(),
|
|
rb: bufio.NewReader(netConn),
|
|
wb: bufio.NewWriter(netConn),
|
|
}
|
|
return connection
|
|
}
|
|
|
|
// 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())
|
|
}
|