gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

instanceget.go (2767B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package instance
     19 
     20 import (
     21 	"net/http"
     22 
     23 	apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
     24 	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
     25 
     26 	"github.com/gin-gonic/gin"
     27 )
     28 
     29 // InstanceInformationV1GETHandlerV1 swagger:operation GET /api/v1/instance instanceGetV1
     30 //
     31 // View instance information.
     32 //
     33 //	---
     34 //	tags:
     35 //	- instance
     36 //
     37 //	produces:
     38 //	- application/json
     39 //
     40 //	responses:
     41 //		'200':
     42 //			description: "Instance information."
     43 //			schema:
     44 //				"$ref": "#/definitions/instanceV1"
     45 //		'406':
     46 //			description: not acceptable
     47 //		'500':
     48 //			description: internal error
     49 func (m *Module) InstanceInformationGETHandlerV1(c *gin.Context) {
     50 	if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
     51 		apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
     52 		return
     53 	}
     54 
     55 	instance, errWithCode := m.processor.InstanceGetV1(c.Request.Context())
     56 	if errWithCode != nil {
     57 		apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
     58 		return
     59 	}
     60 
     61 	c.JSON(http.StatusOK, instance)
     62 }
     63 
     64 // InstanceInformationGETHandlerV2 swagger:operation GET /api/v2/instance instanceGetV2
     65 //
     66 // View instance information.
     67 //
     68 //	---
     69 //	tags:
     70 //	- instance
     71 //
     72 //	produces:
     73 //	- application/json
     74 //
     75 //	responses:
     76 //		'200':
     77 //			description: "Instance information."
     78 //			schema:
     79 //				"$ref": "#/definitions/instanceV2"
     80 //		'406':
     81 //			description: not acceptable
     82 //		'500':
     83 //			description: internal error
     84 func (m *Module) InstanceInformationGETHandlerV2(c *gin.Context) {
     85 	if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
     86 		apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
     87 		return
     88 	}
     89 
     90 	instance, errWithCode := m.processor.InstanceGetV2(c.Request.Context())
     91 	if errWithCode != nil {
     92 		apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
     93 		return
     94 	}
     95 
     96 	c.JSON(http.StatusOK, instance)
     97 }