diff --git a/cmd/gotosocial/action/server/server.go b/cmd/gotosocial/action/server/server.go index 9fd3f66fe..24b3771df 100644 --- a/cmd/gotosocial/action/server/server.go +++ b/cmd/gotosocial/action/server/server.go @@ -78,7 +78,7 @@ // depending on what services were // managed to be started. - state state.State + state = new(state.State) route *router.Router ) @@ -137,7 +137,7 @@ state.Caches.Start() // Open connection to the database now caches started. - dbService, err := bundb.NewBunDBService(ctx, &state) + dbService, err := bundb.NewBunDBService(ctx, state) if err != nil { return fmt.Errorf("error creating dbservice: %s", err) } @@ -177,14 +177,14 @@ }) // Build handlers used in later initializations. - mediaManager := media.NewManager(&state) + mediaManager := media.NewManager(state) oauthServer := oauth.New(ctx, dbService) - typeConverter := typeutils.NewConverter(&state) - visFilter := visibility.NewFilter(&state) - spamFilter := spam.NewFilter(&state) - federatingDB := federatingdb.New(&state, typeConverter, visFilter, spamFilter) - transportController := transport.NewController(&state, federatingDB, &federation.Clock{}, client) - federator := federation.NewFederator(&state, federatingDB, transportController, typeConverter, visFilter, mediaManager) + typeConverter := typeutils.NewConverter(state) + visFilter := visibility.NewFilter(state) + spamFilter := spam.NewFilter(state) + federatingDB := federatingdb.New(state, typeConverter, visFilter, spamFilter) + transportController := transport.NewController(state, federatingDB, &federation.Clock{}, client) + federator := federation.NewFederator(state, federatingDB, transportController, typeConverter, visFilter, mediaManager) // Decide whether to create a noop email // sender (won't send emails) or a real one. @@ -205,18 +205,18 @@ // Initialize both home / list timelines. state.Timelines.Home = timeline.NewManager( - tlprocessor.HomeTimelineGrab(&state), - tlprocessor.HomeTimelineFilter(&state, visFilter), - tlprocessor.HomeTimelineStatusPrepare(&state, typeConverter), + tlprocessor.HomeTimelineGrab(state), + tlprocessor.HomeTimelineFilter(state, visFilter), + tlprocessor.HomeTimelineStatusPrepare(state, typeConverter), tlprocessor.SkipInsert(), ) if err := state.Timelines.Home.Start(); err != nil { return fmt.Errorf("error starting home timeline: %s", err) } state.Timelines.List = timeline.NewManager( - tlprocessor.ListTimelineGrab(&state), - tlprocessor.ListTimelineFilter(&state, visFilter), - tlprocessor.ListTimelineStatusPrepare(&state, typeConverter), + tlprocessor.ListTimelineGrab(state), + tlprocessor.ListTimelineFilter(state, visFilter), + tlprocessor.ListTimelineStatusPrepare(state, typeConverter), tlprocessor.SkipInsert(), ) if err := state.Timelines.List.Start(); err != nil { @@ -230,17 +230,19 @@ // Add a task to the scheduler to sweep caches. // Frequency = 1 * minute // Threshold = 60% capacity - _ = state.Workers.Scheduler.AddRecurring( + if !state.Workers.Scheduler.AddRecurring( "@cachesweep", // id time.Time{}, // start time.Minute, // freq func(context.Context, time.Time) { state.Caches.Sweep(60) }, - ) + ) { + return fmt.Errorf("error scheduling cache sweep: %w", err) + } // Create background cleaner. - cleaner := cleaner.New(&state) + cleaner := cleaner.New(state) // Now schedule background cleaning tasks. if err := cleaner.ScheduleJobs(); err != nil { @@ -255,7 +257,7 @@ func(context.Context, time.Time) { federator, oauthServer, mediaManager, - &state, + state, emailSender, ) @@ -308,7 +310,7 @@ func(context.Context, time.Time) { // note: hooks adding ctx fields must be ABOVE // the logger, otherwise won't be accessible. middleware.Logger(config.GetLogClientIP()), - middleware.HeaderFilter(&state), + middleware.HeaderFilter(state), middleware.UserAgent(), middleware.CORS(), middleware.ExtraHeaders(), @@ -366,7 +368,7 @@ func(context.Context, time.Time) { var ( authModule = api.NewAuth(dbService, processor, idp, routerSession, sessionName) // auth/oauth paths - clientModule = api.NewClient(&state, processor) // api client endpoints + clientModule = api.NewClient(state, processor) // api client endpoints metricsModule = api.NewMetrics() // Metrics endpoints healthModule = api.NewHealth(dbService.Ready) // Health check endpoints fileserverModule = api.NewFileserver(processor) // fileserver endpoints diff --git a/cmd/gotosocial/action/testrig/testrig.go b/cmd/gotosocial/action/testrig/testrig.go index 7a3ddde26..7b99a2a13 100644 --- a/cmd/gotosocial/action/testrig/testrig.go +++ b/cmd/gotosocial/action/testrig/testrig.go @@ -64,7 +64,7 @@ // depending on what services were // managed to be started. - state state.State + state = new(state.State) route *router.Router ) @@ -85,7 +85,7 @@ // Stop any currently running // worker processes / scheduled // tasks from being executed. - testrig.StopWorkers(&state) + testrig.StopWorkers(state) if state.Timelines.Home != nil { // Home timeline mgr was setup, ensure it gets stopped. @@ -130,7 +130,7 @@ } // Initialize caches and database - state.DB = testrig.NewTestDB(&state) + state.DB = testrig.NewTestDB(state) // New test db inits caches so we don't need to do // that twice, we can just start the initialized caches. @@ -156,11 +156,11 @@ testrig.StandardStorageSetup(state.Storage, "./testrig/media") // Initialize workers. - testrig.StartNoopWorkers(&state) - defer testrig.StopWorkers(&state) + testrig.StartNoopWorkers(state) + defer testrig.StopWorkers(state) // build backend handlers - transportController := testrig.NewTestTransportController(&state, testrig.NewMockHTTPClient(func(req *http.Request) (*http.Response, error) { + transportController := testrig.NewTestTransportController(state, testrig.NewMockHTTPClient(func(req *http.Request) (*http.Response, error) { r := io.NopCloser(bytes.NewReader([]byte{})) return &http.Response{ StatusCode: 200, @@ -170,34 +170,34 @@ }, }, nil }, "")) - mediaManager := testrig.NewTestMediaManager(&state) - federator := testrig.NewTestFederator(&state, transportController, mediaManager) + mediaManager := testrig.NewTestMediaManager(state) + federator := testrig.NewTestFederator(state, transportController, mediaManager) emailSender := testrig.NewEmailSender("./web/template/", nil) - typeConverter := typeutils.NewConverter(&state) - filter := visibility.NewFilter(&state) + typeConverter := typeutils.NewConverter(state) + filter := visibility.NewFilter(state) // Initialize both home / list timelines. state.Timelines.Home = timeline.NewManager( - tlprocessor.HomeTimelineGrab(&state), - tlprocessor.HomeTimelineFilter(&state, filter), - tlprocessor.HomeTimelineStatusPrepare(&state, typeConverter), + tlprocessor.HomeTimelineGrab(state), + tlprocessor.HomeTimelineFilter(state, filter), + tlprocessor.HomeTimelineStatusPrepare(state, typeConverter), tlprocessor.SkipInsert(), ) if err := state.Timelines.Home.Start(); err != nil { return fmt.Errorf("error starting home timeline: %s", err) } state.Timelines.List = timeline.NewManager( - tlprocessor.ListTimelineGrab(&state), - tlprocessor.ListTimelineFilter(&state, filter), - tlprocessor.ListTimelineStatusPrepare(&state, typeConverter), + tlprocessor.ListTimelineGrab(state), + tlprocessor.ListTimelineFilter(state, filter), + tlprocessor.ListTimelineStatusPrepare(state, typeConverter), tlprocessor.SkipInsert(), ) if err := state.Timelines.List.Start(); err != nil { return fmt.Errorf("error starting list timeline: %s", err) } - processor := testrig.NewTestProcessor(&state, federator, emailSender, mediaManager) + processor := testrig.NewTestProcessor(state, federator, emailSender, mediaManager) // Initialize metrics. if err := metrics.Initialize(state.DB); err != nil { @@ -222,7 +222,7 @@ middlewares = append(middlewares, []gin.HandlerFunc{ middleware.Logger(config.GetLogClientIP()), - middleware.HeaderFilter(&state), + middleware.HeaderFilter(state), middleware.UserAgent(), middleware.CORS(), middleware.ExtraHeaders(), @@ -280,7 +280,7 @@ var ( authModule = api.NewAuth(state.DB, processor, idp, routerSession, sessionName) // auth/oauth paths - clientModule = api.NewClient(&state, processor) // api client endpoints + clientModule = api.NewClient(state, processor) // api client endpoints metricsModule = api.NewMetrics() // Metrics endpoints healthModule = api.NewHealth(state.DB.Ready) // Health check endpoints fileserverModule = api.NewFileserver(processor) // fileserver endpoints @@ -304,7 +304,7 @@ webModule.Route(route) // Create background cleaner. - cleaner := cleaner.New(&state) + cleaner := cleaner.New(state) // Now schedule background cleaning tasks. if err := cleaner.ScheduleJobs(); err != nil {