mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-04 18:50:42 -06:00
[server][cmd] clean up debug flag
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func SetupCommand(debug bool) *cobra.Command {
|
||||
func SetupCommand() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "app",
|
||||
Short: "Server Administration",
|
||||
@@ -27,7 +27,7 @@ func SetupCommand(debug bool) *cobra.Command {
|
||||
if err := storage.Create(context.Background(), db.Default, viper.GetString("default_storage_dir")); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
if err := core.Create(context.Background(), db.Default, storage.Default, debug); err != nil {
|
||||
if err := core.Create(context.Background(), db.Default, storage.Default); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -23,7 +23,7 @@ func setupServeCommand() *cobra.Command {
|
||||
Short: "Run the server",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
config := viper.GetViper()
|
||||
engine := createEngine(config.GetBool("log_body"), config.GetBool("cors_enabled"), config.GetStringSlice("cors_origins"))
|
||||
engine := createEngine(config.GetBool("debug"), config.GetBool("log_body"), config.GetBool("cors_enabled"), config.GetStringSlice("cors_origins"))
|
||||
engine.Use(errors.RecoverApiError)
|
||||
|
||||
webdav.SetupHandler(engine.Group(config.GetString("webdav_prefix")), core.Default)
|
||||
@@ -60,8 +60,8 @@ func setupServeCommand() *cobra.Command {
|
||||
return cmdServe
|
||||
}
|
||||
|
||||
func createEngine(logBody bool, corsEnabled bool, corsOrigins []string) *gin.Engine {
|
||||
if !core.Default.Debug {
|
||||
func createEngine(debug, logBody bool, corsEnabled bool, corsOrigins []string) *gin.Engine {
|
||||
if !debug {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
engine := gin.New()
|
||||
@@ -72,7 +72,7 @@ func createEngine(logBody bool, corsEnabled bool, corsOrigins []string) *gin.Eng
|
||||
"msg": "Internal Server Error",
|
||||
})
|
||||
}))
|
||||
if core.Default.Debug && logBody {
|
||||
if debug && logBody {
|
||||
engine.Use(logBodyMiddleware)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var debug bool = false
|
||||
|
||||
func SetupCommand() {
|
||||
viper.SetEnvPrefix("phylum")
|
||||
|
||||
@@ -39,7 +37,7 @@ func SetupCommand() {
|
||||
os.Mkdir(workDir, 0750)
|
||||
os.Chdir(workDir)
|
||||
}
|
||||
debug = viper.GetBool("debug")
|
||||
debug := viper.GetBool("debug")
|
||||
if debug {
|
||||
logrus.Info("Running in debug mode")
|
||||
logrus.SetLevel(logrus.TraceLevel)
|
||||
@@ -59,7 +57,7 @@ func SetupCommand() {
|
||||
}()
|
||||
|
||||
rootCmd.AddCommand([]*cobra.Command{
|
||||
appcmd.SetupCommand(debug),
|
||||
appcmd.SetupCommand(),
|
||||
setupSchemaCommand(),
|
||||
}...)
|
||||
rootCmd.Execute()
|
||||
|
||||
@@ -14,7 +14,6 @@ const defaultUserUsername = "phylum"
|
||||
const defaultUserDisplayName = "Phylum"
|
||||
|
||||
type App struct {
|
||||
Debug bool
|
||||
Rootfs FileSystem
|
||||
db *db.DbHandler
|
||||
cs storage.Storage
|
||||
@@ -22,11 +21,10 @@ type App struct {
|
||||
|
||||
var Default *App
|
||||
|
||||
func Create(ctx context.Context, db *db.DbHandler, cs storage.Storage, debug bool) error {
|
||||
func Create(ctx context.Context, db *db.DbHandler, cs storage.Storage) error {
|
||||
Default = &App{
|
||||
Debug: debug,
|
||||
db: db,
|
||||
cs: cs,
|
||||
db: db,
|
||||
cs: cs,
|
||||
}
|
||||
|
||||
return Default.setupAppData(ctx)
|
||||
|
||||
Reference in New Issue
Block a user