github.com/songzhibin97/gkit@v1.2.13/overload/limiter.go (about)

     1  package overload
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  // Op 操作类型
     8  type Op int
     9  
    10  const (
    11  	Success Op = iota
    12  	Ignore
    13  	Drop
    14  )
    15  
    16  type allowOptions struct{}
    17  
    18  // AllowOption AllowOptions allow options.
    19  type AllowOption interface {
    20  	Apply(*allowOptions)
    21  }
    22  
    23  // DoneInfo 完成信息
    24  type DoneInfo struct {
    25  	Err error
    26  	Op  Op
    27  }
    28  
    29  // DefaultAllowOpts 返回默认选项
    30  func DefaultAllowOpts() allowOptions {
    31  	return allowOptions{}
    32  }
    33  
    34  // Limiter 限制接口
    35  type Limiter interface {
    36  	Allow(ctx context.Context, opts ...AllowOption) (func(info DoneInfo), error)
    37  }