1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
requests.go 2.12 KB
一键复制 编辑 原始数据 按行查看 历史
Masahiro Sano 提交于 2015-04-18 18:35 . Update gophercloud to latest
package throttle
import (
"errors"
"github.com/rackspace/gophercloud"
)
// CreateOptsBuilder is the interface options structs have to satisfy in order
// to be used in the main Create operation in this package.
type CreateOptsBuilder interface {
ToCTCreateMap() (map[string]interface{}, error)
}
// CreateOpts is the common options struct used in this package's Create
// operation.
type CreateOpts struct {
// Required - the maximum amount of connections per IP address to allow per LB.
MaxConnections int
// Deprecated as of v1.22.
MaxConnectionRate int
// Deprecated as of v1.22.
MinConnections int
// Deprecated as of v1.22.
RateInterval int
}
// ToCTCreateMap casts a CreateOpts struct to a map.
func (opts CreateOpts) ToCTCreateMap() (map[string]interface{}, error) {
ct := make(map[string]interface{})
if opts.MaxConnections < 0 || opts.MaxConnections > 100000 {
return ct, errors.New("MaxConnections must be an int between 0 and 100000")
}
ct["maxConnections"] = opts.MaxConnections
ct["maxConnectionRate"] = opts.MaxConnectionRate
ct["minConnections"] = opts.MinConnections
ct["rateInterval"] = opts.RateInterval
return map[string]interface{}{"connectionThrottle": ct}, nil
}
// Create is the operation responsible for creating or updating the connection
// throttling configuration for a load balancer.
func Create(c *gophercloud.ServiceClient, lbID int, opts CreateOptsBuilder) CreateResult {
var res CreateResult
reqBody, err := opts.ToCTCreateMap()
if err != nil {
res.Err = err
return res
}
_, res.Err = c.Put(rootURL(c, lbID), reqBody, &res.Body, nil)
return res
}
// Get is the operation responsible for showing the details of the connection
// throttling configuration for a load balancer.
func Get(c *gophercloud.ServiceClient, lbID int) GetResult {
var res GetResult
_, res.Err = c.Get(rootURL(c, lbID), &res.Body, nil)
return res
}
// Delete is the operation responsible for deleting the connection throttling
// configuration for a load balancer.
func Delete(c *gophercloud.ServiceClient, lbID int) DeleteResult {
var res DeleteResult
_, res.Err = c.Delete(rootURL(c, lbID), nil)
return res
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v1.1.3

搜索帮助

344bd9b3 5694891 D2dac590 5694891