handler

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataTypeSecond = iota
	DataTypeMinute
	DataTypeHour
)

Variables

This section is empty.

Functions

func CleanupLimiters

func CleanupLimiters()

func RedisScript

func RedisScript(script string, args ...interface{}) (interface{}, error)

func ServiceManagerInit

func ServiceManagerInit()

Types

type AppEvent

type AppEvent struct {
	DeleteApp []*model.App
	AddApp    []*model.App
	UpdateApp []*model.App
}

通知事件

type AppManager

type AppManager struct {
	AppMap   map[string]*model.App
	AppSlice []*model.App

	UpdateAt  time.Time
	Observers map[AppObserver]bool
	// contains filtered or unexported fields
}
var AppManagerHandler *AppManager

func NewAppManager

func NewAppManager() *AppManager

func (*AppManager) Deregist

func (s *AppManager) Deregist(ob AppObserver)

func (*AppManager) GetAppList

func (s *AppManager) GetAppList() []*model.App

func (*AppManager) LoadAndWatch

func (s *AppManager) LoadAndWatch() error

func (*AppManager) LoadApp

func (s *AppManager) LoadApp() *AppManager

func (*AppManager) Notify

func (s *AppManager) Notify(e *AppEvent)

func (*AppManager) Regist

func (s *AppManager) Regist(ob AppObserver)

type AppObserver

type AppObserver interface {
	Update(*AppEvent)
}

观察者接口

type AppSubject

type AppSubject interface {
	Regist(ServiceObserver)
	Deregist(ServiceObserver)
	Notify(*AppEvent)
}

被观察者接口

type DistributedCountService

type DistributedCountService struct {
	Name        string
	Interval    time.Duration
	QPS         int64
	Unix        int64
	TickerCount int64
	TotalCount  int64
	// contains filtered or unexported fields
}

func NewDistributedCountService

func NewDistributedCountService(name string, interval time.Duration) *DistributedCountService

func (*DistributedCountService) Close

func (o *DistributedCountService) Close()

func (*DistributedCountService) GetDayData

func (o *DistributedCountService) GetDayData(t time.Time) (int64, error)

func (*DistributedCountService) GetDayKey

func (o *DistributedCountService) GetDayKey(t time.Time) string

func (*DistributedCountService) GetHourData

func (o *DistributedCountService) GetHourData(t time.Time) (int64, error)

func (*DistributedCountService) GetHourKey

func (o *DistributedCountService) GetHourKey(t time.Time) string

func (*DistributedCountService) Increase

func (o *DistributedCountService) Increase()

type DistributedLimiter

type DistributedLimiter struct {
	Name     string
	Dtype    int //0=qps 1=qpm 2=qph
	Rate     int64
	Capacity int64
}

func NewDistributedLimiter

func NewDistributedLimiter(name string, dtype int, rate, capacity int64) *DistributedLimiter

func (*DistributedLimiter) Allow

func (d *DistributedLimiter) Allow() bool

func (*DistributedLimiter) AllowV1

func (d *DistributedLimiter) AllowV1() bool

type FlowAppCounter

type FlowAppCounter struct {
	FlowCounter
}
var AppCounterHandler *FlowAppCounter

func NewFlowAppCounter

func NewFlowAppCounter() *FlowAppCounter

func (*FlowAppCounter) Update

func (counter *FlowAppCounter) Update(e *AppEvent)

type FlowCounter

type FlowCounter struct {
	RedisFlowCountMap map[string]*DistributedCountService
	Locker            sync.RWMutex
}
var ServiceCounterHandler *FlowCounter

func NewFlowCounter

func NewFlowCounter() *FlowCounter

func (*FlowCounter) GetCounter

func (counter *FlowCounter) GetCounter(name string) (*DistributedCountService, error)

func (*FlowCounter) Update

func (counter *FlowCounter) Update(e *ServiceEvent)

type FlowLimiter

type FlowLimiter struct {
	FlowLimiterMap map[string]*FlowLimiterItem
	Locker         sync.RWMutex
}
var FlowLimiterHandler *FlowLimiter

