You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
536 B
34 lines
536 B
package grpcbalancer
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
const RoundRobin BalancingPolicy = iota
|
|
|
|
var ErrEmptyVal = errors.New("empty value")
|
|
|
|
type BalancingPolicy int8
|
|
|
|
type grpcConfig struct {
|
|
Balancing BalancingPolicy `json:"loadBalancingPolicy"`
|
|
}
|
|
|
|
func (bp BalancingPolicy) String() string {
|
|
switch bp {
|
|
case RoundRobin:
|
|
return "round_robin"
|
|
}
|
|
|
|
return ""
|
|
}
|
|
|
|
func (bp BalancingPolicy) MarshalJSON() ([]byte, error) {
|
|
val := bp.String()
|
|
if val == "" {
|
|
return nil, ErrEmptyVal
|
|
}
|
|
|
|
return []byte(fmt.Sprintf(`"%s"`, val)), nil
|
|
}
|
|
|