我有类似的东西
type rateLimit struct {
Count int
}
type RateLimiter struct {
cachePeriod time.Duration
rateLimits map[string]*rateLimit
}
和这样的功能:
func NewRateLimiter(////) *RateLimiter {
rateLimits := make(map[string]*rateLimit)
return &RateLimiter{
cachePeriod: cachePeriod,
rateLimits: rateLimits,
}
}
此结构允许您创建嵌套结构,例如 rateLimits["foo"] = a
但我正在尝试进行更改以使其嵌套并且我可以做到rateLimits["foo"]["bar"] = a
我尝试将结构更改为 rateLimits := make(map[string]map[string]*rateLimit)
和
type rateLimiter struct {
cachePeriod time.Duration
rateLimits map[string]map[string]*rateLimit
}
但我得到panic: assignment to entry in nil map [recovered] panic: assignment to entry in nil map
qq_遁去的一_1
白衣染霜花
相关分类