mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-24 00:08:14 +00:00
try chain
This commit is contained in:
1
backend/cmd/configure/bla5/generator.go
Normal file
1
backend/cmd/configure/bla5/generator.go
Normal file
@@ -0,0 +1 @@
|
||||
package bla5
|
@@ -3,7 +3,6 @@ package bla5
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -16,6 +15,8 @@ var Logger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
|
||||
|
||||
type Configure func() (value any, err error)
|
||||
|
||||
// Configurer should be implemented by each field of the configuration struct.
|
||||
// It is used to configure the value of the field.
|
||||
type Configurer interface {
|
||||
// Configure is called to configure the value.
|
||||
// It must return the same type as itself. Otherwise [Update] will panic because it is not able to set the value.
|
||||
@@ -24,51 +25,51 @@ type Configurer interface {
|
||||
|
||||
func Update(v *viper.Viper, config any) func(cmd *cobra.Command, args []string) {
|
||||
return func(cmd *cobra.Command, args []string) {
|
||||
value := reflect.ValueOf(config)
|
||||
structConfigures := structToConfigureMap(Logger, v, value)
|
||||
for key, configure := range structConfigures {
|
||||
result, err := configure()
|
||||
if err != nil {
|
||||
Logger.Error("error configuring field", slog.String("field", key), slog.Any("cause", err))
|
||||
return
|
||||
}
|
||||
value.Elem().FieldByName(key).Set(reflect.ValueOf(result))
|
||||
}
|
||||
// value := reflect.ValueOf(config)
|
||||
// structConfigures := structToConfigureMap(Logger, v, value)
|
||||
// for key, configure := range structConfigures {
|
||||
// result, err := configure()
|
||||
// if err != nil {
|
||||
// Logger.Error("error configuring field", slog.String("field", key), slog.Any("cause", err))
|
||||
// return
|
||||
// }
|
||||
// value.Elem().FieldByName(key).Set(reflect.ValueOf(result))
|
||||
// }
|
||||
|
||||
err := v.WriteConfig()
|
||||
if err != nil {
|
||||
Logger.Error("error writing config", slog.Any("cause", err))
|
||||
os.Exit(1)
|
||||
}
|
||||
// err := v.WriteConfig()
|
||||
// if err != nil {
|
||||
// Logger.Error("error writing config", slog.Any("cause", err))
|
||||
// os.Exit(1)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
func objectToFlow(l *slog.Logger, value reflect.Value) {
|
||||
if value.Kind() == reflect.Pointer {
|
||||
if value.IsNil() {
|
||||
value = reflect.New(value.Type().Elem())
|
||||
}
|
||||
value = value.Elem()
|
||||
}
|
||||
// func objectToFlow(l *slog.Logger, value reflect.Value) {
|
||||
// if value.Kind() == reflect.Pointer {
|
||||
// if value.IsNil() {
|
||||
// value = reflect.New(value.Type().Elem())
|
||||
// }
|
||||
// value = value.Elem()
|
||||
// }
|
||||
|
||||
typeOfValue := value.Type()
|
||||
for i := 0; i < value.NumField(); i++ {
|
||||
fieldValue := value.Field(i)
|
||||
fieldType := typeOfValue.Field(i)
|
||||
// typeOfValue := value.Type()
|
||||
// for i := 0; i < value.NumField(); i++ {
|
||||
// fieldValue := value.Field(i)
|
||||
// fieldType := typeOfValue.Field(i)
|
||||
|
||||
l.Info("Processing field", slog.String("field", fieldType.Name))
|
||||
}
|
||||
}
|
||||
// l.Info("Processing field", slog.String("field", fieldType.Name))
|
||||
// }
|
||||
// }
|
||||
|
||||
type field struct {
|
||||
set func(value reflect.Value) error
|
||||
}
|
||||
// type field struct {
|
||||
// set func(value reflect.Value) error
|
||||
// }
|
||||
|
||||
type structField struct {
|
||||
name string
|
||||
// type structField struct {
|
||||
// name string
|
||||
|
||||
fields []field
|
||||
}
|
||||
// fields []field
|
||||
// }
|
||||
|
||||
type primitiveField struct {
|
||||
}
|
||||
// type primitiveField struct {
|
||||
// }
|
||||
|
Reference in New Issue
Block a user