Each of the four oversized files (training/store.go 1569 LOC, ucca/rules.go 1231 LOC, ucca_handlers.go 1135 LOC, document_export.go 1101 LOC) is split by logical group into same-package files, all under the 500-line hard cap. Zero behavior changes, no renamed exported symbols. Also fixed pre-existing hazard_library split (missing functions and duplicate UUID keys from a prior session). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
package iace
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// hazardUUID generates a deterministic UUID for a hazard library entry
|
|
// based on category and a 1-based index within that category.
|
|
func hazardUUID(category string, index int) uuid.UUID {
|
|
name := fmt.Sprintf("iace.hazard.%s.%d", category, index)
|
|
return uuid.NewSHA1(uuid.NameSpaceDNS, []byte(name))
|
|
}
|
|
|
|
// mustMarshalJSON marshals the given value to json.RawMessage, panicking on error.
|
|
// This is safe to use for static data known at compile time.
|
|
func mustMarshalJSON(v interface{}) json.RawMessage {
|
|
data, err := json.Marshal(v)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("hazard_library: failed to marshal JSON: %v", err))
|
|
}
|
|
return data
|
|
}
|
|
|
|
// GetBuiltinHazardLibrary returns the complete built-in hazard library with 40+
|
|
// template entries for SW/FW/KI hazards in industrial machines. These entries are
|
|
// intended to be seeded into the iace_hazard_library table during initial setup.
|
|
//
|
|
// All entries have IsBuiltin=true and TenantID=nil (system-level templates).
|
|
// UUIDs are deterministic, generated via uuid.NewSHA1 based on category and index.
|
|
func GetBuiltinHazardLibrary() []HazardLibraryEntry {
|
|
var all []HazardLibraryEntry
|
|
all = append(all, builtinHazardsAISW()...)
|
|
all = append(all, builtinHazardsSoftwareHMI()...)
|
|
all = append(all, builtinHazardsMachineSafety()...)
|
|
all = append(all, builtinHazardsISO12100Mechanical()...)
|
|
all = append(all, builtinHazardsISO12100ElectricalThermal()...)
|
|
all = append(all, builtinHazardsISO12100Pneumatic()...)
|
|
all = append(all, builtinHazardsISO12100Env()...)
|
|
return all
|
|
}
|