mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-01 06:36:38 +08:00
c0869cb878
补齐 Value/String/Bool/Int/Duration/Strings/WasSet/Origin 只读访问器与 按 secret 脱敏的 Entries 导出,新增 core.ConfigGet[T] 泛型读取入口,并用 编译期断言钉住 ConfigRegistry 对 ConfigExtension 的完整实现。
32 lines
779 B
Go
32 lines
779 B
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package core
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"Wavelet/core/extpoints"
|
|
)
|
|
|
|
// ConfigGet reads one resolved configuration value with its declared type. It is the
|
|
// generic counterpart of the fallback accessors on ConfigView, used when a caller must
|
|
// distinguish "unset" from "set to the zero value".
|
|
func ConfigGet[T any](view extpoints.ConfigView, key string) (T, error) {
|
|
var zero T
|
|
if view == nil {
|
|
return zero, extpoints.ErrConfigNotResolved
|
|
}
|
|
|
|
raw, ok := view.Value(key)
|
|
if !ok {
|
|
return zero, fmt.Errorf("%w: %s", extpoints.ErrConfigUnknownKey, key)
|
|
}
|
|
|
|
value, ok := raw.(T)
|
|
if !ok {
|
|
return zero, fmt.Errorf("%w: key %q holds %T, want %T", extpoints.ErrConfigType, key, raw, zero)
|
|
}
|
|
return value, nil
|
|
}
|