本文整理汇总了Golang中github.com/openshift/origin/pkg/route/api.RouteTargetReference.Weight方法的典型用法代码示例。如果您正苦于以下问题:Golang RouteTargetReference.Weight方法的具体用法?Golang RouteTargetReference.Weight怎么用?Golang RouteTargetReference.Weight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openshift/origin/pkg/route/api.RouteTargetReference
的用法示例。
在下文中一共展示了RouteTargetReference.Weight方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: autoConvert_v1_RouteTargetReference_To_api_RouteTargetReference
func autoConvert_v1_RouteTargetReference_To_api_RouteTargetReference(in *RouteTargetReference, out *route_api.RouteTargetReference, s conversion.Scope) error {
SetDefaults_RouteTargetReference(in)
out.Kind = in.Kind
out.Name = in.Name
out.Weight = in.Weight
return nil
}
示例2: autoConvert_v1_RouteTargetReference_To_api_RouteTargetReference
func autoConvert_v1_RouteTargetReference_To_api_RouteTargetReference(in *RouteTargetReference, out *route_api.RouteTargetReference, s conversion.Scope) error {
SetDefaults_RouteTargetReference(in)
out.Kind = in.Kind
out.Name = in.Name
if in.Weight != nil {
in, out := &in.Weight, &out.Weight
*out = new(int32)
**out = **in
} else {
out.Weight = nil
}
return nil
}
示例3: Apply
// Apply alters the weights of two services.
func (input *BackendInput) Apply(ref, to *routeapi.RouteTargetReference, backends []routeapi.RouteTargetReference) {
weight := int32(100)
if ref.Weight != nil {
weight = *ref.Weight
}
switch {
case input.Percentage:
if to == nil {
weight += (weight * input.Value) / 100
ref.Weight = &weight
return
}
otherWeight := int32(0)
if to.Weight != nil {
otherWeight = *to.Weight
}
previousWeight := weight + otherWeight
// rebalance all other backends to be relative in weight to the current
for i, other := range backends {
if previousWeight == 0 || other.Weight == nil || other.Name == ref.Name || other.Name == to.Name {
continue
}
adjusted := *other.Weight * 100 / previousWeight
backends[i].Weight = &adjusted
}
// adjust the weight between ref and to
target := float32(input.Value) / 100
if input.Relative {
if previousWeight != 0 {
percent := float32(weight) / float32(previousWeight)
target = percent + target
}
}
switch {
case target < 0:
target = 0
case target > 1:
target = 1
}
weight = int32(target * 100)
otherWeight = int32((1 - target) * 100)
ref.Weight = &weight
to.Weight = &otherWeight
// rescale the max to 200 in case we are dealing with very small percentages
max := int32(0)
for _, other := range backends {
if other.Weight == nil {
continue
}
if *other.Weight > max {
max = *other.Weight
}
}
if max > 256 {
for i, other := range backends {
if other.Weight == nil || *other.Weight == 0 {
continue
}
adjusted := 200 * *other.Weight / max
if adjusted < 1 {
adjusted = 1
}
backends[i].Weight = &adjusted
}
}
case input.Relative:
weight += input.Value
if weight < 0 {
weight = 0
}
ref.Weight = &weight
default:
ref.Weight = &input.Value
}
}
示例4: autoConvert_v1_RouteTargetReference_To_api_RouteTargetReference
func autoConvert_v1_RouteTargetReference_To_api_RouteTargetReference(in *RouteTargetReference, out *api.RouteTargetReference, s conversion.Scope) error {
out.Kind = in.Kind
out.Name = in.Name
out.Weight = (*int32)(unsafe.Pointer(in.Weight))
return nil
}