summaryrefslogtreecommitdiff
path: root/cmd/gotosocial/action
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/gotosocial/action')
-rw-r--r--cmd/gotosocial/action/admin/account/account.go19
-rw-r--r--cmd/gotosocial/action/admin/trans/export.go3
-rw-r--r--cmd/gotosocial/action/admin/trans/import.go3
-rw-r--r--cmd/gotosocial/action/debug/config/config.go22
-rw-r--r--cmd/gotosocial/action/server/server.go8
5 files changed, 31 insertions, 24 deletions
diff --git a/cmd/gotosocial/action/admin/account/account.go b/cmd/gotosocial/action/admin/account/account.go
index cdbe70c15..05f5a776b 100644
--- a/cmd/gotosocial/action/admin/account/account.go
+++ b/cmd/gotosocial/action/admin/account/account.go
@@ -24,7 +24,6 @@ import (
"fmt"
"time"
- "github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
@@ -41,7 +40,7 @@ var Create action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error creating dbservice: %s", err)
}
- username := viper.GetString(config.Keys.AdminAccountUsername)
+ username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
}
@@ -49,7 +48,7 @@ var Create action.GTSAction = func(ctx context.Context) error {
return err
}
- email := viper.GetString(config.Keys.AdminAccountEmail)
+ email := config.GetAdminAccountEmail()
if email == "" {
return errors.New("no email set")
}
@@ -57,7 +56,7 @@ var Create action.GTSAction = func(ctx context.Context) error {
return err
}
- password := viper.GetString(config.Keys.AdminAccountPassword)
+ password := config.GetAdminAccountPassword()
if password == "" {
return errors.New("no password set")
}
@@ -80,7 +79,7 @@ var Confirm action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error creating dbservice: %s", err)
}
- username := viper.GetString(config.Keys.AdminAccountUsername)
+ username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
}
@@ -115,7 +114,7 @@ var Promote action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error creating dbservice: %s", err)
}
- username := viper.GetString(config.Keys.AdminAccountUsername)
+ username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
}
@@ -147,7 +146,7 @@ var Demote action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error creating dbservice: %s", err)
}
- username := viper.GetString(config.Keys.AdminAccountUsername)
+ username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
}
@@ -179,7 +178,7 @@ var Disable action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error creating dbservice: %s", err)
}
- username := viper.GetString(config.Keys.AdminAccountUsername)
+ username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
}
@@ -217,7 +216,7 @@ var Password action.GTSAction = func(ctx context.Context) error {
return fmt.Errorf("error creating dbservice: %s", err)
}
- username := viper.GetString(config.Keys.AdminAccountUsername)
+ username := config.GetAdminAccountUsername()
if username == "" {
return errors.New("no username set")
}
@@ -225,7 +224,7 @@ var Password action.GTSAction = func(ctx context.Context) error {
return err
}
- password := viper.GetString(config.Keys.AdminAccountPassword)
+ password := config.GetAdminAccountPassword()
if password == "" {
return errors.New("no password set")
}
diff --git a/cmd/gotosocial/action/admin/trans/export.go b/cmd/gotosocial/action/admin/trans/export.go
index a6eb3f73b..2b5f82ee8 100644
--- a/cmd/gotosocial/action/admin/trans/export.go
+++ b/cmd/gotosocial/action/admin/trans/export.go
@@ -23,7 +23,6 @@ import (
"errors"
"fmt"
- "github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
@@ -39,7 +38,7 @@ var Export action.GTSAction = func(ctx context.Context) error {
exporter := trans.NewExporter(dbConn)
- path := viper.GetString(config.Keys.AdminTransPath)
+ path := config.GetAdminTransPath()
if path == "" {
return errors.New("no path set")
}
diff --git a/cmd/gotosocial/action/admin/trans/import.go b/cmd/gotosocial/action/admin/trans/import.go
index df7d32b69..75f2d6a5e 100644
--- a/cmd/gotosocial/action/admin/trans/import.go
+++ b/cmd/gotosocial/action/admin/trans/import.go
@@ -23,7 +23,6 @@ import (
"errors"
"fmt"
- "github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db/bundb"
@@ -39,7 +38,7 @@ var Import action.GTSAction = func(ctx context.Context) error {
importer := trans.NewImporter(dbConn)
- path := viper.GetString(config.Keys.AdminTransPath)
+ path := config.GetAdminTransPath()
if path == "" {
return errors.New("no path set")
}
diff --git a/cmd/gotosocial/action/debug/config/config.go b/cmd/gotosocial/action/debug/config/config.go
index 92f18bdfd..010907eab 100644
--- a/cmd/gotosocial/action/debug/config/config.go
+++ b/cmd/gotosocial/action/debug/config/config.go
@@ -23,17 +23,29 @@ import (
"encoding/json"
"fmt"
- "github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
)
// Config just prints the collated config out to stdout as json.
-var Config action.GTSAction = func(ctx context.Context) error {
- allSettings := viper.AllSettings()
- b, err := json.Marshal(&allSettings)
+var Config action.GTSAction = func(ctx context.Context) (err error) {
+ var raw map[string]interface{}
+
+ // Marshal configuration to a raw JSON map
+ config.Config(func(cfg *config.Configuration) {
+ raw, err = cfg.MarshalMap()
+ })
+ if err != nil {
+ return err
+ }
+
+ // Marshal map to JSON
+ b, err := json.Marshal(raw)
if err != nil {
return err
}
- fmt.Println(string(b))
+
+ // Print to stdout
+ fmt.Printf("%s\n", b)
return nil
}
diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go
index 709b3d481..f266331f2 100644
--- a/cmd/gotosocial/action/server/server.go
+++ b/cmd/gotosocial/action/server/server.go
@@ -29,7 +29,6 @@ import (
"codeberg.org/gruf/go-store/kv"
"codeberg.org/gruf/go-store/storage"
"github.com/sirupsen/logrus"
- "github.com/spf13/viper"
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/api/client/account"
@@ -107,7 +106,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
typeConverter := typeutils.NewConverter(dbService)
// Open the storage backend
- storageBasePath := viper.GetString(config.Keys.StorageLocalBasePath)
+ storageBasePath := config.GetStorageLocalBasePath()
storage, err := kv.OpenFile(storageBasePath, &storage.DiskConfig{
// Put the store lockfile in the storage dir itself.
// Normally this would not be safe, since we could end up
@@ -134,8 +133,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
// decide whether to create a noop email sender (won't send emails) or a real one
var emailSender email.Sender
- smtpHost := viper.GetString(config.Keys.SMTPHost)
- if smtpHost != "" {
+ if smtpHost := config.GetSMTPHost(); smtpHost != "" {
// host is defined so create a proper sender
emailSender, err = email.NewSender()
if err != nil {
@@ -239,7 +237,7 @@ var Start action.GTSAction = func(ctx context.Context) error {
}
// perform initial media prune in case value of MediaRemoteCacheDays changed
- if err := processor.AdminMediaPrune(ctx, viper.GetInt(config.Keys.MediaRemoteCacheDays)); err != nil {
+ if err := processor.AdminMediaPrune(ctx, config.GetMediaRemoteCacheDays()); err != nil {
return fmt.Errorf("error during initial media prune: %s", err)
}