Documentation ¶
Overview ¶
Package utils contains various utility functions/types.
Index ¶
- Variables
- func BucketResourceID(project, bucket string) string
- func Duration(start *timestamppb.Timestamp, ends ...*timestamppb.Timestamp) string
- func GetJSONData(client *http.Client, url string, out any) (err error)
- func HumanDuration(d time.Duration) string
- func LegacyBuilderIDString(bid *buildbucketpb.BuilderID) string
- func MergeStrings(sss ...[]string) []string
- func ObfuscateEmail(email string) template.HTML
- func ParseBuildbucketBuildID(bid string) (buildID int64, err error)
- func ParseBuilderID(bid string) (*buildbucketpb.BuilderID, error)
- func ParseIntFromForm(form url.Values, key string, base int, bitSize int) (int64, error)
- func ParseLegacyBuildbucketBuildID(bid string) (builderID *buildbucketpb.BuilderID, number int32, err error)
- func ParseLegacyBuilderID(bid string) (*buildbucketpb.BuilderID, error)
- func ReadExactOneFromForm(form url.Values, key string) (string, error)
- func ReplaceNSEWith(err errors.MultiError, replacement error) error
- func ShortenEmail(email string) string
- func TagGRPC(c context.Context, err error) error
- type Interval
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidBuilderID = errors.New("the string is not a valid builder ID")
var ErrInvalidLegacyBuildID = errors.New("the string is not a valid legacy build ID")
var ErrInvalidLegacyBuilderID = errors.New("the string is not a valid legacy builder ID (format: buildbucket/luci.<project>.<bucket>/<builder>)")
Functions ¶
func BucketResourceID ¶
BucketResourceID returns a string identifying the bucket resource. It is used when checking bucket permission.
func Duration ¶
func Duration(start *timestamppb.Timestamp, ends ...*timestamppb.Timestamp) string
Duration returns duration between start and the earliest of ends. Ignores nil ends. Fallbacks to "N/A" on insufficient data.
func GetJSONData ¶
GetJSONData fetches data from the given URL, parses the response body to `out`. It follows redirection and returns an error if the status code is 4xx or 5xx.
func HumanDuration ¶
HumanDuration translates d into a human readable string of x units y units, where x and y could be in days, hours, minutes, or seconds, whichever is the largest.
func LegacyBuilderIDString ¶
func LegacyBuilderIDString(bid *buildbucketpb.BuilderID) string
LegacyBuilderIDString returns a legacy string identifying the builder. It is used in the Milo datastore.
func MergeStrings ¶
MergeStrings merges multiple string slices together into a single slice, removing duplicates.
func ObfuscateEmail ¶
ObfuscateEmail converts a string containing email address email@address.com into email<junk>@address.com.
func ParseBuildbucketBuildID ¶
ParseBuildbucketBuildID parses the legacy build ID in the format of `buildbucket/<build_id>`
func ParseBuilderID ¶
func ParseBuilderID(bid string) (*buildbucketpb.BuilderID, error)
ParseBuilderID parses the canonical builder ID (e.g. `<project>/<bucket>/<builder>`) and returns the BuilderID struct.
func ParseIntFromForm ¶
ParseIntFromForm parses an integer from a form.
func ParseLegacyBuildbucketBuildID ¶
func ParseLegacyBuildbucketBuildID(bid string) (builderID *buildbucketpb.BuilderID, number int32, err error)
ParseLegacyBuildbucketBuildID parses the legacy build ID in the format of `buildbucket/luci.<project>.<bucket>/<builder>/<number>`.
func ParseLegacyBuilderID ¶
func ParseLegacyBuilderID(bid string) (*buildbucketpb.BuilderID, error)
ParseLegacyBuilderID parses the legacy builder ID (e.g. `buildbucket/luci.<project>.<bucket>/<builder>`) and returns the BuilderID struct.
func ReadExactOneFromForm ¶
ReadExactOneFromForm read a string from a form. There must be exactly one and non-empty entry of the given key in the form.
func ReplaceNSEWith ¶
func ReplaceNSEWith(err errors.MultiError, replacement error) error
ReplaceNSEWith takes an errors.MultiError returned by a datastore.Get() on a slice (which is always a MultiError), filters out all datastore.ErrNoSuchEntity or replaces it with replacement instances, and returns an error generated by errors.LazyMultiError.