mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-10 22:18:06 -06:00
[chore] Global server configuration overhaul (#575)
* move config flag names and usage to config package, rewrite config package to use global Configuration{} struct
Signed-off-by: kim <grufwub@gmail.com>
* improved code comment
Signed-off-by: kim <grufwub@gmail.com>
* linter
Signed-off-by: kim <grufwub@gmail.com>
* fix unmarshaling
Signed-off-by: kim <grufwub@gmail.com>
* remove kim's custom go compiler changes
Signed-off-by: kim <grufwub@gmail.com>
* generate setter and flag-name functions, implement these in codebase
Signed-off-by: kim <grufwub@gmail.com>
* update deps
Signed-off-by: kim <grufwub@gmail.com>
* small change
Signed-off-by: kim <grufwub@gmail.com>
* appease the linter...
Signed-off-by: kim <grufwub@gmail.com>
* move configuration into ConfigState structure, ensure reloading to/from viper settings to keep in sync
Signed-off-by: kim <grufwub@gmail.com>
* lint
Signed-off-by: kim <grufwub@gmail.com>
* update code comments
Signed-off-by: kim <grufwub@gmail.com>
* fix merge issue
Signed-off-by: kim <grufwub@gmail.com>
* fix merge issue
Signed-off-by: kim <grufwub@gmail.com>
* improved version string (removes time + go version)
Signed-off-by: kim <grufwub@gmail.com>
* fix version string build to pass test script + consolidate logic in func
Signed-off-by: kim <grufwub@gmail.com>
* add license text, update config.Defaults comment
Signed-off-by: kim <grufwub@gmail.com>
* add license text to generated config helpers file
Signed-off-by: kim <grufwub@gmail.com>
* defer unlock on config.Set___(), to ensure unlocked on panic
Signed-off-by: kim <grufwub@gmail.com>
* make it more obvious which cmd flags are being attached
Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
ae5402ada6
commit
43ac0cdb9c
90 changed files with 2450 additions and 1125 deletions
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
fmt.Println(string(b))
|
||||
|
||||
// Marshal map to JSON
|
||||
b, err := json.Marshal(raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Print to stdout
|
||||
fmt.Printf("%s\n", b)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue