Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrServersEmpty = errors.New("server list is empty") ErrServerNotFound = errors.New("server not found") )
Functions ¶
This section is empty.
Types ¶
type RoundRobin ¶
type RoundRobin interface {
NextServer() *url.URL
AddServer(*url.URL, int) error
RemoveServer(*url.URL) error
Servers() []*url.URL
RemoveAll()
// Reset resets all current weights.
Reset()
}
Example ¶
r, _ := New()
for _, server := range servers {
_ = r.AddServer(server.url, server.weight)
}
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
fmt.Println(r.NextServer().Host)
Output: 192.168.1.10 192.168.1.10 192.168.1.11 192.168.1.10 192.168.1.11 192.168.1.12 192.168.1.10 192.168.1.11 192.168.1.12
func New ¶
func New() (RoundRobin, error)
Click to show internal directories.
Click to hide internal directories.