107
108// WithRejectionResponse return limiterOption. WithRejectionResponse
109// customize the response for the request rejected by the limiter.
110func WithRejectionResponse(resp RejectionResponse) limiterOption {111 return func(l *limiter) {
112 l.resp = resp
113 }
99
100// WithBucketFactory return limiterOption. WithBucketFactory customize the
101// implementation of Bucket.
102func WithBucketFactory(f func(opts ...bucketOption) bucket) limiterOption {103 return func(l *limiter) {
104 l.bucketFactory = f
105 }
91// WithCapacity return limiterOption. WithCapacity config the capacity size.
92// The bucket with a capacity of n has n tokens after initialization. The capacity
93// defines how many requests a client can make in excess of the rate.
94func WithCapacity(c uint) limiterOption { 95 return func(l *limiter) {
96 l.capacity = c
97 }
82
83// WithRate return limiterOption. WithRate config how long it takes to
84// generate a token.
85func WithRate(r time.Duration) limiterOption { 86 return func(l *limiter) {
87 l.rate = r
88 }
74
75// WithSessionKey return limiterOption. WithSessionKey config func
76// which defines the request characteristic against the limit is applied
77func WithSessionKey(f func(ctx *context.Context) string) limiterOption { 78 return func(l *limiter) {
79 l.sessionKey = f
80 }
An exported function or method returning a value of an unexported type may be frustrating to use.
In Go, if the function or method starts with a lowercase letter, it is not exported outside the package.
type unexportedType string
func ExportedFunc() *unexportedType {
return &unexportedType("some string")
}
type ExportedType string
func ExportedFunc() *ExportedType {
return &ExportedType("some string")
}