shunt

package
v0.0.0-...-796898b Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package shunt 负载服务包

Index

Constants

View Source
const (
	// Random 负载均衡 random 策略
	Random = iota
	// Round 负载均衡 round 策略
	Round
	// Hash 负载均衡 hash 策略
	Hash
)

Variables

This section is empty.

Functions

func GetService

func GetService(serviceName string) (service *server.Service, err error)

GetService 根据服务名称获取待转发服务

func Route

func Route(engine *gin.Engine)

Route 网关服务路由

func RunHash

func RunHash(serviceName string) (add *server.Service, err error)

RunHash 负载均衡 hash 策略实现

func RunRandom

func RunRandom(serviceName string) (add *server.Service, err error)

RunRandom 负载均衡 random 策略实现

func RunRound

func RunRound(serviceName string) (service *server.Service, err error)

RunRound 负载均衡 round 策略实现

func RunShunt

func RunShunt(context *gin.Context, serviceName string)

RunShunt 开启路由

func RunShuntCallback

func RunShuntCallback(context *gin.Context, serviceName string, f func() *response.Result)

RunShuntCallback 开启路由并处理降级

func YamlLBs

func YamlLBs(data []byte)

YamlLBs YML转负载对象数组

Types

type LB

type LB struct {
	Name      string `yaml:"Name"`      // 服务名称
	InURI     string `yaml:"InURI"`     // 负载入口 URI
	OutRemote string `yaml:"OutRemote"` // 负载出口地址
	Register  int    `yaml:"Register"`  // 负载均衡算法,1:随机;2:轮询;3:Hash一致性
}

LB 负载均衡配置对象

type LBs

type LBs struct {
	LBs []*LB `yaml:"shunt"`
}

LBs 负载对象数组

type RoundRobinBalance

type RoundRobinBalance struct {
	// contains filtered or unexported fields
}

RoundRobinBalance 负载均衡 round 策略实体

type Shunt

type Shunt struct {
	AllWay map[string]int
}

Shunt 负载入口对象

func GetShuntInstance

func GetShuntInstance() *Shunt

GetShuntInstance 获取负载管理对象 Shunt 单例

func (*Shunt) AddService

func (s *Shunt) AddService(serviceName, inURI, outRemote string, way int)

AddService 新增负载服务

func (*Shunt) Register

func (s *Shunt) Register(serviceName string, way int)

Register 注册新的负载方式

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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