1 Star 0 Fork 0

东海苍月/traefik

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
annotations_parser.go 1.78 KB
一键复制 编辑 原始数据 按行查看 历史
Ludovic Fernandez 提交于 2017-12-04 11:40 . Change custom headers separator
package kubernetes
import (
"net/http"
"strings"
"github.com/containous/traefik/log"
"github.com/containous/traefik/types"
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
)
func getBoolAnnotation(meta *v1beta1.Ingress, name string, defaultValue bool) bool {
annotationValue := defaultValue
annotationStringValue, ok := meta.Annotations[name]
switch {
case !ok:
// No op.
case annotationStringValue == "false":
annotationValue = false
case annotationStringValue == "true":
annotationValue = true
default:
log.Warnf("Unknown value %q for %q, falling back to %v", annotationStringValue, name, defaultValue)
}
return annotationValue
}
func getStringAnnotation(meta *v1beta1.Ingress, name string) string {
value := meta.Annotations[name]
return value
}
func getSliceAnnotation(meta *v1beta1.Ingress, name string) []string {
var value []string
if annotation, ok := meta.Annotations[name]; ok && annotation != "" {
value = types.SplitAndTrimString(annotation)
}
if len(value) == 0 {
log.Debugf("Could not load %v annotation, skipping...", name)
return nil
}
return value
}
func getMapAnnotation(meta *v1beta1.Ingress, annotName string) map[string]string {
if values, ok := meta.Annotations[annotName]; ok {
if len(values) == 0 {
log.Errorf("Missing value for annotation %q", annotName)
return nil
}
mapValue := make(map[string]string)
for _, parts := range strings.Split(values, "||") {
pair := strings.SplitN(parts, ":", 2)
if len(pair) != 2 {
log.Warnf("Could not load %q: %v, skipping...", annotName, pair)
} else {
mapValue[http.CanonicalHeaderKey(strings.TrimSpace(pair[0]))] = strings.TrimSpace(pair[1])
}
}
if len(mapValue) == 0 {
log.Errorf("Could not load %q, skipping...", annotName)
return nil
}
return mapValue
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dhcy/traefik.git
git@gitee.com:dhcy/traefik.git
dhcy
traefik
traefik
v1.5.2

搜索帮助

0d507c66 1850385 C8b1a773 1850385