github.com/polarismesh/polaris@v1.17.8/plugin/ratelimit/token/invoke.go (about) 1 /** 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package token 19 20 import ( 21 "github.com/polarismesh/polaris/plugin" 22 ) 23 24 // tokenBucket 实现Plugin接口 25 type tokenBucket struct { 26 config *Config 27 limiters map[plugin.RatelimitType]limiter 28 } 29 30 // Name 实现Plugin接口,Name方法 31 func (tb *tokenBucket) Name() string { 32 return PluginName 33 } 34 35 // Initialize 实现Plugin接口,Initialize方法 36 func (tb *tokenBucket) Initialize(c *plugin.ConfigEntry) error { 37 return tb.initialize(c) 38 } 39 40 // Destroy 实现Plugin接口,Destroy方法 41 func (tb *tokenBucket) Destroy() error { 42 return nil 43 } 44 45 // Allow 限流接口实现 46 func (tb *tokenBucket) Allow(typ plugin.RatelimitType, key string) bool { 47 return tb.allow(typ, key) 48 }