messagetype

package module
v0.0.62 Latest Latest
Warning

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

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

README

Message Type Package

Project Badges

⚠️ This library is no longer maintained and will be archived. All functionality has been moved to github.com/cdvelop/tinystring.

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)
Using helper methods for type checking

The package provides convenient helper methods for checking message types:

message := "Starting application..."
msgType := messagetype.DetectMessageType(message)

// Using helper methods (recommended)
if msgType.IsInfo() {
    println("This is an informational message")
}

if msgType.IsError() {
    println("This is an error message")
}

if msgType.IsWarning() {
    println("This is a warning message")
}

if msgType.IsSuccess() {
    println("This is a success message")
}

if msgType.IsNormal() {
    println("This is a normal message")
}

// Get string representation
println("Message type:", msgType.String())
Available helper methods
  • IsNormal() - Returns true if the message type is Normal
  • IsInfo() - Returns true if the message type is Info
  • IsError() - Returns true if the message type is Error
  • IsWarning() - Returns true if the message type is Warning
  • IsSuccess() - Returns true if the message type is Success
  • String() - Returns a string representation of the message type

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

func (Type) IsError added in v0.0.40

func (t Type) IsError() bool

IsError returns true if the message type is Error

func (Type) IsInfo added in v0.0.40

func (t Type) IsInfo() bool

IsInfo returns true if the message type is Info

func (Type) IsNormal added in v0.0.40

func (t Type) IsNormal() bool

IsNormal returns true if the message type is Normal

func (Type) IsSuccess added in v0.0.40

func (t Type) IsSuccess() bool

IsSuccess returns true if the message type is Success

func (Type) IsWarning added in v0.0.40

func (t Type) IsWarning() bool

IsWarning returns true if the message type is Warning

func (Type) String added in v0.0.40

func (t Type) String() string

String returns a string representation of the message type

Jump to

Keyboard shortcuts

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