mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-23 15:18:22 +00:00
init
This commit is contained in:
56
backend/cmd/configure/configure.go
Normal file
56
backend/cmd/configure/configure.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package configure
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/storage/database/dialect"
|
||||
)
|
||||
|
||||
var (
|
||||
// ConfigureCmd represents the config command
|
||||
ConfigureCmd = &cobra.Command{
|
||||
Use: "configure",
|
||||
Short: "Guides you through configuring Zitadel",
|
||||
// Long: `A longer description that spans multiple lines and likely contains examples
|
||||
// and usage of using your command. For example:
|
||||
|
||||
// Cobra is a CLI library for Go that empowers applications.
|
||||
// This application is a tool to generate the needed files
|
||||
// to quickly create a Cobra application.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("config called")
|
||||
fmt.Println(viper.AllSettings())
|
||||
fmt.Println(viper.Sub("database").AllSettings())
|
||||
pool, err := config.Database.Connect(cmd.Context())
|
||||
_, _ = pool, err
|
||||
},
|
||||
PreRun: ReadConfigPreRun[Config](viper.GetViper(), &config),
|
||||
}
|
||||
|
||||
config Config
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Here you will define your flags and configuration settings.
|
||||
ConfigureCmd.Flags().BoolVarP(&config.upgrade, "upgrade", "u", false, "Only changed configuration values since the previously used version will be asked for")
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// configureCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Database dialect.Config
|
||||
|
||||
upgrade bool
|
||||
}
|
||||
|
||||
func (c Config) Hooks() []viper.DecoderConfigOption {
|
||||
return c.Database.Hooks()
|
||||
}
|
26
backend/cmd/configure/read.go
Normal file
26
backend/cmd/configure/read.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package configure
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Unmarshaller interface {
|
||||
Hooks() []viper.DecoderConfigOption
|
||||
}
|
||||
|
||||
func ReadConfigPreRun[C Unmarshaller](v *viper.Viper, config *C) func(cmd *cobra.Command, args []string) {
|
||||
return func(cmd *cobra.Command, args []string) {
|
||||
if err := v.Unmarshal(config, (*config).Hooks()...); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ReadConfig[C Unmarshaller](v *viper.Viper) (*C, error) {
|
||||
var config C
|
||||
if err := v.Unmarshal(&config, config.Hooks()...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &config, nil
|
||||
}
|
23
backend/cmd/prepare/step_001.go
Normal file
23
backend/cmd/prepare/step_001.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package prepare
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/storage/database"
|
||||
"github.com/zitadel/zitadel/backend/storage/eventstore"
|
||||
)
|
||||
|
||||
type Step001 struct {
|
||||
Database database.Pool
|
||||
}
|
||||
|
||||
func (v *Step001) Migrate(ctx context.Context) error {
|
||||
conn, err := v.Database.Acquire(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Release(ctx)
|
||||
|
||||
eventstore.New(conn).
|
||||
return nil
|
||||
}
|
15
backend/cmd/start/config.go
Normal file
15
backend/cmd/start/config.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package start
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/storage/database/dialect"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Database dialect.Config
|
||||
}
|
||||
|
||||
func (c Config) Hooks() []viper.DecoderConfigOption {
|
||||
return c.Database.Hooks()
|
||||
}
|
Reference in New Issue
Block a user