github.com/wgh-/mattermost-server@v4.8.0-rc2+incompatible/model/plugin_key_value.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "net/http" 8 "unicode/utf8" 9 ) 10 11 const ( 12 KEY_VALUE_PLUGIN_ID_MAX_RUNES = 190 13 KEY_VALUE_KEY_MAX_RUNES = 50 14 ) 15 16 type PluginKeyValue struct { 17 PluginId string `json:"plugin_id"` 18 Key string `json:"key" db:"PKey"` 19 Value []byte `json:"value" db:"PValue"` 20 } 21 22 func (kv *PluginKeyValue) IsValid() *AppError { 23 if len(kv.PluginId) == 0 || utf8.RuneCountInString(kv.PluginId) > KEY_VALUE_PLUGIN_ID_MAX_RUNES { 24 return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.plugin_id.app_error", map[string]interface{}{"Max": KEY_VALUE_KEY_MAX_RUNES, "Min": 0}, "key="+kv.Key, http.StatusBadRequest) 25 } 26 27 if len(kv.Key) == 0 || utf8.RuneCountInString(kv.Key) > KEY_VALUE_KEY_MAX_RUNES { 28 return NewAppError("PluginKeyValue.IsValid", "model.plugin_key_value.is_valid.key.app_error", map[string]interface{}{"Max": KEY_VALUE_KEY_MAX_RUNES, "Min": 0}, "key="+kv.Key, http.StatusBadRequest) 29 } 30 31 return nil 32 }