func NewFlowLimiter

func NewFlowLimiter() *FlowLimiter

func (*FlowLimiter) GetLimiter

func (counter *FlowLimiter) GetLimiter(serverName string, val float64, ltype int, isDistributed bool) (Limiter, error)

一个服务,可能设置多种限流策略

type FlowLimiterItem

type FlowLimiterItem struct {
	LastTime      time.Time
	Name          string
	LType         int  //限流类型 0=qps 1=qpm 2=qph
	IsDistributed bool //是否分布式
	Limter        Limiter
}

type Limiter

type Limiter interface {
	Allow() bool
}

type LoadBalancer

type LoadBalancer struct {
	LoadBanlanceMap   map[string]*LoadBalancerItem
	LoadBanlanceSlice []*LoadBalancerItem
	Locker            sync.RWMutex
}
var LoadBalancerHandler *LoadBalancer

func NewLoadBalancer

func NewLoadBalancer() *LoadBalancer

func (*LoadBalancer) GetLoadBalancer

func (lbr *LoadBalancer) GetLoadBalancer(service *model.ServiceDetail) (*load_balance.LoadBalance, error)

func (*LoadBalancer) Update

func (lbr *LoadBalancer) Update(e *ServiceEvent)

type LoadBalancerItem

type LoadBalancerItem struct {
	LoadBanlance *load_balance.LoadBalance
	ServiceName  string
	UpdatedAt    time.Time
}

type ServiceEvent

type ServiceEvent struct {
	DeleteService []*model.ServiceDetail
	AddService    []*model.ServiceDetail
	UpdateService []*model.ServiceDetail
}

通知事件

type ServiceManager

type ServiceManager struct {
	ServiceMap   map[string]*model.ServiceDetail
	ServiceSlice []*model.ServiceDetail

	UpdateAt  time.Time
	Observers map[ServiceObserver]bool
	sync.RWMutex
	// contains filtered or unexported fields
}
var ServiceManagerHandler *ServiceManager = NewServiceManager()

func NewServiceManager

func NewServiceManager() *ServiceManager

func (*ServiceManager) Deregist

func (s *ServiceManager) Deregist(ob ServiceObserver)

func (*ServiceManager) GetGrpcServiceList

func (s *ServiceManager) GetGrpcServiceList() []*model.ServiceDetail

func (*ServiceManager) GetTcpServiceList

func (s *ServiceManager) GetTcpServiceList() []*model.ServiceDetail

func (*ServiceManager) HTTPAccessMode

func (s *ServiceManager) HTTPAccessMode(c *gin.Context) (*model.ServiceDetail, error)

func (*ServiceManager) Load

func (s *ServiceManager) Load() error

func (*ServiceManager) LoadAndWatch

func (s *ServiceManager) LoadAndWatch() error

func (*ServiceManager) LoadService

func (s *ServiceManager) LoadService() *ServiceManager

func (*ServiceManager) Notify

func (s *ServiceManager) Notify(e *ServiceEvent)

func (*ServiceManager) Regist

func (s *ServiceManager) Regist(ob ServiceObserver)

type ServiceObserver

type ServiceObserver interface {
	Update(*ServiceEvent)
}

观察者接口

type ServiceSubject

type ServiceSubject interface {
	Regist(ServiceObserver)
	Deregist(ServiceObserver)
	Notify(*ServiceEvent)
}

被观察者接口

type TransportItem

type TransportItem struct {
	Trans       *http.Transport
	ServiceName string
	UpdateAt    time.Time
}

type Transportor

type Transportor struct {
	TransportMap   map[string]*TransportItem
	TransportSlice []*TransportItem
	Locker         sync.RWMutex
}
var TransportorHandler *Transportor

func NewTransportor

func NewTransportor() *Transportor

func (*Transportor) GetTrans

func (t *Transportor) GetTrans(service *model.ServiceDetail) (*http.Transport, error)

func (*Transportor) Update

func (t *Transportor) Update(e *ServiceEvent)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL