moby/image/image_os.go
Sebastiaan van Stijn a3c97beee0
image: implement CheckOS, deprecate pkg/system IsOSSupported
Implement a function that returns an error to replace existing uses of
the IsOSSupported utility, where callers had to produce the error after
checking.

The IsOSSupported function was used in combination with images, so implementing
a utility in "image" to prevent having to import pkg/system (which contains many
unrelated functions)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-09-07 22:14:44 +02:00

18 lines
369 B
Go

package image
import (
"errors"
"runtime"
"strings"
"github.com/docker/docker/errdefs"
)
// CheckOS checks if the given OS matches the host's platform, and
// returns an error otherwise.
func CheckOS(os string) error {
if !strings.EqualFold(runtime.GOOS, os) {
return errdefs.InvalidParameter(errors.New("operating system is not supported"))
}
return nil
}