priorityframeworks

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 0 Imported by: 0

README

Priority Frameworks

Go CI Go Lint Go SAST Go Report Card Docs Visualization License

Pluggable prioritization systems for Go applications.

Installation

go get github.com/grokify/priority-frameworks

Overview

This package provides a unified interface for working with different prioritization frameworks. Instead of hardcoding a single priority system, applications can allow users to choose the framework that fits their organization's practices.

Built-in Frameworks

Framework Levels Use Case
Severity Critical, High, Medium, Low, Informational Security, incidents, bugs
Priority (P#) P0, P1, P2, P3, P4 Engineering work prioritization
IETF RFC 2119 MUST, MUST NOT, SHOULD, SHOULD NOT, MAY Technical specifications
MoSCoW Must have, Should have, Could have, Won't have Agile, product management
General Required, Recommended, Optional, Avoid General-purpose requirement levels

Usage

import pf "github.com/grokify/priority-frameworks"

// Get a built-in framework (returns nil if not found)
framework := pf.Get("severity")
if framework == nil {
    log.Fatal("unknown framework")
}

// Parse a level (returns nil if not found)
level := framework.Parse("Critical")
if level == nil {
    log.Fatal("unknown level")
}
fmt.Println(level.Name)       // "Critical"
fmt.Println(level.Actionable) // true
fmt.Println(level.Color)      // "#7f1d1d"

// Compare levels within a framework
result := framework.Compare("critical", "low") // 1 (critical > low)

// Get highest/lowest priority levels
highest := framework.Highest() // Critical
lowest := framework.Lowest()   // Informational

// Get only actionable levels
actionable := framework.ActionableLevels()

// List all built-in frameworks
ids := pf.AllBuiltinIDs()    // ["severity", "priority", "ietf", "moscow", "general"]
frameworks := pf.All()       // []*Framework

Cross-Framework Normalization

Compare and map levels across different frameworks:

severity := pf.Severity()
moscow := pf.MoSCoW()

// Normalize to a common scale (1-4)
norm := pf.Normalize(severity, "critical") // NormalizedCritical (4)

// Compare across frameworks
result := pf.CompareAcross(severity, "critical", moscow, "must") // 0 (equal)

// Map a level to another framework
mapped := pf.MapTo(severity, "critical", moscow)
fmt.Println(mapped.Name) // "Must have"

Custom Frameworks

Create your own framework:

custom := &pf.Framework{
    ID:          "custom",
    Name:        "Custom Framework",
    Description: "My organization's priority system",
    Levels: []pf.Level{
        {ID: "urgent", Name: "Urgent", Actionable: true, Color: "#dc2626"},
        {ID: "normal", Name: "Normal", Actionable: true, Color: "#ca8a04"},
        {ID: "backlog", Name: "Backlog", Actionable: false, Color: "#6b7280"},
    },
}

Design

  • Position = Priority: Level position in the Levels slice determines priority (index 0 = highest)
  • Simple data types: Frameworks are plain structs, easily serializable to JSON/YAML
  • Actionable flag: Distinguishes between levels that require action vs. informational
  • Aliases: Multiple names can map to the same level (e.g., "CRITICAL", "Crit", "S1")

Contributing

Contributions are welcome. Please see the CHANGELOG for recent changes.

License

MIT - see LICENSE for details.

Documentation

Overview

Package priorityframeworks provides pluggable prioritization systems.

Built-in frameworks include Severity, Priority (P#), IETF RFC 2119, MoSCoW, and a General requirement framework. Users can choose which framework fits their organization's practices.

The position in the Levels slice implies priority order (index 0 = highest).

Index

Constants

View Source
const (
	IDSeverity = "severity"
	IDPriority = "priority"
	IDIETF     = "ietf"
	IDMoSCoW   = "moscow"
	IDGeneral  = "general"
)

FrameworkID constants for built-in frameworks.

Variables

This section is empty.

Functions

func AllBuiltinIDs

func AllBuiltinIDs() []string

AllBuiltinIDs returns all built-in framework IDs.

func CompareAcross

func CompareAcross(fA *Framework, levelA string, fB *Framework, levelB string) int

CompareAcross compares levels from potentially different frameworks. Returns: 1 if a > b (higher priority), -1 if a < b, 0 if equal.

Types

type Framework

type Framework struct {
	// ID is the unique identifier (e.g., "severity", "moscow").
	ID string `json:"id" yaml:"id"`

	// Name is the display name (e.g., "Severity", "MoSCoW").
	Name string `json:"name" yaml:"name"`

	// Description explains when to use this framework.
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// Levels are ordered from highest to lowest priority.
	// Index 0 is the highest priority level.
	Levels []Level `json:"levels" yaml:"levels"`
}

Framework represents a prioritization system with ordered levels.

func All

func All() []*Framework

All returns all built-in frameworks.

func General

func General() *Framework

General returns a general-purpose requirement framework. Simple Required/Recommended/Optional/Avoid levels.

func Get

func Get(id string) *Framework

Get returns a built-in framework by ID. Returns nil if not found.

func IETF

func IETF() *Framework

IETF returns the IETF RFC 2119 framework. Standard for requirement specification in technical documents. Ordered by implementation priority: actions to take, then actions to avoid.

func MoSCoW

func MoSCoW() *Framework

MoSCoW returns the MoSCoW framework (Must/Should/Could/Won't). Common in agile and product management.

func Priority

func Priority() *Framework

Priority returns the Priority framework (P0/P1/P2/P3/P4). Common in engineering teams for work prioritization.

func Severity

func Severity() *Framework

Severity returns the Severity framework (Critical/High/Medium/Low/Informational). Common in security, incident response, and bug tracking.

func (*Framework) ActionableLevels

func (f *Framework) ActionableLevels() []Level

ActionableLevels returns only levels where Actionable is true.

func (*Framework) Compare

func (f *Framework) Compare(a, b string) int

Compare compares two level identifiers within this framework. Returns: 1 if a > b (higher priority), -1 if a < b, 0 if equal. Returns 0 if either level is not found.

func (*Framework) Default

func (f *Framework) Default() *Level

Default returns the default level (middle of the range).

func (*Framework) Highest

func (f *Framework) Highest() *Level

Highest returns the highest priority level (index 0).

func (*Framework) IndexOf

func (f *Framework) IndexOf(idOrName string) int

IndexOf returns the index of the level with the given ID or name. Returns -1 if not found.

func (*Framework) Lowest

func (f *Framework) Lowest() *Level

Lowest returns the lowest priority level (last index).

func (*Framework) Parse

func (f *Framework) Parse(s string) *Level

Parse returns the Level matching the given string (ID, Name, or Alias). Returns nil if not found.

type Level

type Level struct {
	// ID is the canonical identifier (e.g., "critical", "must", "p0").
	ID string `json:"id" yaml:"id"`

	// Name is the display name (e.g., "Critical", "MUST", "P0").
	Name string `json:"name" yaml:"name"`

	// Aliases are alternative names that parse to this level.
	Aliases []string `json:"aliases,omitempty" yaml:"aliases,omitempty"`

	// Actionable indicates whether items at this level require action.
	// For example, "Critical" and "Must have" are actionable; "Informational" is not.
	Actionable bool `json:"actionable" yaml:"actionable"`

	// Color is the suggested display color (hex code).
	Color string `json:"color,omitempty" yaml:"color,omitempty"`
}

Level represents a single priority level within a framework.

func MapTo

func MapTo(src *Framework, srcLevel string, dst *Framework) *Level

MapTo maps a level from one framework to the closest equivalent in another. Returns nil if the source level is not found.

type NormalizedPriority

type NormalizedPriority int

NormalizedPriority represents a normalized priority bucket (1-4). This allows comparison across different frameworks.

const (
	NormalizedCritical NormalizedPriority = 4 // Highest
	NormalizedHigh     NormalizedPriority = 3
	NormalizedMedium   NormalizedPriority = 2
	NormalizedLow      NormalizedPriority = 1 // Lowest
)

func Normalize

func Normalize(f *Framework, levelID string) NormalizedPriority

Normalize converts a level index to a normalized priority (1-4). This enables sorting and comparison across different frameworks.

The normalization maps the level's position in the framework to one of four buckets: Critical (4), High (3), Medium (2), Low (1).

func NormalizeIndex

func NormalizeIndex(index, total int) NormalizedPriority

NormalizeIndex converts a level index and total count to normalized priority.

func (NormalizedPriority) String

func (p NormalizedPriority) String() string

String returns the display name for the normalized priority.

Jump to

Keyboard shortcuts

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