Documentation
¶
Index ¶
Constants ¶
const (
// LogErrKey is the keyword used in slog for error messages
LogErrKey = "error"
)
Variables ¶
var ErrCertConfigEmpty = errors.New("certificate and key paths are required for listener type: TLS")
ErrCertConfigEmpty is returned if a TLS listener is configured but ot certificate or key paths are set
Functions ¶
func NewConnectionID ¶
func NewConnectionID() string
NewConnectionID generates a new unique message ID using a random number generator and returns it as a hexadecimal string.
Types ¶
type Config ¶
type Config struct {
// Server holds server specific configuration values
Server struct {
PIDFile string `fig:"pid_file" default:"/var/run/logranger.pid"`
RuleFile string `fig:"rule_file" default:"etc/logranger.rules.toml"`
}
Listener struct {
ListenerUnix struct {
Path string `fig:"path" default:"/var/tmp/logranger.sock"`
} `fig:"unix"`
ListenerTCP struct {
Addr string `fig:"addr" default:"0.0.0.0"`
Port uint `fig:"port" default:"9099"`
} `fig:"tcp"`
ListenerTLS struct {
Addr string `fig:"addr" default:"0.0.0.0"`
Port uint `fig:"port" default:"9099"`
CertPath string `fig:"cert_path"`
KeyPath string `fig:"key_path"`
} `fig:"tls"`
Type ListenerType `fig:"type" default:"unix"`
} `fig:"listener"`
Log struct {
Level string `fig:"level" default:"info"`
Extended bool `fig:"extended"`
} `fig:"log"`
Parser struct {
Type string `fig:"type" validate:"required"`
Timeout time.Duration `fig:"timeout" default:"500ms"`
} `fig:"parser"`
// contains filtered or unexported fields
}
Config holds all the global configuration settings that are parsed by fig
func NewConfig ¶
NewConfig creates a new instance of the Config object by reading and loading configuration values. It takes in the file path and file name of the configuration file as parameters. It returns a pointer to the Config object and an error if there was a problem reading or loading the configuration.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection represents a connection to a network resource.
func NewConnection ¶
func NewConnection(netConn net.Conn) *Connection
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.
type ListenerType ¶
type ListenerType uint
ListenerType is an enumeration wrapper for the different listener types
const ( // ListenerUnix is a constant of type ListenerType that represents a UNIX listener. ListenerUnix ListenerType = iota // ListenerTCP is a constant representing the type of listener that uses TCP protocol. ListenerTCP // ListenerTLS is a constant of type ListenerType that represents a TLS listener. ListenerTLS )
func (ListenerType) String ¶
func (l ListenerType) String() string
String satisfies the fmt.Stringer interface for the ListenerType type
func (*ListenerType) UnmarshalString ¶
func (l *ListenerType) UnmarshalString(value string) error
UnmarshalString satisfies the fig.StringUnmarshaler interface for the ListenerType type
type Rule ¶
type Rule struct {
ID string `fig:"id" validate:"required"`
Regexp *regexp.Regexp `fig:"regexp" validate:"required"`
HostMatch *regexp.Regexp `fig:"host_match"`
Actions map[string]any `fig:"actions"`
}
Rule represents a rule with its properties.
type Ruleset ¶
type Ruleset struct {
Rule []Rule `fig:"rule"`
}
Ruleset represents a collection of rules.
func NewRuleset ¶
NewRuleset initializes a new Ruleset based on the provided Config. It reads the rule file specified in the Config, validates the file's existence, and loads the Ruleset using the fig library. It checks for duplicate rules and returns an error if any duplicates are found. If all operations are successful, it returns the created Ruleset and no error.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the main server struct
func (*Server) HandleConnection ¶
func (s *Server) HandleConnection(connection *Connection)
HandleConnection handles a single connection by parsing and processing log messages. It logs debug information about the connection and measures the processing time. It closes the connection when done, and logs any error encountered during the process.
func (*Server) Listen ¶
func (s *Server) Listen()
Listen handles incoming connections and processes log messages.
func (*Server) ReloadConfig ¶
ReloadConfig reloads the configuration of the Server with the specified path and filename. It creates a new Config using the NewConfig method and updates the Server's conf field. It also reloads the configured Ruleset. If an error occurs while reloading the configuration, an error is returned.
func (*Server) Run ¶
Run starts the logranger Server by creating a new listener using the NewListener method and calling RunWithListener with the obtained listener.
func (*Server) RunWithListener ¶
RunWithListener sets the listener for the server and performs some additional tasks for initializing the server. It creates a PID file, writes the process ID to the file, and listens for connections. It returns an error if any of the initialization steps fail.