chore: migrate to gitea
This commit is contained in:
37
cmd/root.go
37
cmd/root.go
@@ -1,12 +1,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"budget/ginserver"
|
||||
"budget/handler"
|
||||
"budget/internal/utils"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/ginserver"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/handler"
|
||||
"gitea.frenchtouch.duckdns.org/kratisto/budget-backend/internal/utils"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -47,7 +48,10 @@ var rootCmd = &cobra.Command{
|
||||
WithField(parameterDBConnectionURI, config.DBConnectionURI).
|
||||
Warn("Configuration")
|
||||
router := ginserver.NewRouter(config)
|
||||
router.Run(fmt.Sprintf(":%d", config.Port))
|
||||
err := router.Run(fmt.Sprintf(":%d", config.Port))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -64,19 +68,34 @@ func init() {
|
||||
rootCmd.PersistentFlags().StringVar(&cfgFile, parameterConfigurationFile, "", "Config file. All flags given in command line will override the values from this file.")
|
||||
|
||||
rootCmd.Flags().String(parameterLogLevel, defaultLogLevel, "Use this flag to set the logging level")
|
||||
viper.BindPFlag(parameterLogLevel, rootCmd.Flags().Lookup(parameterLogLevel))
|
||||
err := viper.BindPFlag(parameterLogLevel, rootCmd.Flags().Lookup(parameterLogLevel))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rootCmd.Flags().String(parameterLogFormat, defaultLogFormat, "Use this flag to set the logging format")
|
||||
viper.BindPFlag(parameterLogFormat, rootCmd.Flags().Lookup(parameterLogFormat))
|
||||
err = viper.BindPFlag(parameterLogFormat, rootCmd.Flags().Lookup(parameterLogFormat))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rootCmd.Flags().String(parameterDBConnectionURI, defaultDBConnectionURI, "Use this flag to set the db connection URI")
|
||||
viper.BindPFlag(parameterDBConnectionURI, rootCmd.Flags().Lookup(parameterDBConnectionURI))
|
||||
err = viper.BindPFlag(parameterDBConnectionURI, rootCmd.Flags().Lookup(parameterDBConnectionURI))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rootCmd.Flags().Int(parameterPort, defaultPort, "Use this flag to set the listening port of the api")
|
||||
viper.BindPFlag(parameterPort, rootCmd.Flags().Lookup(parameterPort))
|
||||
err = viper.BindPFlag(parameterPort, rootCmd.Flags().Lookup(parameterPort))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rootCmd.Flags().Bool(parameterMock, false, "Use this flag to enable the mock mode")
|
||||
viper.BindPFlag(parameterMock, rootCmd.Flags().Lookup(parameterMock))
|
||||
err = viper.BindPFlag(parameterMock, rootCmd.Flags().Lookup(parameterMock))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// initConfig reads in config file and ENV variables if set.
|
||||
|
||||
Reference in New Issue
Block a user