mirror of
https://github.com/go-sigma/sigma.git
synced 2026-10-29 15:34:34 +08:00
Replace every `// <Identifier> ...` placeholder doc comment with a real description of the declared symbol. 276 comments in 71 files were rewritten: 149 top-level placeholders first, then a follow-up scan caught another 127 indented ones (interface methods and const blocks) that a column-anchored match had missed. Comments now open with the declared identifier and record the actual contract - behaviour, side effects, error/panic conditions, units, HTTP endpoints, lock keys and cache prefixes - instead of restating the signature. Three placeholders carried a stale identifier and were corrected to the declared symbol: ConfigurationDatabasePostgresql, GetImageRef and Initialize. No functional change: every modified line is a comment. Verification: - grep '^\s*//\s+\S+\s+\.\.\.\s*$' over all *.go returns no matches - gofmt -l over the changed files prints nothing - CGO_ENABLED=1 go build -tags "netgo,timetzdata,exclude_graphdriver_btrfs,containers_image_openpgp" ./... exits 0 - git diff HEAD -U0 filtered to non-comment changed lines is empty
59 lines
2.0 KiB
Go
59 lines
2.0 KiB
Go
// Copyright 2023 sigma
|
|
//
|
|
// 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 reference parses registry image references into their domain, namespace, repository, and tag or digest components.
|
|
package reference
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/distribution/reference"
|
|
)
|
|
|
|
// Parse splits name into its domain, namespace (first repository path component), full repository path, and tag or digest. It requires a namespaced reference and, when neither a tag nor a digest is present, falls back to the default tag "latest"; a missing namespace yields an error.
|
|
func Parse(name string) (string, string, string, string, error) {
|
|
if !strings.Contains(name, "/") {
|
|
return "", "", "", "", fmt.Errorf("invalid reference: %s", name)
|
|
}
|
|
|
|
named, err := reference.ParseNormalizedNamed(name)
|
|
if err != nil {
|
|
return "", "", "", "", fmt.Errorf("failed to parse reference: %v, %s", err, name)
|
|
}
|
|
named = reference.TagNameOnly(named)
|
|
domain := reference.Domain(named)
|
|
path := reference.Path(named)
|
|
|
|
var tagOrDigest string
|
|
tagged, ok := named.(reference.Tagged)
|
|
if !ok {
|
|
digested, ok := named.(reference.Digested)
|
|
if !ok {
|
|
return "", "", "", "", fmt.Errorf("reference is not tagged or digested: %v, %s", named, name)
|
|
}
|
|
tagOrDigest = digested.Digest().String()
|
|
} else {
|
|
tagOrDigest = tagged.Tag()
|
|
}
|
|
|
|
if !strings.Contains(path, "/") {
|
|
return "", "", "", "", fmt.Errorf("invalid reference: %s", name)
|
|
}
|
|
parts := strings.Split(path, "/")
|
|
ns := parts[0]
|
|
repo := path
|
|
return domain, ns, repo, tagOrDigest, nil
|
|
}
|