diag

package
v0.0.0-...-33ef25c Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Info level is for informational messages
	Info = Level{2, "Info"}

	// Warning level is for warning messages
	Warning = Level{1, "Warning"}

	// Error level is for error messages
	Error = Level{0, "Error"}
)

Functions

func GetAllLevelStrings

func GetAllLevelStrings() []string

GetAllLevelStrings returns a list of strings representing the names of all Levels defined. The order is arbitrary but should be the same as GetAllLevels.

func GetUppercaseStringToLevelMap

func GetUppercaseStringToLevelMap() map[string]Level

GetUppercaseStringToLevelMap returns a mapping of uppercase strings to Level structs. This function is intended to be used to convert user input to structs.

func MockResource

func MockResource(name string) *resource.Instance

Types

type Level

type Level struct {
	// contains filtered or unexported fields
}

Level is the severity level of a message.

func GetAllLevels

func GetAllLevels() []Level

GetAllLevels returns an arbitrarily ordered slice of all Levels defined.

func (Level) IsWorseThanOrEqualTo

func (l Level) IsWorseThanOrEqualTo(target Level) bool

func (Level) String

func (l Level) String() string

type Message

type Message struct {
	Type *MessageType

	// The Parameters to the message
	Parameters []any

	// Resource is the underlying resource instance associated with the
	// message, or nil if no resource is associated with it.
	Resource *resource.Instance

	// DocRef is an optional reference tracker for the documentation URL
	DocRef string

	// Line is the line number of the error place in the message
	Line int
}

Message is a specific diagnostic message TODO: Implement using Analysis message API

func NewMessage

func NewMessage(mt *MessageType, r *resource.Instance, p ...any) Message

NewMessage returns a new Message instance from an existing type.

func (*Message) AnalysisMessageBase

func (m *Message) AnalysisMessageBase() *v1alpha1.AnalysisMessageBase

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the Marshaler interface

func (*Message) Origin

func (m *Message) Origin() string

Origin returns the origin of the message

func (Message) ReplaceLine

func (m Message) ReplaceLine(l string) string

ReplaceLine replaces the line number from the input String method of Reference to the line number from Message

func (*Message) String

func (m *Message) String() string

String implements io.Stringer

func (*Message) Unstructured

func (m *Message) Unstructured(includeOrigin bool) map[string]any

Unstructured returns this message as a JSON-style unstructured map

func (*Message) UnstructuredAnalysisMessageBase

func (m *Message) UnstructuredAnalysisMessageBase() map[string]any

UnstructuredAnalysisMessageBase returns this message as a JSON-style unstructured map in AnalaysisMessageBase TODO(jasonwzm): Remove once message implements AnalysisMessageBase

type MessageType

type MessageType struct {
	// contains filtered or unexported fields
}

MessageType is a type of diagnostic message

func NewMessageType

func NewMessageType(level Level, code, template string) *MessageType

NewMessageType returns a new MessageType instance.

func (*MessageType) Code

func (m *MessageType) Code() string

Code returns the code of the MessageType

func (*MessageType) Level

func (m *MessageType) Level() Level

Level returns the level of the MessageType

func (*MessageType) Template

func (m *MessageType) Template() string

Template returns the message template used by the MessageType

type Messages

type Messages []Message

Messages is a slice of Message items.

func (*Messages) Add

func (ms *Messages) Add(m ...Message)

Add a new message to the messages

func (*Messages) FilterOutLowerThan

func (ms *Messages) FilterOutLowerThan(outputLevel Level) Messages

FilterOutLowerThan only keeps messages at or above the specified output level

func (*Messages) SetDocRef

func (ms *Messages) SetDocRef(docRef string) *Messages

SetDocRef sets the doc URL reference tracker for the messages

func (*Messages) Sort

func (ms *Messages) Sort()

Sort the message lexicographically by level, code, resource origin name, then string.

func (*Messages) SortedDedupedCopy

func (ms *Messages) SortedDedupedCopy() Messages

SortedDedupedCopy returns a different sorted (and deduped) Messages struct.

Jump to

Keyboard shortcuts

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