milvus/master/config/util.go
xige-16 6eff45989e Serialize produce message in proxy node
Signed-off-by: xige-16 <xi.ge@zilliz.com>
2020-09-04 18:37:21 +08:00

50 lines
1.5 KiB
Go

// Copyright 2019 TiKV Project Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"net/url"
"regexp"
"github.com/czs007/suvlim/errors"
)
const (
// Label key consists of alphanumeric characters, '-', '_', '.' or '/', and must start and end with an
// alphanumeric character. If can also contain an extra '$' at the beginning.
keyFormat = "^[$]?[A-Za-z0-9]([-A-Za-z0-9_./]*[A-Za-z0-9])?$"
// Value key can be any combination of alphanumeric characters, '-', '_', '.' or '/'. It can also be empty to
// mark the label as deleted.
valueFormat = "^[-A-Za-z0-9_./]*$"
)
func validateFormat(s, format string) error {
isValid, _ := regexp.MatchString(format, s)
if !isValid {
return errors.Errorf("%s does not match format %q", s, format)
}
return nil
}
// ValidateURLWithScheme checks the format of the URL.
func ValidateURLWithScheme(rawURL string) error {
u, err := url.ParseRequestURI(rawURL)
if err != nil {
return err
}
if u.Scheme == "" || u.Host == "" {
return errors.Errorf("%s has no scheme", rawURL)
}
return nil
}