2026-09-26 18:00:50 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2026-11-17 22:00:43 +00:00
|
|
|
"go.maximumdirect.net/configkit"
|
2026-09-26 18:00:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// LoadOptions selects one application source and explicit configuration values.
|
|
|
|
|
type LoadOptions struct {
|
|
|
|
|
Path string
|
|
|
|
|
Explicit bool
|
|
|
|
|
Overlay string
|
|
|
|
|
Overrides []configkit.Override
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-20 04:26:17 +00:00
|
|
|
var applicationSearch = configkit.Searches(
|
|
|
|
|
configkit.WorkingDirectory(), configkit.UserConfigDirectory(),
|
|
|
|
|
configkit.HomeDirectory(), configkit.UnixSystemDirectories(),
|
|
|
|
|
)
|
|
|
|
|
|
2026-09-26 18:08:36 +00:00
|
|
|
// Load resolves one ConfigKit document and retains its inspection snapshot.
|
2026-09-26 18:00:50 +00:00
|
|
|
func Load(options LoadOptions) (*configkit.Result[Document], error) {
|
|
|
|
|
var source configkit.Source
|
|
|
|
|
if options.Explicit {
|
|
|
|
|
source = configkit.File(options.Path)
|
|
|
|
|
} else {
|
2026-11-20 04:26:17 +00:00
|
|
|
source = configkit.SearchConfig("scriptorium", applicationSearch)
|
2026-09-26 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := configkit.Load(source, configkit.Options[Document]{
|
|
|
|
|
Definition: documentDefinition(),
|
2026-11-17 22:00:43 +00:00
|
|
|
Imports: true,
|
2026-09-26 18:12:27 +00:00
|
|
|
Overlay: options.Overlay,
|
2026-09-26 18:00:50 +00:00
|
|
|
Overrides: options.Overrides,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("load application configuration: %w", err)
|
|
|
|
|
}
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Settings converts a validated document without another merge or normalization.
|
|
|
|
|
func Settings(document Document) AppSettings {
|
|
|
|
|
settings := AppSettings{
|
2026-11-20 04:26:17 +00:00
|
|
|
SchemaDir: document.PromptKit.SchemaDir,
|
|
|
|
|
PromptKitConfiguration: document.PromptKit.Configuration,
|
|
|
|
|
ServerAddr: document.Server.Addr,
|
|
|
|
|
ArtifactRoot: document.Server.ArtifactRoot,
|
|
|
|
|
MaxRequestBytes: document.Server.MaxRequestBytes,
|
|
|
|
|
MaxArtifactBytes: document.Server.MaxArtifactBytes,
|
|
|
|
|
MaxResponseBytes: document.Server.MaxResponseBytes,
|
|
|
|
|
TransientRetries: document.TransientRetries,
|
2026-09-26 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
return settings
|
|
|
|
|
}
|