Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace 'interface{}' with 'any' for consistency #1788

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ linters-settings:
check-type-assertions: true
gocyclo:
min-complexity: 35
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'

issues:
# Excluding configuration per-path, per-linter, per-text and per-source
Expand Down
8 changes: 4 additions & 4 deletions internal/attributedstring/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func (a *Slice) Set(values []string) {
}

// UnmarshalTOML is the custom unmarshal method for Slice.
func (a *Slice) UnmarshalTOML(data interface{}) error {
iFaceSlice, ok := data.([]interface{})
func (a *Slice) UnmarshalTOML(data any) error {
iFaceSlice, ok := data.([]any)
if !ok {
return fmt.Errorf("unable to cast to interface array: %v", data)
}
Expand All @@ -53,7 +53,7 @@ func (a *Slice) UnmarshalTOML(data interface{}) error {
switch val := x.(type) {
case string: // Strings are directly appended to the slice.
loadedStrings = append(loadedStrings, val)
case map[string]interface{}: // The attribute struct is represented as a map.
case map[string]any: // The attribute struct is represented as a map.
for k, v := range val { // Iterate over all _supported_ keys.
switch k {
case "append":
Expand Down Expand Up @@ -81,7 +81,7 @@ func (a *Slice) UnmarshalTOML(data interface{}) error {

// MarshalTOML is the custom marshal method for Slice.
func (a *Slice) MarshalTOML() ([]byte, error) {
iFaceSlice := make([]interface{}, 0, len(a.Values))
iFaceSlice := make([]any, 0, len(a.Values))

for _, x := range a.Values {
iFaceSlice = append(iFaceSlice, x)
Expand Down
10 changes: 5 additions & 5 deletions libnetwork/cni/cni_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func createNetworkFromCNIConfigList(conf *libcni.NetworkConfigList, confPath str
IPAMOptions: map[string]string{},
}

cniJSON := make(map[string]interface{})
cniJSON := make(map[string]any)
err := json.Unmarshal(conf.Bytes, &cniJSON)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal network config %s: %w", conf.Name, err)
}
if args, ok := cniJSON["args"]; ok {
if key, ok := args.(map[string]interface{}); ok {
if key, ok := args.(map[string]any); ok {
// read network labels and options from the conf file
network.Labels = getNetworkArgsFromConfList(key, podmanLabelKey)
network.Options = getNetworkArgsFromConfList(key, podmanOptionsKey)
Expand Down Expand Up @@ -214,9 +214,9 @@ func convertIPAMConfToNetwork(network *types.Network, ipam *ipamConfig, confPath
}

// getNetworkArgsFromConfList returns the map of args in a conflist, argType should be labels or options
func getNetworkArgsFromConfList(args map[string]interface{}, argType string) map[string]string {
func getNetworkArgsFromConfList(args map[string]any, argType string) map[string]string {
if args, ok := args[argType]; ok {
if labels, ok := args.(map[string]interface{}); ok {
if labels, ok := args.(map[string]any); ok {
result := make(map[string]string, len(labels))
for k, v := range labels {
if v, ok := v.(string); ok {
Expand Down Expand Up @@ -298,7 +298,7 @@ func (n *cniNetwork) createCNIConfigListFromNetwork(network *types.Network, writ
// the dnsname plugin also needs to be updated for 1.0.0
// TODO change to 1.0.0 when most distros support it
ncList := newNcList(network.Name, "0.4.0", network.Labels, network.Options)
var plugins []interface{}
var plugins []any

switch network.Driver {
case types.BridgeNetworkDriver:
Expand Down
2 changes: 1 addition & 1 deletion libnetwork/cni/cni_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type dnsNameConfig struct {
}

// ncList describes a generic map
type ncList map[string]interface{}
type ncList map[string]any

// newNcList creates a generic map of values with string
// keys and adds in version and network name
Expand Down
4 changes: 2 additions & 2 deletions libnetwork/cni/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (n *cniNetwork) Setup(namespacePath string, options types.SetupOptions) (ma
// If we have more than one static ip we need parse the ips via runtime config,
// make sure to add the ips capability to the first plugin otherwise it doesn't get the ips
if len(netOpts.StaticIPs) > 0 && !network.cniNet.Plugins[0].Network.Capabilities["ips"] {
caps := map[string]interface{}{
caps := map[string]any{
"capabilities": map[string]bool{"ips": true},
}
network.cniNet.Plugins[0], retErr = libcni.InjectConf(network.cniNet.Plugins[0], caps)
Expand Down Expand Up @@ -174,7 +174,7 @@ func getRuntimeConfig(netns, conName, conID, networkName string, ports []cniPort
// Only K8S_POD_NAME is used by dnsname to get the container name.
{"K8S_POD_NAME", conName},
},
CapabilityArgs: map[string]interface{}{},
CapabilityArgs: map[string]any{},
}

// Propagate environment CNI_ARGS
Expand Down
6 changes: 3 additions & 3 deletions libnetwork/netavark/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func getRustLogEnv() string {
// used to marshal the netavark output into it. This can be nil.
// All errors return by this function should be of the type netavarkError
// to provide a helpful error message.
func (n *netavarkNetwork) execNetavark(args []string, needPlugin bool, stdin, result interface{}) error {
func (n *netavarkNetwork) execNetavark(args []string, needPlugin bool, stdin, result any) error {
// set the netavark log level to the same as the podman
env := append(os.Environ(), getRustLogEnv())
// Netavark need access to iptables in $PATH. As it turns out debian doesn't put
Expand All @@ -101,11 +101,11 @@ func (n *netavarkNetwork) execNetavark(args []string, needPlugin bool, stdin, re
return n.execBinary(n.netavarkBinary, append(n.getCommonNetavarkOptions(needPlugin), args...), stdin, result, env)
}

func (n *netavarkNetwork) execPlugin(path string, args []string, stdin, result interface{}) error {
func (n *netavarkNetwork) execPlugin(path string, args []string, stdin, result any) error {
return n.execBinary(path, args, stdin, result, nil)
}

func (n *netavarkNetwork) execBinary(path string, args []string, stdin, result interface{}, env []string) error {
func (n *netavarkNetwork) execBinary(path string, args []string, stdin, result any, env []string) error {
stdinR, stdinW, err := os.Pipe()
if err != nil {
return newNetavarkError("failed to create stdin pipe", err)
Expand Down
2 changes: 1 addition & 1 deletion libnetwork/netavark/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e *ipamError) Error() string {
return msg
}

func newIPAMError(cause error, msg string, args ...interface{}) *ipamError {
func newIPAMError(cause error, msg string, args ...any) *ipamError {
return &ipamError{
msg: fmt.Sprintf(msg, args...),
cause: cause,
Expand Down
6 changes: 3 additions & 3 deletions libnetwork/netavark/netavark_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type equalSubnetMatcher struct {
expected *net.IPNet
}

func (m *equalSubnetMatcher) Match(actual interface{}) (bool, error) {
func (m *equalSubnetMatcher) Match(actual any) (bool, error) {
util.NormalizeIP(&m.expected.IP)

subnet, ok := actual.(*net.IPNet)
Expand All @@ -79,10 +79,10 @@ func (m *equalSubnetMatcher) Match(actual interface{}) (bool, error) {
return reflect.DeepEqual(subnet, m.expected), nil
}

func (m *equalSubnetMatcher) FailureMessage(actual interface{}) string {
func (m *equalSubnetMatcher) FailureMessage(actual any) string {
return fmt.Sprintf("Expected subnet %#v to equal subnet %#v", actual, m.expected)
}

func (m *equalSubnetMatcher) NegatedFailureMessage(actual interface{}) string {
func (m *equalSubnetMatcher) NegatedFailureMessage(actual any) string {
return fmt.Sprintf("Expected subnet %#v not to equal subnet %#v", actual, m.expected)
}
2 changes: 1 addition & 1 deletion libnetwork/slirp4netns/slirp4netns.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ func openSlirp4netnsPort(apiSocket, proto, hostip string, hostport, guestport ui
}
// if there is no 'error' key in the received JSON data, then the operation was
// successful.
var y map[string]interface{}
var y map[string]any
if err := json.Unmarshal(buf[0:readLength], &y); err != nil {
return fmt.Errorf("parsing error status from slirp4netns: %w", err)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/formats/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/report/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (f *Formatter) Init(w io.Writer, minwidth, tabwidth, padding int, padchar b

// Execute applies a parsed template to the specified data object,
// and writes the output to Formatter.Writer.
func (f *Formatter) Execute(data interface{}) error {
func (f *Formatter) Execute(data any) error {
return f.template.Execute(f.writer, data)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/report/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var escapedReplacer = strings.NewReplacer(

var DefaultFuncs = FuncMap{
"join": strings.Join,
"json": func(v interface{}) string {
"json": func(v any) string {
buf := new(bytes.Buffer)
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
Expand Down Expand Up @@ -93,7 +93,7 @@ func truncateWithLength(source string, length int) string {
// 1) unchanged --format includes headers
// 2) --format '{{.ID}" # no headers
// 3) --format 'table {{.ID}}' # includes headers
func Headers(object interface{}, overrides map[string]string) []map[string]string {
func Headers(object any, overrides map[string]string) []map[string]string {
value := reflect.ValueOf(object)
if value.Kind() == reflect.Ptr {
value = value.Elem()
Expand Down
24 changes: 12 additions & 12 deletions pkg/ssh/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ type ConnectionScpReport struct {
// Info is the overall struct that describes the host system
// running libpod/podman
type Info struct {
Host *HostInfo `json:"host"`
Store *StoreInfo `json:"store"`
Registries map[string]interface{} `json:"registries"`
Plugins Plugins `json:"plugins"`
Version Version `json:"version"`
Host *HostInfo `json:"host"`
Store *StoreInfo `json:"store"`
Registries map[string]any `json:"registries"`
Plugins Plugins `json:"plugins"`
Version Version `json:"version"`
}

// Version is an output struct for API
Expand Down Expand Up @@ -121,8 +121,8 @@ type HostInfo struct {
OCIRuntime *OCIRuntimeInfo `json:"ociRuntime"`
OS string `json:"os"`
// RemoteSocket returns the UNIX domain socket the Podman service is listening on
RemoteSocket *RemoteSocket `json:"remoteSocket,omitempty"`
RuntimeInfo map[string]interface{} `json:"runtimeInfo,omitempty"`
RemoteSocket *RemoteSocket `json:"remoteSocket,omitempty"`
RuntimeInfo map[string]any `json:"runtimeInfo,omitempty"`
// ServiceIsRemote is true when the podman/libpod service is remote to the client
ServiceIsRemote bool `json:"serviceIsRemote"`
Security SecurityInfo `json:"security"`
Expand Down Expand Up @@ -179,11 +179,11 @@ type OCIRuntimeInfo struct {
// StoreInfo describes the container storage and its
// attributes
type StoreInfo struct {
ConfigFile string `json:"configFile"`
ContainerStore ContainerStore `json:"containerStore"`
GraphDriverName string `json:"graphDriverName"`
GraphOptions map[string]interface{} `json:"graphOptions"`
GraphRoot string `json:"graphRoot"`
ConfigFile string `json:"configFile"`
ContainerStore ContainerStore `json:"containerStore"`
GraphDriverName string `json:"graphDriverName"`
GraphOptions map[string]any `json:"graphOptions"`
GraphRoot string `json:"graphRoot"`
// GraphRootAllocated is how much space the graphroot has in bytes
GraphRootAllocated uint64 `json:"graphRootAllocated"`
// GraphRootUsed is how much of graphroot is used in bytes
Expand Down
2 changes: 1 addition & 1 deletion pkg/systemd/systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func RunUnderSystemdScope(pid int, slice string, unitName string) error {
return nil
}

func newProp(name string, units interface{}) systemdDbus.Property {
func newProp(name string, units any) systemdDbus.Property {
return systemdDbus.Property{
Name: name,
Value: dbus.MakeVariant(units),
Expand Down