core

package
v0.0.0-...-ecf5411 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LoopBalancer = "loop"
)

Variables

View Source
var ErrorNoIpFoundInBalancer = fmt.Errorf("no ip found in balancer")
View Source
var (
	NoGroupFoundError = errors.New("no available group found")
)

Functions

func AddCity

func AddCity(c *models.City) error

func AddGroup

func AddGroup(g *models.Group) error

func AddGroupServerRef

func AddGroupServerRef(ref *models.ServerGroupRef) error

func AddIdc

func AddIdc(i *models.Idc)

func AddPool

func AddPool(p *models.Pool) error

func AddPoolGroupRef

func AddPoolGroupRef(ref *models.GroupPoolRef) error

todo 保证一个server 只会被加到一个pool中一次

func AddProvince

func AddProvince(p *models.Province) error

func AddRegion

func AddRegion(rg *models.Region) error

func AddRoute

func AddRoute(r *models.Route) error

func AddServer

func AddServer(ref *models.ServerGroupRef) error

func AddService

func AddService(s *models.Service) error

func DeleteCity

func DeleteCity(code int) error

func DeleteGroup

func DeleteGroup(id string)

func DeleteGroupServerRef

func DeleteGroupServerRef(refId string) error

func DeleteIdc

func DeleteIdc(id string)

func DeletePool

func DeletePool(id string) error

func DeletePoolGroupRef

func DeletePoolGroupRef(refId string) error

func DeleteProvince

func DeleteProvince(code int) error

func DeleteRegion

func DeleteRegion(code int) error

func DeleteRoute

func DeleteRoute(id string) error

func DeleteService

func DeleteService(id string)

func GetIpInfo

func GetIpInfo(ip net.IP) interface{}

func If

func If(cond bool, a, b interface{}) interface{}

func Init

func Init(arg Args) error

func InitRequestContext

func InitRequestContext(c *Context, ipAddr net.IP, params string)

服务入口api

func InitRoutes

func InitRoutes(rs ...*route) error

func IsValidIp

func IsValidIp(ip string) (int, bool)

func NewGroup

func NewGroup(g *models.Group) (*group, error)

func NewHealthyCheck

func NewHealthyCheck(name string, cfg string) (healthyCheckFunc, error)

func NewPoolSelector

func NewPoolSelector(mode int) (poolSelector, error)

func ParseRules

func ParseRules(rules string) ([]*rule, error)

[]

func ResolveIpsByHost

func ResolveIpsByHost(c *Context, host string, address *Address) error

func UpdateGroup

func UpdateGroup(groupId string) error

func UpdatePoolGroup

func UpdatePoolGroup(poolId string) error

func ValidateHost

func ValidateHost(host string) error

Types

type Address

type Address struct {
	Host    string
	Ips     []string
	IdcName string
	Svc     string
	Port    int
	Ttl     int
	Default []string
	Ver     string
	Mul     bool
}

type Args

type Args struct {
	Dao            *Daoes
	IpResourcePath string
}

type Balancer

type Balancer interface {
	Get(ctx *Context) ([]*Target, error)
	Reload(tgs []*Target)
}

func NewBalancer

func NewBalancer(name string, targets []*Target, numIpsReturn int) (bc Balancer, err error)

type Context

type Context struct {
	GetV6 bool

	Getter   func(key string) string
	Group    string
	Pool     string
	Service  string
	Route    string
	Idc      string
	LbMode   int
	ClientIp net.IP
	// contains filtered or unexported fields
}

func (*Context) Get

func (c *Context) Get(key string) string

func (*Context) Host

func (c *Context) Host() string

func (*Context) IdcAffinity

func (c *Context) IdcAffinity() (res []string)

func (*Context) Params

func (c *Context) Params() map[string]string

func (*Context) Set

func (c *Context) Set(key, val string)

func (*Context) String

func (c *Context) String() string

type Daoes

type Daoes struct {
	ServiceDao dao.Service
	//ServerDao         dao.Server
	GroupServerRefDao dao.GroupServerRef
	GroupDao          dao.Group
	PoolDao           dao.Pool
	GroupPoolRefDao   dao.GroupPoolRef
	RouteDao          dao.Route
	IdcDao            dao.Idc
	City              dao.City
	Province          dao.Province
	Region            dao.Region
	Param             dao.ParamsEnums
	Country           dao.Country
	User              dao.User
}

func (*Daoes) InitCmds

func (d *Daoes) InitCmds() map[string]func() error

type GroupStatus

type GroupStatus struct {
	Name             string
	Nodes            []Node
	HealthyCheckAble bool
}

func GetGroupStatus

func GetGroupStatus() []*GroupStatus

type Metrics

type Metrics struct {
	HostAccess  map[string]int64 `json:"host_access"`
	GroupSelect map[string]int64 `json:"group_select"`
	IdcSelect   map[string]int64 `json:"idc_select"`
}

type Node

type Node struct {
	Addr    string
	Weight  int
	Healthy bool
}

type RouteSelector

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

func NewRouteSelector

func NewRouteSelector() *RouteSelector

type Target

type Target struct {
	Addr   string // in mem ,this is server id
	Weight int
	IsV6   bool
}

func (Target) String

func (t Target) String() string

type WeightedLoopBalancer

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

带权重轮询负载均衡器

func (*WeightedLoopBalancer) Get

func (b *WeightedLoopBalancer) Get(ctx *Context) ([]*Target, error)

func (*WeightedLoopBalancer) Reload

func (b *WeightedLoopBalancer) Reload(tgs []*Target)

Jump to

Keyboard shortcuts

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