Improve instance management

This commit is contained in:
2025-07-18 22:39:06 +02:00
parent b0873d5629
commit a6c7b7250f
3 changed files with 94 additions and 17 deletions

View File

@@ -8,10 +8,35 @@ import (
)
type InstanceOptions struct {
Name string `json:"name,omitempty"`
Name string `json:"name,omitempty"` // Display name
// Auto restart
AutoRestart bool `json:"auto_restart,omitempty"`
MaxRestarts int `json:"max_restarts,omitempty"`
RestartDelay int `json:"restart_delay,omitempty"` // in seconds
*LlamaServerOptions
}
// UnmarshalJSON implements custom JSON unmarshaling with default values
func (o *InstanceOptions) UnmarshalJSON(data []byte) error {
// Set defaults first
o.AutoRestart = true
o.MaxRestarts = 3
o.RestartDelay = 5
// Create a temporary struct to avoid recursion
type tempInstanceOptions InstanceOptions
temp := (*tempInstanceOptions)(o)
// Unmarshal into the temporary struct
if err := json.Unmarshal(data, temp); err != nil {
return err
}
return nil
}
type LlamaServerOptions struct {
// Common params
VerbosePrompt bool `json:"verbose_prompt,omitempty"`