messagetype

package module
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: MIT Imports: 1 Imported by: 1

README

Message Type Package

Overview

The messagetype package provides functionality for classifying text messages into different types based on their content. This package is useful for categorizing log messages, user notifications, or any text content that needs to be displayed with appropriate styling or handling.

Message Types

The package defines the following message types:

  • Normal: Standard message with no specific classification
  • Info: Informational message
  • Error: Error message
  • Warning: Warning message
  • Success: Success/confirmation message

Usage

Import the package
import "github.com/cdvelop/messagetype"
Using the message type detection
message := "Failed to connect to database"
msgType := messagetype.DetectMessageType(message)

// msgType will be messagetype.Error

if msgType == messagetype.Error {
    // Handle error message
}

// Multiple arguments
msgType := messagetype.DetectMessageType("Processing", err, "Completed")
// Returns Error (highest priority)

Detection Logic

The DetectMessageType function analyzes the content of a message and categorizes it based on keywords:

  • Error messages: Contain keywords like "error", "failed", "exit status 1", "undeclared", "undefined", or "fatal"
  • Warning messages: Contain keywords like "warning" or "warn"
  • Info messages: Contain keywords like "info", "...", "starting", "initializing", or "success"
  • Normal messages: Default type for messages that don't match other categories

Dependencies

This package depends on:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Type added in v0.0.9

type Type uint8

Type represents the classification of message types in the system. Available types: - Normal (0): Standard message without special formatting - Info (1): Informational message usually displayed with distinct styling - Error (2): Error message indicating failures or critical issues - Warning (3): Warning message indicating potential issues - Success (4): Success or confirmation message

const (
	Normal  Type = iota // 0
	Info                // 1
	Error               // 2
	Warning             // 3
	Success             // 4
)

func DetectMessageType

func DetectMessageType(args ...any) Type

DetectMessageType detects the message type based on its content Accepts multiple arguments of any type, processing strings and errors

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL