mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 07:22:24 -05:00
further yak shaving
This commit is contained in:
parent
b8e0f33c35
commit
54c4b8de20
9 changed files with 282 additions and 39 deletions
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue