// 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 }