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
- Variables
- func AllBuiltinIDs() []string
- func CompareAcross(fA *Framework, levelA string, fB *Framework, levelB string) int
- type Framework
- type Level
- type LevelCounts
- func (lc *LevelCounts) ActionableTotal() int
- func (lc *LevelCounts) Add(levelID string, count int)
- func (lc *LevelCounts) Clone() *LevelCounts
- func (lc *LevelCounts) Get(levelID string) int
- func (lc *LevelCounts) HigherThan(levelID string) int
- func (lc *LevelCounts) HigherThanOrEqual(levelID string) int
- func (lc *LevelCounts) Increment(levelID string)
- func (lc *LevelCounts) IsEmpty() bool
- func (lc *LevelCounts) LowerThan(levelID string) int
- func (lc *LevelCounts) Merge(other *LevelCounts)
- func (lc *LevelCounts) Reset()
- func (lc *LevelCounts) Slice() []int
- func (lc *LevelCounts) Total() int
- type NormalizedPriority
- type RangeEntry
- type ScoreRange
Constants ¶
const ( IDSeverity = "severity" IDPriority = "priority" IDIETF = "ietf" IDIETFProhibitions = "ietf-prohibitions" IDMoSCoW = "moscow" IDGeneral = "general" )
FrameworkID constants for built-in frameworks.
Variables ¶
var ErrScoreOutOfRange = errors.New("score out of range")
ErrScoreOutOfRange is returned when a score is outside the defined ranges.
Functions ¶
func AllBuiltinIDs ¶
func AllBuiltinIDs() []string
AllBuiltinIDs returns all built-in framework IDs.
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 General ¶
func General() *Framework
General returns a general-purpose requirement framework. Simple Required/Recommended/Optional/Avoid levels.
func IETF ¶
func IETF() *Framework
IETF returns the IETF RFC 2119 requirements framework (MUST/SHOULD/MAY). Use this for prioritizing requirements - what to implement. For prohibitions (MUST NOT/SHOULD NOT), use IETFProhibitions().
func IETFProhibitions ¶ added in v0.2.0
func IETFProhibitions() *Framework
IETFProhibitions returns the IETF RFC 2119 prohibitions framework (MUST NOT/SHOULD NOT). Use this for compliance checking - constraints to validate against. For requirements (MUST/SHOULD/MAY), use IETF().
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 ¶
ActionableLevels returns only levels where Actionable is true.
func (*Framework) Compare ¶
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) IndexOf ¶
IndexOf returns the index of the level with the given ID or name. Returns -1 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.
type LevelCounts ¶ added in v0.2.0
type LevelCounts struct {
// Framework is the associated framework (optional, for validation).
Framework *Framework
// Counts maps level IDs to their count.
Counts map[string]int
}
LevelCounts tracks counts of items at each priority level. This is useful for dashboards, reports, and aggregations.
func NewLevelCounts ¶ added in v0.2.0
func NewLevelCounts(f *Framework) *LevelCounts
NewLevelCounts creates a new LevelCounts for the given framework. If framework is provided, initializes all levels to zero.
func (*LevelCounts) ActionableTotal ¶ added in v0.2.0
func (lc *LevelCounts) ActionableTotal() int
ActionableTotal returns the sum of counts for actionable levels only. Requires Framework to be set; returns 0 if Framework is nil.
func (*LevelCounts) Add ¶ added in v0.2.0
func (lc *LevelCounts) Add(levelID string, count int)
Add increments the count for the given level ID. If the level doesn't exist in the map, it's created with count 1.
func (*LevelCounts) Clone ¶ added in v0.2.0
func (lc *LevelCounts) Clone() *LevelCounts
Clone returns a deep copy of the LevelCounts.
func (*LevelCounts) Get ¶ added in v0.2.0
func (lc *LevelCounts) Get(levelID string) int
Get returns the count for the given level ID. Returns 0 if the level is not found.
func (*LevelCounts) HigherThan ¶ added in v0.2.0
func (lc *LevelCounts) HigherThan(levelID string) int
HigherThan returns the sum of counts for levels higher than the given level. Requires Framework to be set; returns 0 if Framework is nil.
func (*LevelCounts) HigherThanOrEqual ¶ added in v0.2.0
func (lc *LevelCounts) HigherThanOrEqual(levelID string) int
HigherThanOrEqual returns the sum of counts for levels >= the given level. Requires Framework to be set; returns 0 if Framework is nil.
func (*LevelCounts) Increment ¶ added in v0.2.0
func (lc *LevelCounts) Increment(levelID string)
Increment adds 1 to the count for the given level ID.
func (*LevelCounts) IsEmpty ¶ added in v0.2.0
func (lc *LevelCounts) IsEmpty() bool
IsEmpty returns true if all counts are zero.
func (*LevelCounts) LowerThan ¶ added in v0.2.0
func (lc *LevelCounts) LowerThan(levelID string) int
LowerThan returns the sum of counts for levels lower than the given level. Requires Framework to be set; returns 0 if Framework is nil.
func (*LevelCounts) Merge ¶ added in v0.2.0
func (lc *LevelCounts) Merge(other *LevelCounts)
Merge adds counts from another LevelCounts.
func (*LevelCounts) Reset ¶ added in v0.2.0
func (lc *LevelCounts) Reset()
Reset sets all counts to zero.
func (*LevelCounts) Slice ¶ added in v0.2.0
func (lc *LevelCounts) Slice() []int
Slice returns counts in framework level order. Requires Framework to be set; returns nil if Framework is nil.
func (*LevelCounts) Total ¶ added in v0.2.0
func (lc *LevelCounts) Total() int
Total returns the sum of all counts.
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.
type RangeEntry ¶ added in v0.2.0
type RangeEntry struct {
// LevelID is the framework level this range maps to.
LevelID string
// MinScore is the minimum score (inclusive) for this level.
MinScore float64
}
RangeEntry defines a minimum score threshold for a level.
type ScoreRange ¶ added in v0.2.0
type ScoreRange struct {
// Framework is the target framework for level lookups.
Framework *Framework
// Ranges defines the score thresholds for each level.
// Each entry maps a level ID to its minimum score (inclusive).
// Levels are evaluated from highest to lowest score.
Ranges []RangeEntry
// Min is the minimum valid score (inclusive).
Min float64
// Max is the maximum valid score (inclusive).
Max float64
}
ScoreRange maps numeric score ranges to framework levels. This enables conversion from scoring systems (like CVSS) to priority levels.
func CVSSScoreRange ¶ added in v0.2.0
func CVSSScoreRange() *ScoreRange
CVSSScoreRange returns a ScoreRange for CVSS v3 scores mapped to Severity levels. CVSS ranges: None (0), Low (0.1-3.9), Medium (4.0-6.9), High (7.0-8.9), Critical (9.0-10.0)
func PercentageScoreRange ¶ added in v0.2.0
func PercentageScoreRange(f *Framework) *ScoreRange
PercentageScoreRange returns a ScoreRange for percentage scores (0-100) mapped to a 4-level framework using quartiles.
func (*ScoreRange) LevelFromScore ¶ added in v0.2.0
func (sr *ScoreRange) LevelFromScore(score float64) (*Level, error)
LevelFromScore returns the level for the given score. Returns nil and ErrScoreOutOfRange if score is outside Min/Max bounds. Returns nil if no matching range is found.
func (*ScoreRange) MustLevelFromScore ¶ added in v0.2.0
func (sr *ScoreRange) MustLevelFromScore(score float64) *Level
MustLevelFromScore returns the level for the given score. Panics if score is out of range. Returns nil if no match found.