mirror of
https://github.com/distribution/reference.git
synced 2026-10-28 18:25:32 +08:00
89ee7ec63e17bd74e6766ecac7d8ff2bd4b8dd8a
The splitDockerDomain attempts to determine whether the given name
contains a domain, or should be used as a "remote-name". The logic used
in doing so is based on (legacy) conventions, which have not always been
properly documented.
The logic used in this function was also optimized for "brevity", but
not easy to ready, due to the combination of multiple boolean conditions
combined on a single line, and some "double negatives".
More documentation may still be needed, but let's start with documenting
the logic used in this function;
- Use `strings.Cut()` instead of `strings.IndexRune()`, which allows us to
use descriptive variable names, and prevents use of the magic `-1` value.
- Split the conditions into a switch, so that each of them can be documented
separately. While this makes the code more verbose (and introduces some
duplication), it should not impact performance, as only one condition
would ever be met (performance may even be better, as the old code
combined multiple conditions with `&&`).
- Introduce a fast-path for single-element ("familiar") names. These names
can be canonicalized early, without doing further handling.
While working on the code, I also discovered an existing bug (or omission)
where the code would not handle bare _domain names_. Ironically, the
TestParseDockerRef test has a test-case name "hostname only", but which does
not cover that case. THat test-case was transferred from containerd/cri,
and does not describe this scenario (possibly was left as a "further exercise");
https://github.com/containerd/cri/commit/25fdf726923b607d0155550c5e85a911bb04bad1
Let keep it as a further exercise, but add a "TODO" to remind us doing so.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Distribution reference
Go library to handle references to container images.
This repository contains a library for handling refrences to container images held in container registries. Please see godoc for details.
Contribution
Please see CONTRIBUTING.md for details on how to contribute issues, fixes, and patches to this project.
Communication
For async communication and long running discussions please use issues and pull requests on the github repo. This will be the best place to discuss design and implementation.
For sync communication we have a #distribution channel in the CNCF Slack that everyone is welcome to join and chat about development.
Licenses
The distribution codebase is released under the Apache 2.0 license.
Languages
Go
99.2%
Makefile
0.8%