1
0
mirror of https://github.com/opencontainers/runc.git synced 2025-04-18 19:44:09 +03:00

Use any instead of interface{}

The keyword is available since Go 1.18 (see
https://pkg.go.dev/builtin#any).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2025-03-28 18:55:28 -07:00
parent 17570625c0
commit 7fdec327a0
8 changed files with 10 additions and 10 deletions

View File

@ -503,7 +503,7 @@ func (hooks *Hooks) MarshalJSON() ([]byte, error) {
return serializableHooks
}
return json.Marshal(map[string]interface{}{
return json.Marshal(map[string]any{
"prestart": serialize((*hooks)[Prestart]),
"createRuntime": serialize((*hooks)[CreateRuntime]),
"createContainer": serialize((*hooks)[CreateContainer]),

View File

@ -81,7 +81,7 @@ func TestFactoryLoadContainer(t *testing.T) {
}
}
func marshal(path string, v interface{}) error {
func marshal(path string, v any) error {
f, err := os.Create(path)
if err != nil {
return err

View File

@ -676,7 +676,7 @@ func TestInitSystemdProps(t *testing.T) {
type expT struct {
isErr bool
name string
value interface{}
value any
}
testCases := []struct {

View File

@ -24,7 +24,7 @@ func TestStateStatus(t *testing.T) {
}
func testTransitions(t *testing.T, initialState containerState, valid []containerState) {
validMap := map[reflect.Type]interface{}{}
validMap := map[reflect.Type]any{}
for _, validState := range valid {
validMap[reflect.TypeOf(validState)] = nil
t.Run(validState.status().String(), func(t *testing.T) {

View File

@ -113,7 +113,7 @@ func writeSync(pipe *syncSocket, sync syncType) error {
return doWriteSync(pipe, syncT{Type: sync})
}
func writeSyncArg(pipe *syncSocket, sync syncType, arg interface{}) error {
func writeSyncArg(pipe *syncSocket, sync syncType, arg any) error {
argJSON, err := json.Marshal(arg)
if err != nil {
return fmt.Errorf("writing sync %v: marshal argument failed: %w", sync, err)

View File

@ -27,7 +27,7 @@ func ExitStatus(status unix.WaitStatus) int {
// without a trailing newline. This is used instead of json.Encoder because
// there might be a problem in json decoder in some cases, see:
// https://github.com/docker/docker/issues/14203#issuecomment-174177790
func WriteJSON(w io.Writer, v interface{}) error {
func WriteJSON(w io.Writer, v any) error {
data, err := json.Marshal(v)
if err != nil {
return err

2
tty.go
View File

@ -44,7 +44,7 @@ func setupProcessPipes(p *libcontainer.Process, rootuid, rootgid int) (*tty, err
},
}
// add the process's io to the post start closers if they support close
for _, cc := range []interface{}{
for _, cc := range []any{
p.Stdin,
p.Stdout,
p.Stderr,

View File

@ -7,9 +7,9 @@ import (
// Event struct for encoding the event data to json.
type Event struct {
Type string `json:"type"`
ID string `json:"id"`
Data interface{} `json:"data,omitempty"`
Type string `json:"type"`
ID string `json:"id"`
Data any `json:"data,omitempty"`
}
// Stats is the runc specific stats structure for stability when encoding and decoding stats.