blob: e93cffca5d884ac5656ef09f7bcca38445af6225 [file] [log] [blame]
// Copyright 2015 The LUCI 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,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import (
"fmt"
)
const (
// MaxTagKeySize is the maximum number of bytes allowed in a tag's key
// parameter.
MaxTagKeySize = 64
// MaxTagValueSize is the maximum number of bytes allowed in a tag's value
// parameter.
MaxTagValueSize = 4096
)
// ValidateTag returns an error if a tag contains a nonconfirming value.
func ValidateTag(k, v string) error {
if err := StreamName(k).Validate(); err != nil {
return fmt.Errorf("invalid tag key: %s", err)
}
if len(k) > MaxTagKeySize {
return fmt.Errorf("tag key exceeds maximum size (%d > %d)", len(k), MaxTagKeySize)
}
if len(v) > MaxTagValueSize {
return fmt.Errorf("tag value exceeds maximum size (%d > %d)", len(v), MaxTagValueSize)
}
return nil
}