main

mattermost/focalboard

Last updated at: 29/12/2023 09:48

config.go

TLDR

This file defines a registerConfigRoutes method that sets up the API routes related to config. It also includes a getClientConfig method that returns the client configuration.

Methods

registerConfigRoutes

This method sets up the API routes related to config. It takes a mux.Router as a parameter and registers the /clientConfig route with the getClientConfig method to handle GET requests.

getClientConfig

This method handles the GET request to retrieve the client configuration. It returns the client configuration as a JSON response. It first retrieves the client configuration using a.app.GetClientConfig() and then encodes it into a JSON byte array. If there are any errors during the encoding process, an error response is sent.

package api

import (
	"encoding/json"
	"net/http"

	"github.com/gorilla/mux"
)

func (a *API) registerConfigRoutes(r *mux.Router) {
	// Config APIs
	r.HandleFunc("/clientConfig", a.getClientConfig).Methods("GET")
}

func (a *API) getClientConfig(w http.ResponseWriter, r *http.Request) {
	// swagger:operation GET /clientConfig getClientConfig
	//
	// Returns the client configuration
	//
	// ---
	// produces:
	// - application/json
	// responses:
	//   '200':
	//     description: success
	//     schema:
	//       "$ref": "#/definitions/ClientConfig"
	//   default:
	//     description: internal error
	//     schema:
	//       "$ref": "#/definitions/ErrorResponse"

	clientConfig := a.app.GetClientConfig()

	configData, err := json.Marshal(clientConfig)
	if err != nil {
		a.errorResponse(w, r, err)
		return
	}
	jsonBytesResponse(w, http.StatusOK, configData)
}