diff options
author | 2023-02-02 14:08:13 +0100 | |
---|---|---|
committer | 2023-02-02 14:08:13 +0100 | |
commit | 382512a5a6cc3f13576bbde8d607098d019f4063 (patch) | |
tree | dc2ccd1d30cd65b3f3d576a8d2a6910bbecc593a /internal/api/client/instance/instanceget.go | |
parent | [chore/performance] use only 1 sqlite db connection regardless of multiplier ... (diff) | |
download | gotosocial-382512a5a6cc3f13576bbde8d607098d019f4063.tar.xz |
[feature] Implement `/api/v2/instance` endpoint (#1409)
* interim: start adding /api/v2/instance
* finish up
Diffstat (limited to 'internal/api/client/instance/instanceget.go')
-rw-r--r-- | internal/api/client/instance/instanceget.go | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/internal/api/client/instance/instanceget.go b/internal/api/client/instance/instanceget.go index 438085771..f3027b1d7 100644 --- a/internal/api/client/instance/instanceget.go +++ b/internal/api/client/instance/instanceget.go @@ -22,13 +22,12 @@ import ( "net/http" apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/gin-gonic/gin" ) -// InstanceInformationGETHandler swagger:operation GET /api/v1/instance instanceGet +// InstanceInformationV1GETHandlerV1 swagger:operation GET /api/v1/instance instanceGetV1 // // View instance information. // @@ -43,20 +42,55 @@ import ( // '200': // description: "Instance information." // schema: -// "$ref": "#/definitions/instance" +// "$ref": "#/definitions/instanceV1" // '406': // description: not acceptable // '500': // description: internal error -func (m *Module) InstanceInformationGETHandler(c *gin.Context) { +func (m *Module) InstanceInformationGETHandlerV1(c *gin.Context) { if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { - apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet) + apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) return } - instance, errWithCode := m.processor.InstanceGet(c.Request.Context(), config.GetHost()) + instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context()) if errWithCode != nil { - apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGet) + apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) + return + } + + c.JSON(http.StatusOK, instance) +} + +// InstanceInformationGETHandlerV2 swagger:operation GET /api/v2/instance instanceGetV2 +// +// View instance information. +// +// --- +// tags: +// - instance +// +// produces: +// - application/json +// +// responses: +// '200': +// description: "Instance information." +// schema: +// "$ref": "#/definitions/instanceV2" +// '406': +// description: not acceptable +// '500': +// description: internal error +func (m *Module) InstanceInformationGETHandlerV2(c *gin.Context) { + if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil { + apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1) + return + } + + instance, errWithCode := m.processor.InstanceGetV2(c.Request.Context()) + if errWithCode != nil { + apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1) return } |