56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
renderformat "gitea.maximumdirect.net/eric/scriptorium/internal/format"
|
|
"go.maximumdirect.net/configkit"
|
|
)
|
|
|
|
// LoadOptions selects one application source and explicit configuration values.
|
|
type LoadOptions struct {
|
|
Path string
|
|
Explicit bool
|
|
Overlay string
|
|
Overrides []configkit.Override
|
|
}
|
|
|
|
// Load resolves one ConfigKit document and retains its inspection snapshot.
|
|
func Load(options LoadOptions) (*configkit.Result[Document], error) {
|
|
var source configkit.Source
|
|
if options.Explicit {
|
|
source = configkit.File(options.Path)
|
|
} else {
|
|
source = configkit.SearchConfig("scriptorium", configkit.SearchPaths(defaultConfigSearchPaths...))
|
|
}
|
|
|
|
result, err := configkit.Load(source, configkit.Options[Document]{
|
|
Definition: documentDefinition(),
|
|
Imports: true,
|
|
Overlay: options.Overlay,
|
|
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{
|
|
SchemaDir: document.SchemaDir,
|
|
ServerAddr: document.Server.Addr,
|
|
ArtifactRoot: document.Server.ArtifactRoot,
|
|
MaxRequestBytes: document.Server.MaxRequestBytes,
|
|
MaxArtifactBytes: document.Server.MaxArtifactBytes,
|
|
MaxResponseBytes: document.Server.MaxResponseBytes,
|
|
DefaultRenderFormat: renderformat.PreparedRunOutputFormat(document.Defaults.RenderFormat),
|
|
TransientRetries: document.TransientRetries,
|
|
}
|
|
if document.PromptKitSources != nil {
|
|
settings.PromptKitSources = append([]SourceSelection{}, document.PromptKitSources...)
|
|
}
|
|
return settings
|
|
}
|