summaryrefslogtreecommitdiff
path: root/internal/gotosocial/gotosocial.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/gotosocial/gotosocial.go')
-rw-r--r--internal/gotosocial/gotosocial.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/internal/gotosocial/gotosocial.go b/internal/gotosocial/gotosocial.go
index d9fb29527..d8f46f873 100644
--- a/internal/gotosocial/gotosocial.go
+++ b/internal/gotosocial/gotosocial.go
@@ -22,17 +22,22 @@ import (
"context"
"github.com/go-fed/activity/pub"
- "github.com/gotosocial/gotosocial/internal/cache"
- "github.com/gotosocial/gotosocial/internal/config"
- "github.com/gotosocial/gotosocial/internal/db"
- "github.com/gotosocial/gotosocial/internal/router"
+ "github.com/superseriousbusiness/gotosocial/internal/cache"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/db"
+ "github.com/superseriousbusiness/gotosocial/internal/router"
)
+// Gotosocial is the 'main' function of the gotosocial server, and the place where everything hangs together.
+// The logic of stopping and starting the entire server is contained here.
type Gotosocial interface {
Start(context.Context) error
Stop(context.Context) error
}
+// New returns a new gotosocial server, initialized with the given configuration.
+// An error will be returned the caller if something goes wrong during initialization
+// eg., no db or storage connection, port for router already in use, etc.
func New(db db.DB, cache cache.Cache, apiRouter router.Router, federationAPI pub.FederatingActor, config *config.Config) (Gotosocial, error) {
return &gotosocial{
db: db,
@@ -43,6 +48,7 @@ func New(db db.DB, cache cache.Cache, apiRouter router.Router, federationAPI pub
}, nil
}
+// gotosocial fulfils the gotosocial interface.
type gotosocial struct {
db db.DB
cache cache.Cache
@@ -51,10 +57,19 @@ type gotosocial struct {
config *config.Config
}
+// Start starts up the gotosocial server. If something goes wrong
+// while starting the server, then an error will be returned.
func (gts *gotosocial) Start(ctx context.Context) error {
+ gts.apiRouter.Start()
return nil
}
func (gts *gotosocial) Stop(ctx context.Context) error {
+ if err := gts.apiRouter.Stop(ctx); err != nil {
+ return err
+ }
+ if err := gts.db.Stop(ctx); err != nil {
+ return err
+ }
return nil
}