Allow empty backend options

This commit is contained in:
2025-12-22 18:19:18 +01:00
parent 5062c882de
commit d9d7b6d814
2 changed files with 29 additions and 10 deletions

View File

@@ -56,13 +56,15 @@ func (o *Options) UnmarshalJSON(data []byte) error {
}
// Create backend from constructor map
if o.BackendOptions != nil {
constructor, exists := backendConstructors[o.BackendType]
if !exists {
return fmt.Errorf("unsupported backend type: %s", o.BackendType)
}
constructor, exists := backendConstructors[o.BackendType]
if !exists {
return fmt.Errorf("unsupported backend type: %s", o.BackendType)
}
backend := constructor()
backend := constructor()
// If backend_options is provided, unmarshal into the backend
if o.BackendOptions != nil {
optionsData, err := json.Marshal(o.BackendOptions)
if err != nil {
return fmt.Errorf("failed to marshal backend options: %w", err)
@@ -71,10 +73,11 @@ func (o *Options) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(optionsData, backend); err != nil {
return fmt.Errorf("failed to unmarshal backend options: %w", err)
}
// Store in the appropriate typed field for backward compatibility
o.setBackendOptions(backend)
}
// If backend_options is nil or empty, backend remains as empty struct (for router mode)
// Store in the appropriate typed field
o.setBackendOptions(backend)
return nil
}