func ParseConfig()

in proxy/health/health.go [162:198]


func ParseConfig(c *config.HealthCheck) (string, L7Check, error) {
	if c.Port == "" {
		return "", nil, ErrPortEmpty
	}
	var check L7Check
	if c.Protocol != "" {
		var ok bool
		check, ok = l7Checks[c.Protocol]
		if !ok {
			return "", nil, errors.New("don not support L7 checker:" + c.Protocol)
		}
	} else {
		check = nil
	}

	address := "127.0.0.1:" + c.Port
	if c.URI != "" {
		if !strings.HasPrefix(c.URI, "/") {
			return "", nil, ErrInvalidURI
		}
	}
	if c.Match != nil {
		if c.Match.Status != "" {
			_, err := strconv.Atoi(c.Match.Status)
			if err != nil {
				return "", nil, err
			}
		}
		if c.Match.Body != "" {
			_, err := regexp.Compile(c.Match.Body)
			if err != nil {
				return "", nil, err
			}
		}
	}
	return address, check, nil
}