bootloader.go RawHistoryFolder
1package bootloader
2
3import (
4 "errors"
5 "strconv"
6)
7
8// BootloaderType represents the bootloader implementation
9type BootloaderType int
10
11const (
12 // BootloaderTypeLimine is the Limine bootloader
13 BootloaderTypeLimine BootloaderType = iota
14)
15
16// String returns human-readable bootloader name
17func (b BootloaderType) String() string {
18 return "Limine"
19}
20
21// Bootloader is an immutable value object representing bootloader configuration
22type Bootloader struct {
23 bootType BootloaderType
24 timeout int // seconds
25 branding string
26 efiPath string
27}
28
29// NewBootloader creates a new Bootloader value object with validation
30func NewBootloader(bootType BootloaderType, timeoutSeconds int, branding string) (*Bootloader, error) {
31 // Validate timeout
32 if timeoutSeconds < 0 {
33 return nil, errors.New("bootloader timeout cannot be negative")
34 }
35
36 if timeoutSeconds > 600 {
37 return nil, errors.New("bootloader timeout cannot exceed 600 seconds")
38 }
39
40 // Validate branding
41 if branding == "" {
42 return nil, errors.New("bootloader branding cannot be empty")
43 }
44
45 if len(branding) > 64 {
46 return nil, errors.New("bootloader branding too long")
47 }
48
49 return &Bootloader{
50 bootType: bootType,
51 timeout: timeoutSeconds,
52 branding: branding,
53 efiPath: "/boot/efi",
54 }, nil
55}
56
57// Type returns the bootloader type
58func (b *Bootloader) Type() BootloaderType {
59 return b.bootType
60}
61
62// Timeout returns the bootloader timeout in seconds
63func (b *Bootloader) Timeout() int {
64 return b.timeout
65}
66
67// Branding returns the bootloader branding string
68func (b *Bootloader) Branding() string {
69 return b.branding
70}
71
72// EFIPath returns the EFI boot path
73func (b *Bootloader) EFIPath() string {
74 return b.efiPath
75}
76
77// IsLimine returns true if bootloader is Limine
78func (b *Bootloader) IsLimine() bool {
79 return b.bootType == BootloaderTypeLimine
80}
81
82// String returns human-readable representation
83func (b *Bootloader) String() string {
84 return "Bootloader(type=" + b.bootType.String() + ", timeout=" + strconv.Itoa(b.timeout) + "s)"
85}
86
87// Equals checks if two Bootloader objects are equal
88func (b *Bootloader) Equals(other *Bootloader) bool {
89 if other == nil {
90 return false
91 }
92 return b.bootType == other.bootType &&
93 b.timeout == other.timeout &&
94 b.branding == other.branding
95}