support json schema
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user