MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / SavePanelLayout

Function SavePanelLayout

internal/templates/panel.go:622–641  ·  view source on GitHub ↗

SavePanelLayout writes yamlData to the panel layout file for the given name. name is relative to panel-layouts/ without the .yaml extension. The file must already exist; this function does not create new layout files.

(name, yamlData string)

Source from the content-addressed store, hash-verified

620// name is relative to panel-layouts/ without the .yaml extension.
621// The file must already exist; this function does not create new layout files.
622func SavePanelLayout(name, yamlData string) error {
623 dataFiles := string(configs.GetFilePathsConfig().DataFiles)
624 path := dataFiles + "/panel-layouts/" + name + ".yaml"
625
626 // Verify the file exists before overwriting.
627 if _, err := os.Stat(path); err != nil {
628 return fmt.Errorf("panel layout %q: %w", name, err)
629 }
630
631 // Validate the YAML parses correctly before writing.
632 var def panelLayoutDef
633 if err := yaml.Unmarshal([]byte(yamlData), &def); err != nil {
634 return fmt.Errorf("panel layout %q: invalid YAML: %w", name, err)
635 }
636
637 if err := os.WriteFile(path, []byte(yamlData), 0644); err != nil {
638 return fmt.Errorf("panel layout %q: %w", name, err)
639 }
640 return nil
641}
642
643// LoadPanelLayout loads a panel layout definition from the datafiles directory.
644// name is relative to the panel-layouts/ subdirectory and has no extension.

Callers 1

apiV1PutPanelFunction · 0.92

Calls 2

GetFilePathsConfigFunction · 0.92
StatMethod · 0.45

Tested by

no test coverage detected