support json schema

This commit is contained in:
2025-03-22 14:02:39 -04:00
parent f0a699029a
commit 3e319b24fd
10 changed files with 82 additions and 36 deletions

View File

@ -19,7 +19,7 @@ import (
// are up to the caller.
func MustLoadConfigInto[T any](ctx context.Context, into T) (context.Context, T) {
// Step 1: Check our custom type for required *config.AppConfig
if err := hasAppConfig(into); err != nil {
if err := HasAppConfig(into); err != nil {
panic(err)
}
@ -66,7 +66,7 @@ func setAppConfig[T any](target T, appConfig *config.AppConfig) error {
}
// Replace *config.AppConfig
for i := 0; i < v.NumField(); i++ {
for i := range v.NumField() {
field := v.Field(i)
if field.Type() == reflect.TypeOf((*config.AppConfig)(nil)) {
if !field.CanSet() {
@ -80,7 +80,7 @@ func setAppConfig[T any](target T, appConfig *config.AppConfig) error {
return errors.New("no *config.AppConfig field found in target struct")
}
func hasAppConfig[T any](target T) error {
func HasAppConfig[T any](target T) error {
v := reflect.ValueOf(target)
if v.Kind() != reflect.Ptr || v.IsNil() {
return errors.New("target must be a non-nil pointer to a struct")
@ -92,7 +92,7 @@ func hasAppConfig[T any](target T) error {
}
hasAppConfig := false
for i := 0; i < v.NumField(); i++ {
for i := range v.NumField() {
field := v.Type().Field(i)
if field.Type == reflect.TypeOf((*config.AppConfig)(nil)) {
hasAppConfig = true