balance

package
v0.0.0-...-fac4fbb Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 5 Imported by: 0

README

Balance

介绍

安装

go get -u -v github.com/bincent/balance

使用示例

// 预置数组
var insts []*balance.Instance

host := "192.168.1.1"
port, _ := 8080
one := balance.NewInstance(host, port)
insts = append(insts, one)

// 调用负载均衡说明
// RandomRule表示随机策略
inst, err := balance.Random(insts)

// RoundRobin表示轮询策略
inst, err := balance.Round(insts)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Random

func Random(insts []*Instance) (address string, err error)

随机策略

func Round

func Round(insts []*Instance) (address string, err error)

轮询调度算法

Types

type Balance

type Balance interface {
	Execute([]*Instance, ...string) (string, error)
}

*

  • 负载均衡算法

*

type Instance

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

func NewInstance

func NewInstance(host string, port int) *Instance

func (*Instance) GetHost

func (p *Instance) GetHost() string

func (*Instance) GetPort

func (p *Instance) GetPort() int

type Manager

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

type RandomRule

type RandomRule struct {
}

随机策略

func (*RandomRule) Execute

func (this *RandomRule) Execute(insts []*Instance, key ...string) (address string, err error)

type RoundRobin

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

轮询调度算法

func (*RoundRobin) Execute

func (this *RoundRobin) Execute(insts []*Instance, key ...string) (address string, err error)

Jump to

Keyboard shortcuts

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