From 382512a5a6cc3f13576bbde8d607098d019f4063 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 2 Feb 2023 14:08:13 +0100 Subject: [feature] Implement `/api/v2/instance` endpoint (#1409) * interim: start adding /api/v2/instance * finish up --- internal/api/util/errorhandling.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'internal/api/util/errorhandling.go') diff --git a/internal/api/util/errorhandling.go b/internal/api/util/errorhandling.go index 9d8267250..414b8d7e8 100644 --- a/internal/api/util/errorhandling.go +++ b/internal/api/util/errorhandling.go @@ -25,7 +25,6 @@ import ( "codeberg.org/gruf/go-kv" "github.com/gin-gonic/gin" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/log" ) @@ -41,11 +40,10 @@ import ( // 404 header and footer. // // If an error is returned by InstanceGet, the function will panic. -func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode), accept string) { +func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode), accept string) { switch accept { case string(TextHTML): - host := config.GetHost() - instance, err := instanceGet(c.Request.Context(), host) + instance, err := instanceGet(c.Request.Context()) if err != nil { panic(err) } @@ -61,11 +59,10 @@ func NotFoundHandler(c *gin.Context, instanceGet func(ctx context.Context, domai // genericErrorHandler is a more general version of the NotFoundHandler, which can // be used for serving either generic error pages with some rendered help text, // or just some error json if the caller prefers (or has no preference). -func genericErrorHandler(c *gin.Context, instanceGet func(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode), accept string, errWithCode gtserror.WithCode) { +func genericErrorHandler(c *gin.Context, instanceGet func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode), accept string, errWithCode gtserror.WithCode) { switch accept { case string(TextHTML): - host := config.GetHost() - instance, err := instanceGet(c.Request.Context(), host) + instance, err := instanceGet(c.Request.Context()) if err != nil { panic(err) } @@ -85,7 +82,7 @@ func genericErrorHandler(c *gin.Context, instanceGet func(ctx context.Context, d // the caller prefers to see an html page with the error rendered there. If not, or // if something goes wrong during the function, it will recover and just try to serve // an appropriate application/json content-type error. -func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet func(ctx context.Context, domain string) (*apimodel.Instance, gtserror.WithCode)) { +func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet func(ctx context.Context) (*apimodel.InstanceV1, gtserror.WithCode)) { // set the error on the gin context so that it can be logged // in the gin logger middleware (internal/router/logger.go) c.Error(errWithCode) //nolint:errcheck -- cgit v1.2.3