feat: init sproutclaw-web — Go+Gin backend + React frontend
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
28
backend/internal/services/models_config.go
Normal file
28
backend/internal/services/models_config.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
// ReadModelsConfig reads models.json as a raw string.
|
||||
func ReadModelsConfig(path string) (string, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if os.IsNotExist(err) {
|
||||
return "{}", nil
|
||||
}
|
||||
return string(data), err
|
||||
}
|
||||
|
||||
// WriteModelsConfig validates JSON and writes models.json.
|
||||
func WriteModelsConfig(path, content string) error {
|
||||
var v any
|
||||
if err := json.Unmarshal([]byte(content), &v); err != nil {
|
||||
return err
|
||||
}
|
||||
pretty, err := json.MarshalIndent(v, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, append(pretty, '\n'), 0o644)
|
||||
}
|
||||
Reference in New Issue
Block a user