summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/gotosocial/main.go58
-rw-r--r--cmd/server/server.go35
2 files changed, 62 insertions, 31 deletions
diff --git a/cmd/gotosocial/main.go b/cmd/gotosocial/main.go
index 78c7002a2..ffb7b9b8d 100644
--- a/cmd/gotosocial/main.go
+++ b/cmd/gotosocial/main.go
@@ -22,23 +22,69 @@ import (
"os"
"github.com/gotosocial/gotosocial/cmd/server"
+ "github.com/gotosocial/gotosocial/internal/consts"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
func main() {
+ flagNames := consts.GetFlagNames()
+ envNames := consts.GetEnvNames()
app := &cli.App{
Flags: []cli.Flag{
+ // GENERAL FLAGS
&cli.StringFlag{
- Name: "config",
- Aliases: []string{"c"},
- Usage: "Load configuration from `FILE`",
+ Name: flagNames.LogLevel,
+ Usage: "Log level to run at: debug, info, warn, fatal",
+ Value: "info",
+ EnvVars: []string{"GTS_LOG_LEVEL"},
},
&cli.StringFlag{
- Name: "log-level",
- Usage: "Log level to run at: debug, info, warn, fatal",
- Value: "info",
+ Name: flagNames.ApplicationName,
+ Usage: "Name of the application, used in various places internally",
+ Value: "gotosocial",
+ EnvVars: []string{envNames.ApplicationName},
+ Hidden: true,
+ },
+
+ // DATABASE FLAGS
+ &cli.StringFlag{
+ Name: flagNames.DbType,
+ Usage: "Database type: eg., postgres",
+ Value: "postgres",
+ EnvVars: []string{envNames.DbType},
+ },
+ &cli.StringFlag{
+ Name: flagNames.DbAddress,
+ Usage: "Database ipv4 address or hostname",
+ Value: "localhost",
+ EnvVars: []string{envNames.DbAddress},
+ },
+ &cli.IntFlag{
+ Name: flagNames.DbPort,
+ Usage: "Database port",
+ Value: 5432,
+ EnvVars: []string{envNames.DbPort},
+ },
+ &cli.StringFlag{
+ Name: flagNames.DbUser,
+ Usage: "Database username",
+ Value: "postgres",
+ EnvVars: []string{envNames.DbUser},
+ },
+ &cli.StringFlag{
+ Name: flagNames.DbPassword,
+ Usage: "Database password",
+ Value: "postgres",
+ EnvVars: []string{envNames.DbPassword},
+ FilePath: "./dbpass",
+ },
+ &cli.StringFlag{
+ Name: flagNames.DbDatabase,
+ Usage: "Database name",
+ Value: "postgres",
+ EnvVars: []string{envNames.DbDatabase},
},
},
Commands: []*cli.Command{
diff --git a/cmd/server/server.go b/cmd/server/server.go
index 4f2969993..bd16e1f84 100644
--- a/cmd/server/server.go
+++ b/cmd/server/server.go
@@ -25,43 +25,28 @@ import (
"os/signal"
"syscall"
+ "github.com/gotosocial/gotosocial/internal/config"
"github.com/gotosocial/gotosocial/internal/db"
- "github.com/sirupsen/logrus"
+ "github.com/gotosocial/gotosocial/internal/log"
"github.com/urfave/cli/v2"
)
-// getLog will try to set the logrus log level to the
-// desired level specified by the user with the --log-level flag
-func getLog(c *cli.Context) (*logrus.Logger, error) {
- log := logrus.New()
- logLevel, err := logrus.ParseLevel(c.String("log-level"))
- if err != nil {
- return nil, err
- }
- log.SetLevel(logLevel)
- return log, nil
-}
-
// Run starts the gotosocial server
func Run(c *cli.Context) error {
- log, err := getLog(c)
+ log, err := log.New(c.String("log-level"))
if err != nil {
return fmt.Errorf("error creating logger: %s", err)
}
- ctx := context.Background()
- dbConfig := &db.Config{
- Type: "POSTGRES",
- Address: "",
- Port: 5432,
- User: "",
- Password: "whatever",
- Database: "postgres",
- ApplicationName: "gotosocial",
+ var gtsConfig *config.Config
+ if gtsConfig, err = config.New(c.String("config")); err != nil {
+ return fmt.Errorf("error creating config: %s", err)
}
- dbService, err := db.NewService(ctx, dbConfig, log)
+
+ ctx := context.Background()
+ dbService, err := db.NewService(ctx, gtsConfig.DBConfig, log)
if err != nil {
- return err
+ return fmt.Errorf("error creating dbservice: %s", err)
}
// catch shutdown signals from the operating system