Documentation ¶
Index ¶
- Constants
- Variables
- func HashCode(key string) int
- func Register(b Builder)
- func URLJoin(urls ...string) string
- func Unregister(name string)
- type Backend
- type Backends
- type Balancer
- type Builder
- type Doctor
- type DoctorBuilder
- type DoctorOptions
- type DoneHandler
- type DoneInfo
- type FailureError
- type Options
- type Picker
- type PickerBuilder
- type PingHandler
- type State
- type Statistic
- type StatisticOptions
Constants ¶
const URLSeparator = '/'
URLSeparator define url separator
Variables ¶
var Manager = &manager{ balancers: new(sync.Map), }
Manager is a struct map from name to balancer.
Functions ¶
func Register ¶
func Register(b Builder)
Register registers the balancer builder to the balancer map. b.Name
func Unregister ¶
func Unregister(name string)
Unregister deletes the balancer with the given name from the balancer map.
Types ¶
type Backends ¶
Backends backend node list
type Balancer ¶
type Balancer interface { Do(req *http.Request) (*http.Response, error) Pick() (*Backend, error) Backends() *Backends Close() }
Balancer takes input from http, manages Backend, and collects and aggregates the connectivity states.
type DoctorBuilder ¶
type DoctorBuilder interface { Build(ping PingHandler, backends *Backends) Doctor Name() string }
DoctorBuilder creates balancer.Doctor.
type DoctorOptions ¶
type DoctorOptions struct { Enable bool `json:"enable" mapstructure:"enable"` //Whether to enable health check Type string `json:"type" mapstructure:"type"` //Doctor type Spec string `json:"spec" mapstructure:"spec"` //Time interval of scheduled tasks }
DoctorOptions contains additional information for Doctor.
type DoneHandler ¶
type DoneHandler func(info DoneInfo)
DoneHandler define the specific implementation of Done
type FailureError ¶
type FailureError struct {
// contains filtered or unexported fields
}
FailureError describe the failed error
func NewFailureError ¶
func NewFailureError(err error) *FailureError
NewFailureError creates a fail error.
type Options ¶
type Options struct { Name string `json:"name" mapstructure:"name"` //Balancer name Type string `json:"type" mapstructure:"type"` //Picker type Timeout int `json:"timeout" mapstructure:"timeout"` //http timeout, Unit: second CacheSize int `json:"cache_size" mapstructure:"cache_size"` //Node cache size NetParam string `json:"net_param" mapstructure:"net_param"` //Node net param Urls []string `json:"urls" mapstructure:"urls"` //Load node url Doctor DoctorOptions `json:"doctor" mapstructure:"doctor"` //Health checker Statistic StatisticOptions `json:"statistic" mapstructure:"statistic"` //Statistics DoneHandler DoneHandler `json:"-"` PingHandler PingHandler `json:"-"` }
Options contains additional information for Build.
type PickerBuilder ¶
PickerBuilder creates balancer.Picker.
type PingHandler ¶
PingHandler define the specific implementation of Ping
type State ¶
type State struct {
// contains filtered or unexported fields
}
State describes the status information of the node
func (*State) HealthCheck ¶
HealthCheck determine whether the node is available
type Statistic ¶
type Statistic struct {
// contains filtered or unexported fields
}
Statistic describe statistics
func (*Statistic) IncFailure ¶
IncFailure auto-increment failure times
func (*Statistic) IncSuccess ¶
IncSuccess auto-increment success times
type StatisticOptions ¶
type StatisticOptions struct { Enable bool `json:"enable" mapstructure:"enable"` //Whether to enable statistics Port int `json:"port" mapstructure:"port"` //Service port for obtaining statistics }
StatisticOptions contains additional information for Statistic.