MM - 19155 Change plugin helpers files to be golint complied (#12686)
* MM-19155 Change plugin helpers files to be golint complied * add makefile target that checks if plugin/helpers files are golint compliant * MM-19155 - Change plugin helpers files to be golint complied * added comment documentation to exported plugin/helpers methods * changed variable names to be compliant with golint * Address feedback
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
36f3b14420
Коммит
1155b08404
@@ -9,6 +9,9 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Helpers provide a common patterns plugins use.
|
||||
//
|
||||
// Plugins obtain access to the Helpers by embedding MattermostPlugin.
|
||||
type Helpers interface {
|
||||
// EnsureBot either returns an existing bot user matching the given bot, or creates a bot user from the given bot.
|
||||
// Returns the id of the resulting bot.
|
||||
@@ -55,6 +58,7 @@ type Helpers interface {
|
||||
KVSetWithExpiryJSON(key string, value interface{}, expireInSeconds int64) error
|
||||
}
|
||||
|
||||
// HelpersImpl implements the helpers interface with an API that retrieves data on behalf of the plugin.
|
||||
type HelpersImpl struct {
|
||||
API API
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (p *HelpersImpl) EnsureBot(bot *model.Bot) (retBotId string, retErr error) {
|
||||
// EnsureBot implements Helpers.EnsureBot
|
||||
func (p *HelpersImpl) EnsureBot(bot *model.Bot) (retBotID string, retErr error) {
|
||||
err := p.ensureServerVersion("5.10.0")
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "failed to ensure bot")
|
||||
@@ -23,34 +25,34 @@ func (p *HelpersImpl) EnsureBot(bot *model.Bot) (retBotId string, retErr error)
|
||||
// If we fail for any reason, this could be a race between creation of bot and
|
||||
// retrieval from another EnsureBot. Just try the basic retrieve existing again.
|
||||
defer func() {
|
||||
if retBotId == "" || retErr != nil {
|
||||
if retBotID == "" || retErr != nil {
|
||||
var err error
|
||||
var botIdBytes []byte
|
||||
var botIDBytes []byte
|
||||
|
||||
err = utils.ProgressiveRetry(func() error {
|
||||
botIdBytes, err = p.API.KVGet(BOT_USER_KEY)
|
||||
botIDBytes, err = p.API.KVGet(BOT_USER_KEY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err == nil && botIdBytes != nil {
|
||||
retBotId = string(botIdBytes)
|
||||
if err == nil && botIDBytes != nil {
|
||||
retBotID = string(botIDBytes)
|
||||
retErr = nil
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
botIdBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY)
|
||||
botIDBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY)
|
||||
if kvGetErr != nil {
|
||||
return "", errors.Wrap(kvGetErr, "failed to get bot")
|
||||
}
|
||||
|
||||
// If the bot has already been created, there is nothing to do.
|
||||
if botIdBytes != nil {
|
||||
botId := string(botIdBytes)
|
||||
return botId, nil
|
||||
if botIDBytes != nil {
|
||||
botID := string(botIDBytes)
|
||||
return botID, nil
|
||||
}
|
||||
|
||||
// Check for an existing bot user with that username. If one exists, then use that.
|
||||
|
||||
Ссылка в новой задаче
Block a user