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

Function SavePetScript

internal/pets/admin.go:73–93  ·  view source on GitHub ↗

SavePetScript writes (or removes) the JavaScript script file for a pet type.

(petType string, content string)

Source from the content-addressed store, hash-verified

71
72// SavePetScript writes (or removes) the JavaScript script file for a pet type.
73func SavePetScript(petType string, content string) error {
74 petType = strings.ToLower(strings.TrimSpace(petType))
75 p, ok := petTypes[petType]
76 if !ok {
77 return fmt.Errorf("pet type %q not found", petType)
78 }
79
80 scriptPath := p.GetScriptPath()
81
82 if content == "" {
83 if err := os.Remove(scriptPath); err != nil && !os.IsNotExist(err) {
84 return fmt.Errorf("removing pet script: %w", err)
85 }
86 return nil
87 }
88
89 if err := os.MkdirAll(filepath.Dir(scriptPath), os.ModePerm); err != nil {
90 return fmt.Errorf("creating pet scripts directory: %w", err)
91 }
92 return util.WriteFile(scriptPath, []byte(content), 0644)
93}

Callers 1

apiV1PutPetScriptFunction · 0.92

Calls 3

WriteFileFunction · 0.92
GetScriptPathMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected