mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-22 06:57:29 -06:00
biiiiig refactor
This commit is contained in:
parent
90b1c94b89
commit
1ec22fe52c
151 changed files with 3231 additions and 4556 deletions
|
|
@ -37,7 +37,7 @@ import (
|
|||
"github.com/google/uuid"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/util"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
|
@ -46,14 +46,14 @@ import (
|
|||
type postgresService struct {
|
||||
config *config.Config
|
||||
conn *pg.DB
|
||||
log *logrus.Entry
|
||||
log *logrus.Logger
|
||||
cancel context.CancelFunc
|
||||
federationDB pub.Database
|
||||
}
|
||||
|
||||
// newPostgresService returns a postgresService derived from the provided config, which implements the go-fed DB interface.
|
||||
// NewPostgresService returns a postgresService derived from the provided config, which implements the go-fed DB interface.
|
||||
// Under the hood, it uses https://github.com/go-pg/pg to create and maintain a database connection.
|
||||
func newPostgresService(ctx context.Context, c *config.Config, log *logrus.Entry) (DB, error) {
|
||||
func NewPostgresService(ctx context.Context, c *config.Config, log *logrus.Logger) (DB, error) {
|
||||
opts, err := derivePGOptions(c)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create postgres service: %s", err)
|
||||
|
|
@ -67,7 +67,7 @@ func newPostgresService(ctx context.Context, c *config.Config, log *logrus.Entry
|
|||
// this will break the logfmt format we normally log in,
|
||||
// since we can't choose where pg outputs to and it defaults to
|
||||
// stdout. So use this option with care!
|
||||
if log.Logger.GetLevel() >= logrus.TraceLevel {
|
||||
if log.GetLevel() >= logrus.TraceLevel {
|
||||
conn.AddQueryHook(pgdebug.DebugHook{
|
||||
// Print all queries.
|
||||
Verbose: true,
|
||||
|
|
@ -95,7 +95,7 @@ func newPostgresService(ctx context.Context, c *config.Config, log *logrus.Entry
|
|||
cancel: cancel,
|
||||
}
|
||||
|
||||
federatingDB := newFederatingDB(ps, c, log)
|
||||
federatingDB := NewFederatingDB(ps, c, log)
|
||||
ps.federationDB = federatingDB
|
||||
|
||||
// we can confidently return this useable postgres service now
|
||||
|
|
@ -109,8 +109,8 @@ func newPostgresService(ctx context.Context, c *config.Config, log *logrus.Entry
|
|||
// derivePGOptions takes an application config and returns either a ready-to-use *pg.Options
|
||||
// with sensible defaults, or an error if it's not satisfied by the provided config.
|
||||
func derivePGOptions(c *config.Config) (*pg.Options, error) {
|
||||
if strings.ToUpper(c.DBConfig.Type) != dbTypePostgres {
|
||||
return nil, fmt.Errorf("expected db type of %s but got %s", dbTypePostgres, c.DBConfig.Type)
|
||||
if strings.ToUpper(c.DBConfig.Type) != DBTypePostgres {
|
||||
return nil, fmt.Errorf("expected db type of %s but got %s", DBTypePostgres, c.DBConfig.Type)
|
||||
}
|
||||
|
||||
// validate port
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue