1
0
mirror of https://github.com/containers/buildah.git synced 2025-04-18 07:04:05 +03:00

Use any instead of interface{}

Brought to you by

	gofmt -r 'interface{} -> any' -w .

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2025-04-07 11:59:01 -07:00
parent bb240a6e40
commit 1ede7ddce7
18 changed files with 62 additions and 62 deletions

View File

@ -154,7 +154,7 @@ func updateEntrypoint(builder *buildah.Builder, entrypoint string) {
builder.SetEntrypoint(entrypointSpec)
}
func conditionallyAddHistory(builder *buildah.Builder, c *cobra.Command, createdByFmt string, args ...interface{}) {
func conditionallyAddHistory(builder *buildah.Builder, c *cobra.Command, createdByFmt string, args ...any) {
history := buildahcli.DefaultHistory()
if c.Flag("add-history").Changed {
history, _ = c.Flags().GetBool("add-history")

View File

@ -250,10 +250,10 @@ func outputContainers(store storage.Store, opts containerOptions, params *contai
return nil
}
func containersToGeneric(templParams []containerOutputParams) (genericParams []interface{}) {
func containersToGeneric(templParams []containerOutputParams) (genericParams []any) {
if len(templParams) > 0 {
for _, v := range templParams {
genericParams = append(genericParams, interface{}(v))
genericParams = append(genericParams, any(v))
}
}
return genericParams

View File

@ -327,10 +327,10 @@ func truncateID(id string, truncate bool) string {
return id
}
func imagesToGeneric(templParams []imageOutputParams) (genericParams []interface{}) {
func imagesToGeneric(templParams []imageOutputParams) (genericParams []any) {
if len(templParams) > 0 {
for _, v := range templParams {
genericParams = append(genericParams, interface{}(v))
genericParams = append(genericParams, any(v))
}
}
return genericParams

View File

@ -43,7 +43,7 @@ func init() {
}
func infoCmd(c *cobra.Command, iopts infoResults) error {
info := map[string]interface{}{}
info := map[string]any{}
store, err := getStore(c)
if err != nil {
@ -92,8 +92,8 @@ func infoCmd(c *cobra.Command, iopts infoResults) error {
}
// top-level "debug" info
func debugInfo() map[string]interface{} {
info := map[string]interface{}{}
func debugInfo() map[string]any {
info := map[string]any{}
info["compiler"] = runtime.Compiler
info["go version"] = runtime.Version()
info["buildah version"] = define.Version

View File

@ -26,7 +26,7 @@ import (
// unmarshalConvertedConfig obtains the config blob of img valid for the wantedManifestMIMEType format
// (either as it exists, or converting the image if necessary), and unmarshals it into dest.
// NOTE: The MIME type is of the _manifest_, not of the _config_ that is returned.
func unmarshalConvertedConfig(ctx context.Context, dest interface{}, img types.Image, wantedManifestMIMEType string) error {
func unmarshalConvertedConfig(ctx context.Context, dest any, img types.Image, wantedManifestMIMEType string) error {
_, actualManifestMIMEType, err := img.Manifest(ctx)
if err != nil {
return fmt.Errorf("getting manifest MIME type for %q: %w", transports.ImageName(img.Reference()), err)

View File

@ -1052,7 +1052,7 @@ func resolvePath(root, path string, evaluateFinalComponent bool, pm *fileutils.P
}
func copierHandlerEval(req request) *response {
errorResponse := func(fmtspec string, args ...interface{}) *response {
errorResponse := func(fmtspec string, args ...any) *response {
return &response{Error: fmt.Sprintf(fmtspec, args...), Eval: evalResponse{}}
}
resolvedTarget, err := resolvePath(req.Root, req.Directory, true, nil)
@ -1063,7 +1063,7 @@ func copierHandlerEval(req request) *response {
}
func copierHandlerStat(req request, pm *fileutils.PatternMatcher) *response {
errorResponse := func(fmtspec string, args ...interface{}) *response {
errorResponse := func(fmtspec string, args ...any) *response {
return &response{Error: fmt.Sprintf(fmtspec, args...), Stat: statResponse{}}
}
if len(req.Globs) == 0 {
@ -1233,7 +1233,7 @@ func copierHandlerGet(bulkWriter io.Writer, req request, pm *fileutils.PatternMa
statRequest := req
statRequest.Request = requestStat
statResponse := copierHandlerStat(req, pm)
errorResponse := func(fmtspec string, args ...interface{}) (*response, func() error, error) {
errorResponse := func(fmtspec string, args ...any) (*response, func() error, error) {
return &response{Error: fmt.Sprintf(fmtspec, args...), Stat: statResponse.Stat, Get: getResponse{}}, nil, nil
}
if statResponse.Error != "" {
@ -1696,7 +1696,7 @@ func copierHandlerGetOne(srcfi os.FileInfo, symlinkTarget, name, contentPath str
}
func copierHandlerPut(bulkReader io.Reader, req request, idMappings *idtools.IDMappings) (*response, func() error, error) {
errorResponse := func(fmtspec string, args ...interface{}) (*response, func() error, error) {
errorResponse := func(fmtspec string, args ...any) (*response, func() error, error) {
return &response{Error: fmt.Sprintf(fmtspec, args...), Put: putResponse{}}, nil, nil
}
dirUID, dirGID, defaultDirUID, defaultDirGID := 0, 0, 0, 0
@ -2110,7 +2110,7 @@ func copierHandlerPut(bulkReader io.Reader, req request, idMappings *idtools.IDM
}
func copierHandlerMkdir(req request, idMappings *idtools.IDMappings) (*response, func() error, error) {
errorResponse := func(fmtspec string, args ...interface{}) (*response, func() error, error) {
errorResponse := func(fmtspec string, args ...any) (*response, func() error, error) {
return &response{Error: fmt.Sprintf(fmtspec, args...), Mkdir: mkdirResponse{}}, nil, nil
}
dirUID, dirGID := 0, 0
@ -2164,7 +2164,7 @@ func copierHandlerMkdir(req request, idMappings *idtools.IDMappings) (*response,
}
func copierHandlerRemove(req request) *response {
errorResponse := func(fmtspec string, args ...interface{}) *response {
errorResponse := func(fmtspec string, args ...any) *response {
return &response{Error: fmt.Sprintf(fmtspec, args...), Remove: removeResponse{}}
}
resolvedTarget, err := resolvePath(req.Root, req.Directory, false, nil)

View File

@ -187,7 +187,7 @@ type BuildOptions struct {
// Log is a callback that will print a progress message. If no value
// is supplied, the message will be sent to Err (or os.Stderr, if Err
// is nil) by default.
Log func(format string, args ...interface{})
Log func(format string, args ...any)
// In is connected to stdin for RUN instructions.
In io.Reader
// Out is a place where non-error log messages are sent.

View File

@ -80,7 +80,7 @@ type Executor struct {
output string
outputFormat string
additionalTags []string
log func(format string, args ...interface{}) // can be nil
log func(format string, args ...any) // can be nil
in io.Reader
out io.Writer
err io.Writer
@ -556,7 +556,7 @@ func (b *Executor) buildStage(ctx context.Context, cleanupStages map[int]*StageE
stageExecutor := b.startStage(ctx, &stage, stages, output)
if stageExecutor.log == nil {
stepCounter := 0
stageExecutor.log = func(format string, args ...interface{}) {
stageExecutor.log = func(format string, args ...any) {
prefix := b.logPrefix
if len(stages) > 1 {
prefix += fmt.Sprintf("[%d/%d] ", stageIndex+1, len(stages))

View File

@ -61,7 +61,7 @@ type StageExecutor struct {
ctx context.Context
systemContext *types.SystemContext
executor *Executor
log func(format string, args ...interface{})
log func(format string, args ...any)
index int
stages imagebuilder.Stages
name string

16
info.go
View File

@ -23,7 +23,7 @@ import (
// InfoData holds the info type, i.e store, host etc and the data for each type
type InfoData struct {
Type string
Data map[string]interface{}
Data map[string]any
}
// Info returns the store and host information
@ -42,8 +42,8 @@ func Info(store storage.Store) ([]InfoData, error) {
return info, nil
}
func hostInfo() map[string]interface{} {
info := map[string]interface{}{}
func hostInfo() map[string]any {
info := map[string]any{}
ps := internalUtil.NormalizePlatform(v1.Platform{OS: runtime.GOOS, Architecture: runtime.GOARCH})
info["os"] = ps.OS
info["arch"] = ps.Architecture
@ -77,7 +77,7 @@ func hostInfo() map[string]interface{} {
info["SwapFree"] = mi.SwapFree
}
hostDistributionInfo := getHostDistributionInfo()
info["Distribution"] = map[string]interface{}{
info["Distribution"] = map[string]any{
"distribution": hostDistributionInfo["Distribution"],
"version": hostDistributionInfo["Version"],
}
@ -128,9 +128,9 @@ func hostInfo() map[string]interface{} {
}
// top-level "store" info
func storeInfo(store storage.Store) (map[string]interface{}, error) {
func storeInfo(store storage.Store) (map[string]any, error) {
// lets say storage driver in use, number of images, number of containers
info := map[string]interface{}{}
info := map[string]any{}
info["GraphRoot"] = store.GraphRoot()
info["RunRoot"] = store.RunRoot()
info["GraphDriverName"] = store.GraphDriverName()
@ -148,7 +148,7 @@ func storeInfo(store storage.Store) (map[string]interface{}, error) {
if err != nil {
logrus.Error(err, "error getting number of images")
}
info["ImageStore"] = map[string]interface{}{
info["ImageStore"] = map[string]any{
"number": len(images),
}
@ -156,7 +156,7 @@ func storeInfo(store storage.Store) (map[string]interface{}, error) {
if err != nil {
logrus.Error(err, "error getting number of containers")
}
info["ContainerStore"] = map[string]interface{}{
info["ContainerStore"] = map[string]any{
"number": len(containers),
}

4
new.go
View File

@ -246,11 +246,11 @@ func newBuilder(ctx context.Context, store storage.Store, options BuilderOptions
suffixDigitsModulo := 100
for {
var flags map[string]interface{}
var flags map[string]any
// check if we have predefined ProcessLabel and MountLabel
// this could be true if this is another stage in a build
if options.ProcessLabel != "" && options.MountLabel != "" {
flags = map[string]interface{}{
flags = map[string]any{
"ProcessLabel": options.ProcessLabel,
"MountLabel": options.MountLabel,
}

View File

@ -30,31 +30,31 @@ type Writer interface {
// JSONStructArray for JSON output
type JSONStructArray struct {
Output []interface{}
Output []any
}
// StdoutTemplateArray for Go template output
type StdoutTemplateArray struct {
Output []interface{}
Output []any
Template string
Fields map[string]string
}
// JSONStruct for JSON output
type JSONStruct struct {
Output interface{}
Output any
}
// StdoutTemplate for Go template output
type StdoutTemplate struct {
Output interface{}
Output any
Template string
Fields map[string]string
}
// YAMLStruct for YAML output
type YAMLStruct struct {
Output interface{}
Output any
}
func setJSONFormatEncoder(isTerminal bool, w io.Writer) *json.Encoder {

View File

@ -10,7 +10,7 @@ import (
// basicFunctions are the set of initial
// functions provided to every template.
var basicFunctions = template.FuncMap{
"json": func(v interface{}) string {
"json": func(v any) string {
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)

View File

@ -29,7 +29,7 @@ const (
)
type config struct {
params map[string]interface{}
params map[string]any
}
var (
@ -39,11 +39,11 @@ var (
func NewConfig() *config {
return &config{
params: make(map[string]interface{}),
params: make(map[string]any),
}
}
func handleBoolSetting(key string, val bool) (string, interface{}) {
func handleBoolSetting(key string, val bool) (string, any) {
// jail doesn't deal with booleans - it uses paired parameter
// names, e.g. "persist"/"nopersist". If the key contains '.',
// the "no" prefix is applied to the last element.
@ -55,7 +55,7 @@ func handleBoolSetting(key string, val bool) (string, interface{}) {
return key, nil
}
func (c *config) Set(key string, value interface{}) {
func (c *config) Set(key string, value any) {
// Normalise integer types to int32
switch v := value.(type) {
case int:

View File

@ -38,7 +38,7 @@ func NewAgentServer(source *Source) (*AgentServer, error) {
}
// newAgentServerKeyring creates a new agent from scratch and adds keys
func newAgentServerKeyring(keys []interface{}) (*AgentServer, error) {
func newAgentServerKeyring(keys []any) (*AgentServer, error) {
a := agent.NewKeyring()
for _, k := range keys {
if err := a.Add(agent.AddedKey{PrivateKey: k}); err != nil {
@ -191,12 +191,12 @@ func (a *readOnlyAgent) Extension(_ string, _ []byte) ([]byte, error) {
// The source of the forwarded agent can be from a socket on the host, or from individual key files
type Source struct {
Socket string
Keys []interface{}
Keys []any
}
// NewSource takes paths and checks of they are keys or sockets, and creates a source
func NewSource(paths []string) (*Source, error) {
var keys []interface{}
var keys []any
var socket string
if len(paths) == 0 {
socket = os.Getenv("SSH_AUTH_SOCK")

View File

@ -16,7 +16,7 @@ func testNewKeySource() (*Source, error) {
return nil, err
}
return &Source{
Keys: []interface{}{k},
Keys: []any{k},
}, nil
}

View File

@ -302,7 +302,7 @@ func (b *Builder) Run(command []string, options RunOptions) error {
// We are going to create bind mounts for devices
// but we need to make sure that we don't override
// anything which is already in OCI spec.
mounts := make(map[string]interface{})
mounts := make(map[string]any)
for _, m := range g.Mounts() {
mounts[m.Destination] = true
}

View File

@ -497,12 +497,12 @@ func testConformanceInternalBuild(ctx context.Context, t *testing.T, cwd string,
if t.Failed() {
t.FailNow()
}
deleteIdentityLabel := func(config map[string]interface{}) {
deleteIdentityLabel := func(config map[string]any) {
for _, configName := range []string{"config", "container_config"} {
if configStruct, ok := config[configName]; ok {
if configMap, ok := configStruct.(map[string]interface{}); ok {
if configMap, ok := configStruct.(map[string]any); ok {
if labels, ok := configMap["Labels"]; ok {
if labelMap, ok := labels.(map[string]interface{}); ok {
if labelMap, ok := labels.(map[string]any); ok {
delete(labelMap, buildah.BuilderIdentityAnnotation)
}
}
@ -513,7 +513,7 @@ func testConformanceInternalBuild(ctx context.Context, t *testing.T, cwd string,
deleteIdentityLabel(originalBuildahConfig)
deleteIdentityLabel(ociBuildahConfig)
var originalDockerConfig, ociDockerConfig, fsDocker map[string]interface{}
var originalDockerConfig, ociDockerConfig, fsDocker map[string]any
// the report on the docker image should be there if we expected the build to succeed
if !test.withoutDocker {
@ -791,7 +791,7 @@ func buildUsingImagebuilder(t *testing.T, client *docker.Client, test testCase,
executor.AllowPull = true
executor.Out = output
executor.ErrOut = output
executor.LogFn = func(format string, args ...interface{}) {
executor.LogFn = func(format string, args ...any) {
fmt.Fprintf(output, "--> %s\n", fmt.Sprintf(format, args...))
}
// buildah tests might be using transient mounts. replace "@@TEMPDIR@@"
@ -1175,12 +1175,12 @@ func applyLayerToFSTree(t *testing.T, layer *Layer, root *FSEntry) {
}
// read information about the specified image from the specified directory
func readReport(t *testing.T, directory string) (manifestType string, original, oci, fs map[string]interface{}) {
func readReport(t *testing.T, directory string) (manifestType string, original, oci, fs map[string]any) {
// read the manifest in the as-committed format, whatever that is
originalManifest, err := os.ReadFile(filepath.Join(directory, "manifest.json"))
require.NoErrorf(t, err, "error reading manifest %q", filepath.Join(directory, "manifest.json"))
// dump it into a map
manifest := make(map[string]interface{})
manifest := make(map[string]any)
err = json.Unmarshal(originalManifest, &manifest)
require.NoErrorf(t, err, "error decoding manifest %q", filepath.Join(directory, "manifest.json"))
if str, ok := manifest["mediaType"].(string); ok {
@ -1190,21 +1190,21 @@ func readReport(t *testing.T, directory string) (manifestType string, original,
originalConfig, err := os.ReadFile(filepath.Join(directory, "config.json"))
require.NoErrorf(t, err, "error reading configuration file %q", filepath.Join(directory, "config.json"))
// dump it into a map
original = make(map[string]interface{})
original = make(map[string]any)
err = json.Unmarshal(originalConfig, &original)
require.NoErrorf(t, err, "error decoding configuration from file %q", filepath.Join(directory, "config.json"))
// read the config in converted-to-OCI format
ociConfig, err := os.ReadFile(filepath.Join(directory, "oci-config.json"))
require.NoErrorf(t, err, "error reading OCI configuration file %q", filepath.Join(directory, "oci-config.json"))
// dump it into a map
oci = make(map[string]interface{})
oci = make(map[string]any)
err = json.Unmarshal(ociConfig, &oci)
require.NoErrorf(t, err, "error decoding OCI configuration from file %q", filepath.Join(directory, "oci.json"))
// read the filesystem
fsInfo, err := os.ReadFile(filepath.Join(directory, "fs.json"))
require.NoErrorf(t, err, "error reading filesystem summary file %q", filepath.Join(directory, "fs.json"))
// dump it into a map for comparison
fs = make(map[string]interface{})
fs = make(map[string]any)
err = json.Unmarshal(fsInfo, &fs)
require.NoErrorf(t, err, "error decoding filesystem summary from file %q", filepath.Join(directory, "fs.json"))
// return both
@ -1233,7 +1233,7 @@ func addPrefix(a []string, prefix string) []string {
// diffDebug returns a row for a tabwriter that summarizes a field name and the
// values for that field in two documents
func diffDebug(k string, a, b interface{}) string {
func diffDebug(k string, a, b any) string {
if k == "mode" {
// force modes to be displayed in octal instead of decimal
a, aok := a.(float64)
@ -1249,7 +1249,7 @@ func diffDebug(k string, a, b interface{}) string {
// lists of field names present only in the first map or the second,
// respectively, while diffKeys is a list of items which are present in both
// maps, but which have different values, formatted with diffDebug.
func compareJSON(a, b map[string]interface{}, skip []string) (missKeys, leftKeys, diffKeys []string, isSame bool) {
func compareJSON(a, b map[string]any, skip []string) (missKeys, leftKeys, diffKeys []string, isSame bool) {
isSame = true
for k, v := range a {
@ -1280,7 +1280,7 @@ func compareJSON(a, b map[string]interface{}, skip []string) (missKeys, leftKeys
continue
}
switch v.(type) {
case map[string]interface{}:
case map[string]any:
// this field in the object is itself an object (e.g.
// "config" or "container_config"), so recursively
// compare them
@ -1291,14 +1291,14 @@ func compareJSON(a, b map[string]interface{}, skip []string) (missKeys, leftKeys
nextSkip = append(nextSkip, strings.TrimPrefix(s, prefix))
}
}
submiss, subleft, subdiff, ok := compareJSON(v.(map[string]interface{}), vb.(map[string]interface{}), nextSkip)
submiss, subleft, subdiff, ok := compareJSON(v.(map[string]any), vb.(map[string]any), nextSkip)
missKeys = append(missKeys, addPrefix(submiss, k)...)
leftKeys = append(leftKeys, addPrefix(subleft, k)...)
diffKeys = append(diffKeys, addPrefix(subdiff, k)...)
if !ok {
isSame = false
}
case []interface{}:
case []any:
// this field in the object is an array; make sure both
// arrays have the same set of elements, which is more
// or less correct for labels and environment
@ -1306,14 +1306,14 @@ func compareJSON(a, b map[string]interface{}, skip []string) (missKeys, leftKeys
// this will break if it tries to compare an array of
// objects like "history", since maps, slices, and
// functions can't be used as keys in maps
tmpa := v.([]interface{})
tmpb := vb.([]interface{})
tmpa := v.([]any)
tmpb := vb.([]any)
if len(tmpa) != len(tmpb) {
diffKeys = append(diffKeys, diffDebug(k, v, vb))
isSame = false
break
}
m := make(map[interface{}]struct{})
m := make(map[any]struct{})
for i := 0; i < len(tmpb); i++ {
m[tmpb[i]] = struct{}{}
}