main

mattermost/focalboard

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

mutex_adapter.go

TLDR

The mutex_adapter.go file in the Demo Projects project contains an implementation of a mutex API adapter. It has a struct mutexAPIAdapter that implements the KVSetWithOptions and LogError methods.

Methods

KVSetWithOptions

This method is part of the mutexAPIAdapter struct. It takes in a key, value, and options, and calls the KVSetWithOptions method of the api object passed to the mutexAPIAdapter struct. It returns a boolean value and an AppError object.

LogError

This method is part of the mutexAPIAdapter struct. It takes in a message and a variable number of key-value pairs. It calls the Error method of the logger in the api object passed to the mutexAPIAdapter struct, with the message and key-value pairs.

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

package boards

import (
	"errors"
	"net/http"

	mm_model "github.com/mattermost/mattermost-server/v6/model"
	"github.com/mattermost/mattermost-server/v6/shared/mlog"

	"github.com/mattermost/focalboard/server/model"
)

type mutexAPIAdapter struct {
	api model.ServicesAPI
}

func (m *mutexAPIAdapter) KVSetWithOptions(key string, value []byte, options mm_model.PluginKVSetOptions) (bool, *mm_model.AppError) {
	b, err := m.api.KVSetWithOptions(key, value, options)

	var appErr *mm_model.AppError
	if err != nil {
		if !errors.As(err, &appErr) {
			appErr = mm_model.NewAppError("KVSetWithOptions", "", nil, "", http.StatusInternalServerError)
		}
	}
	return b, appErr
}

func (m *mutexAPIAdapter) LogError(msg string, keyValuePairs ...interface{}) {
	m.api.GetLogger().Error(msg, mlog.Array("kvpairs", keyValuePairs))
}