github.com/rajatvaryani/mattermost-server@v5.11.1+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 ExpireAt int64 `json:"expire_at"` 21 } 22 23 func (kv *PluginKeyValue) IsValid() *AppError { 24 if len(kv.PluginId) == 0 || utf8.RuneCountInString(kv.PluginId) > KEY_VALUE_PLUGIN_ID_MAX_RUNES { 25 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) 26 } 27 28 if len(kv.Key) == 0 || utf8.RuneCountInString(kv.Key) > KEY_VALUE_KEY_MAX_RUNES { 29 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) 30 } 31 32 return nil 33 }