MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / NewProfile

Function NewProfile

pkg/ratelimit/config.go:104–127  ·  view source on GitHub ↗

NewProfile returns a new ratelimit.Interface from profile configuration.

(ctx context.Context, conf config.RateLimitingProfile, storeConf StoreConfig)

Source from the content-addressed store, hash-verified

102
103// NewProfile returns a new ratelimit.Interface from profile configuration.
104func NewProfile(ctx context.Context, conf config.RateLimitingProfile, storeConf StoreConfig) (Interface, error) {
105 if s := &storeConf.Memory.MaxSize; *s == 0 {
106 *s = defaultMaxSize
107 }
108 if conf.MaxPerMin == 0 {
109 return nil, errInvalidRate.WithAttributes("rate", conf.MaxPerMin, "name", conf.Name)
110 }
111 store, err := newStore(storeConf)
112 if err != nil {
113 return nil, err
114 }
115 if conf.MaxBurst == 0 {
116 conf.MaxBurst = conf.MaxPerMin
117 }
118 quota := throttled.RateQuota{
119 MaxRate: throttled.PerMin(int(conf.MaxPerMin)),
120 MaxBurst: int(conf.MaxBurst - 1),
121 }
122 limiter, err := throttled.NewGCRARateLimiterCtx(store, quota)
123 if err != nil {
124 return nil, err
125 }
126 return &rateLimiter{ctx, limiter}, nil
127}

Callers 2

ServeFunction · 0.92
NewFunction · 0.85

Calls 2

newStoreFunction · 0.70
WithAttributesMethod · 0.45

Tested by

no test coverage detected